summaryrefslogtreecommitdiffstats
path: root/Client/Functions/Client_OnRespawnHandler.sqf
blob: fe6c57d52cca0e7c6869ba45ad7a9151bcce5645 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Private ["_buildings","_charge","_funds","_loadDefault","_listbp","_mode","_price","_safeArray","_skip","_spawn","_spawnInside","_temp","_unit","_weaps"];

_unit = _this select 0;
_spawn = _this select 1;
_loadDefault = true;

//--- Respawn.
_spawnInside = false;
if ((typeOf _spawn) in (Format ["WFBE_%1AMBULANCES",sideJoinedText] Call GetNamespace) && alive _spawn) then {
	if (_spawn emptyPositions "cargo" > 0 && !(locked _spawn)) then {_unit moveInCargo _spawn;_spawnInside = true};
};

if !(_spawnInside) then {_unit setPos ([getPos _spawn,10,20] Call GetRandomPosition)};

//--- Loadout.
if (!isNil "respawnWeapons" && !WFBE_RespawnDefaultGear) then {
	_mode = 'WFBE_RESPAWNPENALTY' Call GetNamespace;
	
	if (_mode in [0,2,3,4,5]) then {
		//--- Calculate the price/funds.
		if (_mode != 0) then {
			_price = 0;
			
			//--- Get the mode pricing.
			switch (_mode) do {
				case 2: {_price = respawnGearCost};
				case 3: {_price = round(respawnGearCost/2)};
				case 4: {_price = round(respawnGearCost/4)};
				case 5: {_price = respawnGearCost};
			};
			
			//--- Are we charging only on mobile respawn?
			_charge = true;
			if (_mode == 5) then {
				_buildings = (sideJoinedText) Call GetSideStructures;
				if (_spawn in _buildings || _spawn == ((sideJoinedText) Call GetSideHQ)) then {_charge = false};
			};
			
			if (_charge) then {
				//--- Charge if possible.
				_funds = Call GetPlayerFunds;
				if (_funds < _price) then {
					// Just take it down to zero.
					_price = _funds;
				};
				-(_price) Call ChangePlayerFunds;
				(Format[localize 'STR_WF_CHAT_Gear_RespawnCharge',_price]) Call GroupChatMessage;
			};
		};
		
		//--- Use the respawn loadout.
		if(WF_ACE) then
		{
			[player, respawnWeapons, respawnAmmo] Call EquipLoadout;
			player setVariable ["ACE_weapononback", respawnWeaponOnBack];
			_safeArray = respawnAceRuckContents select 1;
			player setVariable ["ACE_RuckMagContents", +_safeArray];
			_safeArray = respawnAceRuckContents select 0;
			player setVariable ["ACE_RuckWepContents", +_safeArray];
		}
		else
		{
			_temp = +(respawnWeapons);
			_listbp = 'WFBE_BACKPACKS' Call GetNamespace;
			{if (_x in _listbp) then {_temp = _temp - [_x]}} forEach respawnWeapons;
			_weaps = _temp;
			
			[_unit,_weaps,respawnAmmo] Call EquipLoadout;
			if !(WF_A2_Vanilla) then {Call RespawningBag};
		};
		_loadDefault = false;
	};
};

//--- Load the default loadout.
if (_loadDefault) then {
	player Call EquipDefaultLoadout;
};