PDA

View Full Version : Respawn, addAction & setVehicleInit



Wiggum
Dec 11 2011, 10:47
Hi !

I add a respawn Eventhandler to every player inside the init.sqf:

if (!isDedicated) then {
[] spawn {
waitUntil {!isNull player};
player addEventhandler ["respawn", {_this execvm "respawn.sqf"}];
};
};

Thats how i add action to all players inside the init.sqf:

// Actions
if (!isDedicated) then {
[] spawn {
waitUntil {!isNull player};
_structure="<t font='EtelkaMonospaceProBold' size='0.8' color='#885555ff'>";
[player] execVM "playerMarkers.sqf";
[player] exec "limbheal.sqs";
_actionId1 = player addAction [format ["%1Heilen</t>",_structure],"heal.sqf", [], -1, false, true, "", "(_target == _this) && (damage _this > 0)"];
_actionId2 = player addAction [format ["%1Teleportieren</t>",_structure],"teleport.sqf", [], -1, false, true, "", "(_target == _this) && ( _this distance teleport < 5)"];
_actionId3 = player addAction [format ["%1Luftschlag anfordern</t>",_structure],"support\airstrike.sqf",[10,"Bo_GBU12_LGB",1], -1, false, true, "", "(_target == _this) && (Airstrike_Count > 0) && (Airstrike_Busy == 0)"];
_actionId4 = player addAction [format ["%1Nachschubabwurf anfordern</t>",_structure],"support\supplydrop.sqf",[25,"HMMWV_M998_crows_M2_DES_EP1",200], -1, false, true, "", "(_target == _this) && (Supply_Count > 0) && (Supply_Busy == 0)"];
_actionId5 = player addAction [format ["%1Artillerieschlag anfordern</t>",_structure],"support\artillery.sqf",[150,10,"ARTY_Sh_82_HE",5,1], -1, false, true, "", "(_target == _this) && (Artillery_Count > 0) && (Artillery_Busy == 0)"];
PXS_action = player addAction [format ["%1Satellitenverbindung herstellen</t>",_structure],"pxs_satcom_oa\start_satellite.sqf", [], -1, false, true, "", "(_target == _this)"];
};
};

Now, if a player dies and respawns, i want him to respawn with the weapons he had and give him all actions back.
This is the respawn.sqf:

private ["_unit","_corpse","_w","_m","_b","_bm","_bw","_structure"];

_unit = _this select 0;
_corpse = _this select 1;

_w = weapons _corpse;
_m = magazines _corpse;
_b = typeOf unitBackpack _corpse;
_bm = getMagazineCargo unitBackpack _corpse;
_bw = getWeaponCargo unitBackpack _corpse;
deleteVehicle _corpse;

_structure="<t font='EtelkaMonospaceProBold' size='0.8' color='#885555ff'>";

removeAllWeapons _unit;
removeAllItems _unit;
removeBackpack _unit;
{ _unit addmagazine _x } foreach _m;
{ _unit addweapon _x } foreach _w;
if(_b != "") then {
_unit addBackpack _b; clearWeaponCargo (unitBackpack _unit); clearMagazineCargo (unitBackpack _unit);
for "_i" from 0 to (count (_bm select 0) - 1) do {
(unitBackpack _unit) addMagazineCargo [(_bm select 0) select _i,(_bm select 1) select _i];
};
for "_i" from 0 to (count (_bw select 0) - 1) do {
(unitBackpack _unit) addWeaponCargo [(_bw select 0) select _i,(_bw select 1) select _i];
};
};
_unit setVehicleInit "
[player] execVM ""playerMarkers.sqf"";
[player] exec ""limbheal.sqs"";
_actionId1 = player addAction [format [""%1Heilen</t>"",_structure],""heal.sqf"", [], -1, false, true, """", ""(_target == _this) && (damage _this > 0)""];
_actionId2 = player addAction [format [""%1Teleportieren</t>"",_structure],""teleport.sqf"", [], -1, false, true, """", ""(_target == _this) && ( _this distance teleport < 5)""];
_actionId3 = player addAction [format [""%1Luftschlag anfordern</t>"",_structure],""support\airstrike.sqf"",[10,""Bo_GBU12_LGB"",1], -1, false, true, """", ""(_target == _this) && (Airstrike_Count > 0) && (Airstrike_Busy == 0)""];
_actionId4 = player addAction [format [""%1Nachschubabwurf anfordern</t>"",_structure],""support\supplydrop.sqf"",[25,""HMMWV_M998_crows_M2_DES_EP1"",200], -1, false, true, """", ""(_target == _this) && (Supply_Count > 0) && (Supply_Busy == 0)""];
_actionId5 = player addAction [format [""%1Artillerieschlag anfordern</t>"",_structure],""support\artillery.sqf"",[150,10,""ARTY_Sh_82_HE"",5,1], -1, false, true, """", ""(_target == _this) && (Artillery_Count > 0) && (Artillery_Busy == 0)""];
PXS_action = player addAction [format [""%1Satellitenverbindung herstellen</t>"",_structure],""pxs_satcom_oa\start_satellite.sqf"", [], -1, false, true, """", ""(_target == _this)""];
";
processInitCommands;


Now the problem is that if player 1 respawns, player 2 gets double actions sometimes:
http://www.abload.de/img/unbenannt3vzrn.png

As you can see the double Actions have a any infront of them (clearly _structure is local).
Now i know that setVehicleInit will be:

The statement will be sent to clients connecting after the command has been executed.

So should i just use a local check before the setVehicleInit ?

if (local _unit) then {
// addActions
};

Is this correct or do i have to do something else too ?

Muzzleflash
Dec 11 2011, 10:54
You should not use setVehicleInit at all. setVehicleInit sets that string of code on all machines. When you processInitCommands every machine then executes that string. What does the string code do? It say the player object (which is always local, and there is one on almost every machine) should have those actions added.

Just add the actions directly (normal code) instead.

Bon
Dec 11 2011, 11:11
NVM, read it wrong.

Wiggum
Dec 11 2011, 11:19
Thanks Muzzleflash, sometimes its that easy... :o
I not know why i added the setVehicleInit, but i always thought i would need it...