From 7aa0d02acc136315e1df6ecf2882ed26fc358428 Mon Sep 17 00:00:00 2001 From: McDiod Date: Tue, 20 Nov 2018 20:09:31 +0100 Subject: [PATCH] move waverespawn from saving names to saving units --- functions/waverespawn/fn_addToWave.sqf | 30 ++++++++-------- functions/waverespawn/fn_canRespawn.sqf | 6 ++-- functions/waverespawn/fn_getStatus.sqf | 6 ++-- functions/waverespawn/fn_init.sqf | 10 +++--- functions/waverespawn/fn_onPlayerRespawn.sqf | 2 +- functions/waverespawn/fn_removeFromWave.sqf | 36 +++++++++----------- functions/waverespawn/fn_startWaveLoops.sqf | 6 ++-- functions/waverespawn/fn_waveCountdown.sqf | 2 +- 8 files changed, 47 insertions(+), 51 deletions(-) diff --git a/functions/waverespawn/fn_addToWave.sqf b/functions/waverespawn/fn_addToWave.sqf index 714a146..ba79ef8 100644 --- a/functions/waverespawn/fn_addToWave.sqf +++ b/functions/waverespawn/fn_addToWave.sqf @@ -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); }; }; diff --git a/functions/waverespawn/fn_canRespawn.sqf b/functions/waverespawn/fn_canRespawn.sqf index 0995763..b36f145 100644 --- a/functions/waverespawn/fn_canRespawn.sqf +++ b/functions/waverespawn/fn_canRespawn.sqf @@ -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 { diff --git a/functions/waverespawn/fn_getStatus.sqf b/functions/waverespawn/fn_getStatus.sqf index c357306..abd30cf 100644 --- a/functions/waverespawn/fn_getStatus.sqf +++ b/functions/waverespawn/fn_getStatus.sqf @@ -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 { @@ -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 { @@ -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 { diff --git a/functions/waverespawn/fn_init.sqf b/functions/waverespawn/fn_init.sqf index 4f8987b..d70f747 100644 --- a/functions/waverespawn/fn_init.sqf +++ b/functions/waverespawn/fn_init.sqf @@ -2,9 +2,9 @@ if (([missionConfigFile >> "missionsettings","waveRespawnEnabled",0] call BIS_fnc_returnConfigEntry) == 0) exitWith {}; -wavePlayernamesBlu = []; -wavePlayernamesOpf = []; -wavePlayernamesInd = []; +wavePlayersBlu = []; +wavePlayersOpf = []; +wavePlayersInd = []; waitingPlayersBlu = []; waitingPlayersOpf = []; waitingPlayersInd = []; @@ -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; }]; }; diff --git a/functions/waverespawn/fn_onPlayerRespawn.sqf b/functions/waverespawn/fn_onPlayerRespawn.sqf index c21aee1..31abc21 100644 --- a/functions/waverespawn/fn_onPlayerRespawn.sqf +++ b/functions/waverespawn/fn_onPlayerRespawn.sqf @@ -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; diff --git a/functions/waverespawn/fn_removeFromWave.sqf b/functions/waverespawn/fn_removeFromWave.sqf index 526ac0c..e97110c 100644 --- a/functions/waverespawn/fn_removeFromWave.sqf +++ b/functions/waverespawn/fn_removeFromWave.sqf @@ -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"; diff --git a/functions/waverespawn/fn_startWaveLoops.sqf b/functions/waverespawn/fn_startWaveLoops.sqf index febafba..9cb84fe 100644 --- a/functions/waverespawn/fn_startWaveLoops.sqf +++ b/functions/waverespawn/fn_startWaveLoops.sqf @@ -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 { @@ -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 { @@ -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 { diff --git a/functions/waverespawn/fn_waveCountdown.sqf b/functions/waverespawn/fn_waveCountdown.sqf index c1de153..5e5a520 100644 --- a/functions/waverespawn/fn_waveCountdown.sqf +++ b/functions/waverespawn/fn_waveCountdown.sqf @@ -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]; [{