Skip to content

Commit

Permalink
move waverespawn from saving names to saving units
Browse files Browse the repository at this point in the history
  • Loading branch information
McDiod committed Nov 20, 2018
1 parent 3491f58 commit 7aa0d02
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 51 deletions.
30 changes: 14 additions & 16 deletions functions/waverespawn/fn_addToWave.sqf
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#include "component.hpp"

params ["_deadPlayerName", ["_deadPlayerSide", sideUnknown]];
params ["_deadPlayer", ["_deadPlayerSide", sideUnknown]];

if (isNil "wavePlayernamesBlu") then {wavePlayernamesBlu = []};
if (isNil "wavePlayernamesOpf") then {wavePlayernamesOpf = []};
if (isNil "wavePlayernamesInd") then {wavePlayernamesInd = []};

_deadPlayerName = [_deadPlayerName] call BIS_fnc_filterString;
if (isNil "wavePlayersBlu") then {wavePlayersBlu = []};
if (isNil "wavePlayersOpf") then {wavePlayersOpf = []};
if (isNil "wavePlayersInd") then {wavePlayersInd = []};

//add player to array
switch (_deadPlayerSide) do {
case (WEST): {
wavePlayernamesBlu pushBackUnique _deadPlayerName;
INFO_2("Added player %1 to wavePlayernamesBlu. %2 dead blufor total.", _deadPlayerName, count wavePlayernamesBlu);
WAVERESPAWNPLAYERSLEFTBLU = BLUFORWAVESIZE - (count wavePlayernamesBlu);
wavePlayersBlu pushBackUnique _deadPlayer;
INFO_2("Added player %1 to wavePlayersBlu. %2 dead blufor total.", _deadPlayer, count wavePlayersBlu);
WAVERESPAWNPLAYERSLEFTBLU = BLUFORWAVESIZE - (count wavePlayersBlu);
publicVariable "WAVERESPAWNPLAYERSLEFTBLU";
};
case (EAST): {
wavePlayernamesOpf pushBackUnique _deadPlayerName;
INFO_2("Added player %1 to wavePlayernamesOpf. %2 dead opfor total.", _deadPlayerName, count wavePlayernamesOpf);
WAVERESPAWNPLAYERSLEFTOPF = OPFORWAVESIZE - (count wavePlayernamesOpf);
wavePlayersOpf pushBackUnique _deadPlayer;
INFO_2("Added player %1 to wavePlayersOpf. %2 dead opfor total.", _deadPlayer, count wavePlayersOpf);
WAVERESPAWNPLAYERSLEFTOPF = OPFORWAVESIZE - (count wavePlayersOpf);
publicVariable "WAVERESPAWNPLAYERSLEFTOPF";
};
case (INDEPENDENT): {
wavePlayernamesInd pushBackUnique _deadPlayerName;
INFO_2("Added player %1 to wavePlayernamesOpf. %2 dead opfor total.", _deadPlayerName, count wavePlayernamesInd);
WAVERESPAWNPLAYERSLEFTIND = INDEPWAVESIZE - (count wavePlayernamesInd);
wavePlayersInd pushBackUnique _deadPlayer;
INFO_2("Added player %1 to wavePlayersOpf. %2 dead opfor total.", _deadPlayer, count wavePlayersInd);
WAVERESPAWNPLAYERSLEFTIND = INDEPWAVESIZE - (count wavePlayersInd);
publicVariable "WAVERESPAWNPLAYERSLEFTIND";
};
default {
ERROR_1("Unknown side for player %1", _deadPlayerName);
ERROR_1("Unknown side for player %1", _deadPlayer);
};
};
6 changes: 3 additions & 3 deletions functions/waverespawn/fn_canRespawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ params ["_side"];

