Ecco lo script,le condizioni sono nella variabile "_dragCond"
JavaScript:
#define PL_DRAGTEXT "Trascina Corpo" // AddAction text for drag body
#define PL_DROPTEXT "Rilascia Corpo" // AddAction text for dropping body
#define PL_LOADTEXT "Carica Corpo" // AddAction text for dropping body
#define PL_UNLOTEXT "Scarica Corpo" // AddAction text for dropping body
PL_fnc_Action = {
_dragCond = "vehicle _this != vehicle _target and isNull attachedTo _target and count attachedObjects _this == 0 and _target distance _this < 3 and !alive _target";
{
_x addaction [PL_DRAGTEXT,{call PL_DragAction},nil,6,false,false,"",_dragCond];
}forEach _this;
};
PL_DragAction = {
_unit = (_this select 0);
// GLOBALE
_unitID = _unit getVariable "PL_increm";
[[_unit, vehicle player,_unitID],"PL_fnc_attach",true] call BIS_fnc_MP;
_unit attachTo [player,[0,1,0]];
// CLIENT SIDE
player playAction "grabDrag";
player forceWalk true;
_dropID= player addAction [PL_DROPTEXT,{call PL_dropAction},_unit,6];
_hideID =player addAction [PL_LOADTEXT,{call PL_putIncar},_unit,6,false,false,"","_target distance _this < 8 and cursorTarget isKindOf ""LandVehicle"""];
player setVariable ["PLhideVeh",_hideID];
player setVariable ["PLdropact",_dropID];
};
PL_putIncar = {
_hideID = (_this select 2);
_dropID = player getVariable "PLdropact";
_unit = (_this select 3);
_vehicle = cursorTarget;
_loadedBody =_vehicle getVariable "PLloadedBody";
if (isNil "_loadedBody") then {
// CLIENT SIDE
player playMove "amovpknlmstpsraswrfldnon";
player forceWalk false;
player removeAction _hideID;
player removeAction _dropID;
// GLOBALE
_unitID = _unit getVariable "PL_increm";
0 = [[_unit, vehicle player,_unitID],"PL_fnc_detach",true] call BIS_fnc_MP;
sleep 1;
deTach _unit;
_unit setPos [0,0,0];
_vehicle setVariable ["PLloadedBody",_unit,true];
[[_vehicle],"PL_carAction",true] call BIS_fnc_MP;
}else{
hint "Vehicle already has a body loaded";
};
};
PL_carAction = {
_vehicle = (_this select 0);
_vehicle addAction [PL_UNLOTEXT,{call PL_removeBody},nil,0,false,false,"","_this distance _target < 8"];
};
PL_carRemoveAction = {
_vehicle = (_this select 0);
_id = (_this select 1);
_vehicle removeAction _id;
};
PL_removeBody = {
_vehicle = (_this select 0);
_player = (_this select 1);
_id = (_this select 2);
[[_vehicle,_id],"PL_carRemoveAction",true] call BIS_fnc_MP;
_unit = _vehicle getVariable "PLloadedBody";
_vehicle setVariable ["PLloadedBody",Nil];
_pos = _player modelToWorld [1,0,0];
_unit setPos _pos;
_unit switchMove "AinjPpneMstpSnonWrflDb_release";
};
PL_dropAction = {
_dropID = (_this select 2);
_hideID = player getVariable "PLhideVeh";
_unit = (_this select 3);
// GLOBALE
_unitID = _unit getVariable "PL_increm";
0 = [[_unit, vehicle player,_unitID],"PL_fnc_detach",true] call BIS_fnc_MP;
deTach _unit;
// CLIENT
player removeAction _hideID;
player removeAction _dropID;
player playMove "amovpknlmstpsraswrfldnon";
player forceWalk false;
};
PL_fnc_attach = {
_unit = (_this select 0);
_player = (_this select 1);
_unitID = (_this select 2);
_id = format ["PLEF%1",_unitID];
0 = [_id, "onEachFrame", "PL_fnc_moveBody",[_unit,_player]] call BIS_fnc_addStackedEventHandler;
};
PL_fnc_detach = {
_unit = (_this select 0);
_player = (_this select 1);
_unitID = (_this select 2);
_id = format ["PLEF%1",_unitID];
0 = [_id, "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
sleep 0.05;
_relD = [_unit,_player] call BIS_fnc_dirTo;
_unit switchMove "AinjPpneMstpSnonWrflDb_release";
_unit setDir _relD;
};
PL_fnc_moveBody = {
_unit = (_this select 0);
_player = (_this select 1);
_pos = _player modelToWorld [0,1,0];
_unit setPos _pos;
_unit setDir 180;
_unit switchMove "AinjPpneMrunSnonWnonDb";
};
PL_addDrag = {
{
PL_increments = PL_increments + 1;
_x setVariable ["PL_increm",PL_increments,true];
PL_dragUnitArray set [count PL_dragUnitArray, _x];
}forEach _this;
[_this,"PL_fnc_Action",TRUE] call BIS_fnc_MP;
publicVariable "PL_increments";
publicVariable "PL_dragUnitArray";
};
if (isServer) then {
if (isNil ("PL_dragUnitArray")) then {
PL_dragUnitArray = [];
PL_increments = 0;};
{
PL_increments = PL_increments + 1;
_x setVariable ["PL_increm",PL_increments,true];
PL_dragUnitArray set [count PL_dragUnitArray, _x];
}forEach _this;
publicVariable "PL_increments";
publicVariable "PL_dragUnitArray";
};
if (!isServer && (player != player)) then { waitUntil {player == player}; waitUntil {time > 15};};
if (!isDedicated) then {
0 = PL_dragUnitArray spawn PL_fnc_Action;
};