Skip to content

Commit

Permalink
Replaced vanilla ticket handling with bespoke stuff. (#152)
Browse files Browse the repository at this point in the history
Specified isCall for all respawn modes.
Added new timed-tickets mode.  IDK why it was missing.
  • Loading branch information
Bubbus authored Mar 13, 2023
1 parent d242d3b commit db06426
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 2 deletions.
2 changes: 2 additions & 0 deletions components/respawn/cfgRespawnTemplates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class CfgRespawnTemplates

#include "squad\respawnTemplates.hpp"

#include "tickets\respawnTemplates.hpp"

#include "timed\respawnTemplates.hpp"

#include "triggeredWave\respawnTemplates.hpp"
Expand Down
1 change: 1 addition & 0 deletions components/respawn/fixPlayerTickets/respawnTemplates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class CAFE_FixPlayerTickets
onPlayerKilled = "components\respawn\fixPlayerTickets\onPlayerKilledOrRespawned.sqf";
onPlayerRespawn = "components\respawn\fixPlayerTickets\onPlayerKilledOrRespawned.sqf";
respawnTypes[] = {2,3};
isCall = 1;
};
1 change: 1 addition & 0 deletions components/respawn/tickets/macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../macros.hpp"
70 changes: 70 additions & 0 deletions components/respawn/tickets/onPlayerKilled.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "macros.hpp"

/*
CAFE Tickets on-killed script.
Disable respawn if no tickets remain, then wait until any tickets are added to re-enable respawn.
*/

params ["_oldUnit", "_killer", "_respawn", "_respawnDelay"];

// Wait until a ticket is gained or player is alive. Re-enable respawn if ticket is gained.
// If player does not respawn and tickets run out again, re-disable respawn and await further tickets.
f_fnc_respawn_tickets_waitForTickets =
{
[
// Condition
{
(alive player) or {([player, 0, true] call bis_fnc_respawnTickets) > 0}
},

// Script
{
if (alive player) exitWith {};

DEBUG_FORMAT1_LOG("[RESPAWN-2] %1 has tickets now - removing the wait.", player)
setPlayerRespawnTime 1;
[] call f_fnc_respawn_tickets_waitForNoTickets;
}

] call CBA_fnc_waitUntilAndExecute;
};

// Wait until all tickets are lost or player is alive. Re-disable respawn if tickets are lost.
// If player does not respawn and tickets are gained, re-enable respawn and await further ticket depletion.
f_fnc_respawn_tickets_waitForNoTickets =
{
[
// Condition
{
(alive player) or {([player, 0, true] call bis_fnc_respawnTickets) <= 0}
},

// Script
{
if (alive player) exitWith {};

DEBUG_FORMAT1_LOG("[RESPAWN-2] %1 has no more tickets now - re-applying the wait.", player)
setPlayerRespawnTime 1e10;
[] call f_fnc_respawn_tickets_waitForTickets;
}

] call CBA_fnc_waitUntilAndExecute;
};


// Check if tickets are available, and poll for ticket gain or ticket depletion accordingly.
private _remainingTickets = [player, 0, true] call bis_fnc_respawnTickets;

if (_remainingTickets > 0) then
{
DEBUG_FORMAT2_LOG("[RESPAWN-2] %1 has %2 tickets remaining - not enforcing a wait.", player, _remainingTickets)
[] call f_fnc_respawn_tickets_waitForNoTickets;
}
else
{
DEBUG_FORMAT2_LOG("[RESPAWN-2] %1 has %2 tickets remaining - enforcing a wait.", player, _remainingTickets)
setPlayerRespawnTime 1e10;
[] call f_fnc_respawn_tickets_waitForTickets;
};

23 changes: 23 additions & 0 deletions components/respawn/tickets/onPlayerRespawn.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "macros.hpp"

/*
CAFE Tickets on-respawn script.
Remove a ticket from the most-local non-zero ticket pool to the player.
*/

params [["_newUnit", objNull, [objNull]], "_oldUnit", "_respawn", "_respawnDelay"];

if (!isPlayer _newUnit && !isNull _newUnit) exitWith
{
["Attempting to use 'CAFE_Tickets' on AI unit '%1' - can be used only on players.", _newUnit] call BIS_fnc_error;
};

if (isNil 'f_var_respawn_tickets_hadFirstSpawn') exitWith
{
DEBUG_FORMAT1_LOG("[RESPAWN-2] %1 spawning for the first time - not removing a ticket.", _newUnit)
f_var_respawn_tickets_hadFirstSpawn = true;
};