_canRespawn = switch (_side) do {
case ("WEST"): {
count wavePlayernamesBlu >= BLUFORWAVESIZE &&
count wavePlayersBlu >= BLUFORWAVESIZE &&
WAVERESPAWNTIMELEFTBLU <= 0
};
case ("EAST"): {
count wavePlayernamesOpf >= OPFORWAVESIZE &&
count wavePlayersOpf >= OPFORWAVESIZE &&
WAVERESPAWNTIMELEFTOPF <= 0
};
case ("INDEPENDENT"): {
count wavePlayernamesInd >= INDEPWAVESIZE &&
count wavePlayersInd >= INDEPWAVESIZE &&
WAVERESPAWNTIMELEFTIND <= 0
};
default {
Expand Down
6 changes: 3 additions & 3 deletions functions/waverespawn/fn_getStatus.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (_side == WEST) then {
case (WAVERESPAWNTIMELEFTBLU > 0): {
"Waiting for wave-countdown.";
};
case (count wavePlayernamesBlu < BLUFORWAVESIZE): {
case (count wavePlayersBlu < BLUFORWAVESIZE): {
"Waiting for more players.";
};
default {
Expand All @@ -23,7 +23,7 @@ if (_side == EAST) then {
case (OPFORWAVESIZE > 0): {
"Waiting for wave-countdown.";
};
case (count wavePlayernamesOpf < OPFORWAVESIZE): {
case (count wavePlayersOpf < OPFORWAVESIZE): {
"Waiting for more players.";
};
default {
Expand All @@ -37,7 +37,7 @@ if (_side == INDEPENDENT) then {
case (INDEPWAVESIZE > 0): {
"Waiting for wave-countdown.";
};
case (count wavePlayernamesInd < INDEPWAVESIZE): {
case (count wavePlayersInd < INDEPWAVESIZE): {
"Waiting for more players.";
};
default {
Expand Down
10 changes: 5 additions & 5 deletions functions/waverespawn/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

if (([missionConfigFile >> "missionsettings","waveRespawnEnabled",0] call BIS_fnc_returnConfigEntry) == 0) exitWith {};

wavePlayernamesBlu = [];
wavePlayernamesOpf = [];
wavePlayernamesInd = [];
wavePlayersBlu = [];
wavePlayersOpf = [];
wavePlayersInd = [];
waitingPlayersBlu = [];
waitingPlayersOpf = [];
waitingPlayersInd = [];
Expand All @@ -16,8 +16,8 @@ if (isServer) then {
[] call grad_waverespawn_fnc_setWaveSize;
[] call grad_waverespawn_fnc_startWaveLoops;
addMissionEventHandler ["HandleDisconnect", {
params [["_unit",objNull],"","",["_name",""]];
[_name,side _unit] call grad_waverespawn_fnc_removeFromWave;
params [["_unit",objNull]];
[_unit,side _unit] call grad_waverespawn_fnc_removeFromWave;
[_unit,side _unit,false] call grad_waverespawn_fnc_addToWaiting;
}];
};
Expand Down
2 changes: 1 addition & 1 deletion functions/waverespawn/fn_onPlayerRespawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

params ["",["_oldUnit",objNull]];

[profileName,playerSide] remoteExec ["grad_waverespawn_fnc_removeFromWave",2,false];
[_oldUnit,playerSide] remoteExec ["grad_waverespawn_fnc_removeFromWave",2,false];
[_oldUnit,playerSide,false] remoteExec ["grad_waverespawn_fnc_addToWaiting",2,false];

setPlayerRespawnTime 99999;
Expand Down
36 changes: 17 additions & 19 deletions functions/waverespawn/fn_removeFromWave.sqf
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
#include "component.hpp"

params ["_unitName","_side"];

_unitName = [_unitName] call BIS_fnc_filterString;
params ["_unit","_side"];

switch (_side) do {
case (WEST): {
if (_unitName in wavePlayernamesBlu) then {
wavePlayernamesBlu deleteAt (([wavePlayernamesBlu,_unitName] call BIS_fnc_arrayFindDeep) select 0);
INFO_1("Player %1 respawned and has been removed from wavePlayernamesBlu.", _unitName);
if (_unit in wavePlayersBlu) then {
wavePlayersBlu deleteAt (wavePlayersBlu find _unit);
INFO_1("Player %1 respawned and has been removed from wavePlayersBlu.", _unit);
} else {
ERROR_1("Player %1 is not in wavePlayernamesBlu.", _unitName);
ERROR_1("Player %1 is not in wavePlayersBlu.", _unit);
};
};

case (EAST): {
if (_unitName in wavePlayernamesOpf) then {
wavePlayernamesOpf deleteAt (([wavePlayernamesOpf,_unitName] call BIS_fnc_arrayFindDeep) select 0);
INFO_1("Player %1 respawned and has been removed from wavePlayernamesOpf.", _unitName);
if (_unit in wavePlayersOpf) then {
wavePlayersOpf deleteAt (wavePlayersOpf find _unit);
INFO_1("Player %1 respawned and has been removed from wavePlayersOpf.", _unit);
} else {
ERROR_1("Player %1 is not in wavePlayernamesOpf", _unitName);
ERROR_1("Player %1 is not in wavePlayersOpf", _unit);
};
};

case (INDEPENDENT): {
if (_unitName in wavePlayernamesInd) then {
wavePlayernamesInd deleteAt (([wavePlayernamesInd,_unitName] call BIS_fnc_arrayFindDeep) select 0);
INFO_1("Player %1 respawned and has been removed from wavePlayernamesInd.", _unitName);
if (_unit in wavePlayersInd) then {
wavePlayersInd deleteAt (wavePlayersInd find _unit);
INFO_1("Player %1 respawned and has been removed from wavePlayersInd.", _unit);
} else {
ERROR_1("Player %1 is not in wavePlayernamesInd", _unitName);
ERROR_1("Player %1 is not in wavePlayersInd", _unit);
};
};

default {ERROR_1("Player %1 is neither WEST nor EAST nor INDEPENDENT.", _unitName)};
default {ERROR_1("Player %1 is neither WEST nor EAST nor INDEPENDENT.", _unit)};
};

[{
WAVERESPAWNPLAYERSLEFTBLU = BLUFORWAVESIZE - (count wavePlayernamesBlu);
WAVERESPAWNPLAYERSLEFTOPF = OPFORWAVESIZE - (count wavePlayernamesOpf);
WAVERESPAWNPLAYERSLEFTIND = INDEPWAVESIZE - (count wavePlayernamesInd);
WAVERESPAWNPLAYERSLEFTBLU = BLUFORWAVESIZE - (count wavePlayersBlu);
WAVERESPAWNPLAYERSLEFTOPF = OPFORWAVESIZE - (count wavePlayersOpf);
WAVERESPAWNPLAYERSLEFTIND = INDEPWAVESIZE - (count wavePlayersInd);
publicVariable "WAVERESPAWNPLAYERSLEFTBLU";
publicVariable "WAVERESPAWNPLAYERSLEFTOPF";
publicVariable "WAVERESPAWNPLAYERSLEFTIND";
Expand Down
6 changes: 3 additions & 3 deletions functions/waverespawn/fn_startWaveLoops.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if (WAVERESPAWNBLU) exitWith {};

//start countdown once first player is added to wave
if (count wavePlayernamesBlu > 0) then {
if (count wavePlayersBlu > 0) then {
WAVERESPAWNTIMELEFTBLU = (WAVERESPAWNTIMELEFTBLU - 1) max 0;
publicVariable "WAVERESPAWNTIMELEFTBLU";
} else {
Expand Down Expand Up @@ -41,7 +41,7 @@
if (WAVERESPAWNOPF) exitWith {};

//start countdown once first player is added to wave
if (count wavePlayernamesOpf > 0) then {
if (count wavePlayersOpf > 0) then {
WAVERESPAWNTIMELEFTOPF = (WAVERESPAWNTIMELEFTOPF - 1) max 0;
publicVariable "WAVERESPAWNTIMELEFTOPF";
} else {
Expand Down Expand Up @@ -74,7 +74,7 @@
if (WAVERESPAWNIND) exitWith {};

//start countdown once first player is added to wave
if (count wavePlayernamesInd > 0) then {
if (count wavePlayersInd > 0) then {
WAVERESPAWNTIMELEFTIND = (WAVERESPAWNTIMELEFTIND - 1) max 0;
publicVariable "WAVERESPAWNTIMELEFTIND";
} else {
Expand Down
2 changes: 1 addition & 1 deletion functions/waverespawn/fn_waveCountdown.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (player getVariable "wr_isFreeRespawn") exitWith {player setVariable ["wr_wav

INFO("Player countdown done. Starting wave countdown...");

[profileName, playerSide] remoteExec ["grad_waverespawn_fnc_addToWave",2,false];
[player,playerSide] remoteExec ["grad_waverespawn_fnc_addToWave",2,false];

[{

Expand Down

0 comments on commit 7aa0d02

Please sign in to comment.