diff --git a/components/respawn/cfgRespawnTemplates.hpp b/components/respawn/cfgRespawnTemplates.hpp index 256a807..d2e950b 100644 --- a/components/respawn/cfgRespawnTemplates.hpp +++ b/components/respawn/cfgRespawnTemplates.hpp @@ -6,6 +6,8 @@ class CfgRespawnTemplates #include "squad\respawnTemplates.hpp" + #include "tickets\respawnTemplates.hpp" + #include "timed\respawnTemplates.hpp" #include "triggeredWave\respawnTemplates.hpp" diff --git a/components/respawn/fixPlayerTickets/respawnTemplates.hpp b/components/respawn/fixPlayerTickets/respawnTemplates.hpp index eade6f3..b2efb90 100644 --- a/components/respawn/fixPlayerTickets/respawnTemplates.hpp +++ b/components/respawn/fixPlayerTickets/respawnTemplates.hpp @@ -3,4 +3,5 @@ class CAFE_FixPlayerTickets onPlayerKilled = "components\respawn\fixPlayerTickets\onPlayerKilledOrRespawned.sqf"; onPlayerRespawn = "components\respawn\fixPlayerTickets\onPlayerKilledOrRespawned.sqf"; respawnTypes[] = {2,3}; + isCall = 1; }; \ No newline at end of file diff --git a/components/respawn/tickets/macros.hpp b/components/respawn/tickets/macros.hpp new file mode 100644 index 0000000..5556564 --- /dev/null +++ b/components/respawn/tickets/macros.hpp @@ -0,0 +1 @@ +#include "../macros.hpp" \ No newline at end of file diff --git a/components/respawn/tickets/onPlayerKilled.sqf b/components/respawn/tickets/onPlayerKilled.sqf new file mode 100644 index 0000000..eabedba --- /dev/null +++ b/components/respawn/tickets/onPlayerKilled.sqf @@ -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; +}; + diff --git a/components/respawn/tickets/onPlayerRespawn.sqf b/components/respawn/tickets/onPlayerRespawn.sqf new file mode 100644 index 0000000..171cf21 --- /dev/null +++ b/components/respawn/tickets/onPlayerRespawn.sqf @@ -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; \ No newline at end of file diff --git a/components/respawn/tickets/respawnTemplates.hpp b/components/respawn/tickets/respawnTemplates.hpp new file mode 100644 index 0000000..52479c6 --- /dev/null +++ b/components/respawn/tickets/respawnTemplates.hpp @@ -0,0 +1,6 @@ +class CAFE_Tickets +{ + onPlayerKilled = "components\respawn\tickets\onPlayerKilled.sqf"; + onPlayerRespawn = "components\respawn\tickets\onPlayerRespawn.sqf"; + isCall = 1; +}; \ No newline at end of file diff --git a/components/respawn/timed/respawnTemplates.hpp b/components/respawn/timed/respawnTemplates.hpp index 5137024..1576eb6 100644 --- a/components/respawn/timed/respawnTemplates.hpp +++ b/components/respawn/timed/respawnTemplates.hpp @@ -2,4 +2,5 @@ class CAFE_Timed { onPlayerKilled = "components\respawn\timed\onPlayerKilledOrRespawned.sqf"; onPlayerRespawn = "components\respawn\timed\onPlayerKilledOrRespawned.sqf"; + isCall = 1; }; \ No newline at end of file diff --git a/components/respawn/triggeredWave/respawnTemplates.hpp b/components/respawn/triggeredWave/respawnTemplates.hpp index aab1862..3cc1a71 100644 --- a/components/respawn/triggeredWave/respawnTemplates.hpp +++ b/components/respawn/triggeredWave/respawnTemplates.hpp @@ -2,4 +2,5 @@ class CAFE_TriggeredWave { onPlayerKilled = "components\respawn\triggeredWave\onPlayerKilled.sqf"; respawnTypes[] = {2,3}; + isCall = 1; }; \ No newline at end of file diff --git a/components/respawn/wave/respawnTemplates.hpp b/components/respawn/wave/respawnTemplates.hpp index 4a98398..cbd1742 100644 --- a/components/respawn/wave/respawnTemplates.hpp +++ b/components/respawn/wave/respawnTemplates.hpp @@ -3,4 +3,5 @@ class CAFE_Wave onPlayerKilled = "components\respawn\wave\onPlayerKilledOrRespawned.sqf"; onPlayerRespawn = "components\respawn\wave\onPlayerKilledOrRespawned.sqf"; respawnTypes[] = {2,3}; + isCall = 1; }; \ No newline at end of file diff --git a/configuration/respawn.hpp b/configuration/respawn.hpp index 74630af..834a139 100644 --- a/configuration/respawn.hpp +++ b/configuration/respawn.hpp @@ -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. diff --git a/respawn_macros.hpp b/respawn_macros.hpp index 81a8a84..5bd3ae9 100644 --- a/respawn_macros.hpp +++ b/respawn_macros.hpp @@ -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"}