DEBUG_FORMAT1_LOG("[RESPAWN-2] %1 spawning - removing a ticket.", _newUnit)
[_newUnit, -1, true] call bis_fnc_respawnTickets;
6 changes: 6 additions & 0 deletions components/respawn/tickets/respawnTemplates.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CAFE_Tickets
{
onPlayerKilled = "components\respawn\tickets\onPlayerKilled.sqf";
onPlayerRespawn = "components\respawn\tickets\onPlayerRespawn.sqf";
isCall = 1;
};
1 change: 1 addition & 0 deletions components/respawn/timed/respawnTemplates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class CAFE_Timed
{
onPlayerKilled = "components\respawn\timed\onPlayerKilledOrRespawned.sqf";
onPlayerRespawn = "components\respawn\timed\onPlayerKilledOrRespawned.sqf";
isCall = 1;
};
1 change: 1 addition & 0 deletions components/respawn/triggeredWave/respawnTemplates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class CAFE_TriggeredWave
{
onPlayerKilled = "components\respawn\triggeredWave\onPlayerKilled.sqf";
respawnTypes[] = {2,3};
isCall = 1;
};
1 change: 1 addition & 0 deletions components/respawn/wave/respawnTemplates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class CAFE_Wave
onPlayerKilled = "components\respawn\wave\onPlayerKilledOrRespawned.sqf";
onPlayerRespawn = "components\respawn\wave\onPlayerKilledOrRespawned.sqf";
respawnTypes[] = {2,3};
isCall = 1;
};
3 changes: 2 additions & 1 deletion configuration/respawn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
RESPAWN MODES:
Set a respawn mode for each side. They can be one of the following:
RESPAWN_MODE_TICKETS - Ticket-based respawn, from whatever tickets have been configured.
RESPAWN_MODE_TIMED - A respawn timer for each player individually.
RESPAWN_MODE_TIMED_TICKETS - Like RESPAWN_MODE_TIMED but with tickets also.
RESPAWN_MODE_TIMED_WAVES - A respawn timer for wave respawns. Players will respawn at the same time at the configured interval.
RESPAWN_MODE_TICKETS - Ticket-based respawn, from whatever tickets have been configured.
RESPAWN_MODE_TIMED_WAVES_TICKETS - Like RESPAWN_MODE_TIMED_WAVES but with tickets also.
RESPAWN_MODE_TRIGGERED_WAVES - The classic wave system, triggered by any group leader.
RESPAWN_MODE_TRIGGERED_WAVES_TICKETS - Like RESPAWN_MODE_TRIGGERED_WAVES, but with tickets also.
Expand Down
3 changes: 2 additions & 1 deletion respawn_macros.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#define RESPAWN_TIMED_WAVE "CAFE_Wave"
#define RESPAWN_TIMED "CAFE_Timed"
#define RESPAWN_TICKETS "TicketsSpawn"
#define RESPAWN_TICKETS "CAFE_Tickets"
#define RESPAWN_TRIGGERED_WAVE "CAFE_TriggeredWave"

#define RESPAWN_MENU "MenuPosition"

#define RESPAWN_MODE_TIMED {"CAFE_FixPlayerTickets", RESPAWN_MENU, "CAFE_WeaponSafety", "Spectator", RESPAWN_TIMED, "CAFE_Loadout", "CAFE_Squad"}
#define RESPAWN_MODE_TIMED_TICKETS {"CAFE_FixPlayerTickets", RESPAWN_MENU, "CAFE_WeaponSafety", "Spectator", RESPAWN_TIMED, RESPAWN_TICKETS, "CAFE_Loadout", "CAFE_Squad"}
#define RESPAWN_MODE_TIMED_WAVES {"CAFE_FixPlayerTickets", RESPAWN_MENU, "CAFE_WeaponSafety", "Spectator", RESPAWN_TIMED_WAVE, "CAFE_Loadout", "CAFE_Squad"}
#define RESPAWN_MODE_TICKETS {"CAFE_FixPlayerTickets", RESPAWN_MENU, "CAFE_WeaponSafety", "Spectator", RESPAWN_TICKETS, "CAFE_Loadout", "CAFE_Squad"}
#define RESPAWN_MODE_TIMED_WAVES_TICKETS {"CAFE_FixPlayerTickets", RESPAWN_MENU, "CAFE_WeaponSafety", "Spectator", RESPAWN_TIMED_WAVE, RESPAWN_TICKETS, "CAFE_Loadout", "CAFE_Squad"}
Expand Down

0 comments on commit db06426

Please sign in to comment.