Jump to content
smokeycz

[SOLVED][MP] If player leaves trigger apply only on him removeAllActions

Recommended Posts

Hey, everyone

im having trouble figuring this one out, im trying to remove addAction on player that leaves the trigger. Problem im having is that if some of the players leaves the trigger the .sqf i have deletes it for everyone which i dont want becouse people still standing in the trigger cant activate the action in order to do so they need to leave the trigger and come back inside again.

this is what i currently have

addUserActionPole1.sqf

Quote

if (isServer || isDedicated) exitWith {true};
[[],
 {akce1 = player addAction ["Označit pole", {deleteVehicle Pole1AddKoule;},[],1.5, true, true,"","player in list actiontrigger"];
player setUserActionText [akce1 , "Označit pole", "<img size='3' image='smoke3.paa'/>"];}
] remoteExec ["call"];
 


removeUserActionPole1.sqf

Quote

if (isServer || isDedicated) exitWith {true};
[[],
 {removeAllActions player;}
] remoteExec ["call"];


trigger is set like this:

Quote

 

activation by "anyplayer"
type of action "present"

repeatable is set to true

condition "player in thisList"
activation "pole1Add = execVM ""addUserActionPole1.sqf""
deactivation "pole1Remove = execVM ""removeUserActionPole1.sqf"""

 

 
Mostly its working but it has two problems one i mentioned before but i also have second problem which  is that when two player are in the trigger action is duplicated (having two action in the menu on the left of the screen.)

I would be very humbled if some of you could help me.

Share this post


Link to post
Share on other sites

What I can think of is that you keep a variable on server with all the players in the trigger which you update every time in onactivation.  Then in ondeactivation you compare thisList to that variable and see who's missing.  remoteExec your code on him or add some other kind of check. 

Share this post


Link to post
Share on other sites

1. No need to remoteExec this addAction (keep that for applying an action on a spawned object/unit).

just, in initPlayerLocal.sqf:

akce1 = player addAction ["Označit pole", {deleteVehicle Pole1AddKoule;},[],1.5, true, true,"","<condition here>"];
player setUserActionText [akce1 , "Označit pole", "<img size='3' image='smoke3.paa'/>"];

 

2. the condition field is enough to display/hide the addAction (which is not removed but ready to be displayed). Use preferably the specific local variable (see BIKI)

    "_this inArea actionTrigger"

 

3. So, it's weird to removeAction in this case. But... you need to think about respawning player who will loose all added action:

   add this code (in initPlayerLocal.sqf also):

  player addMPEventHandler ["MPRespawn", {params ["_plyr"]; _plyr addAction ["Označit pole", {deleteVehicle Pole1AddKoule;},[],1.5, true, true,"","_this inArea actionTrigger"]; player setUserActionText [akce1 , "Označit pole", "<img size='3' image='smoke3.paa'/>"]}] }];

 

Suggested whole code in initPlayerLocal.sqf:

fn_akce1 = {
  akce1 = _this addAction ["Označit pole", {deleteVehicle Pole1AddKoule;},[],1.5, true, true,"","_this inArea actionTrigger"];
  _this setUserActionText [akce1 , "Označit pole", "<img size='3' image='smoke3.paa'/>"];
};
player call fn_akce1;
player addMPEventHandler ["MPRespawn", {params ["_plyr"]; _plyr call fn_akce1}];

 

4. As you can see above, the trigger condition itself doesn't matter, you are using its area only. then, the addAction has its own condition related to the player in area of the trigger. This condition is neat but checked on each frame (instead of twice a second for a trigger). And your (action) code seems to be not repeatable (you delete an object without mentioning some re-creation).

So, if you want more help, further questions are:

- Do you need this trigger? is the trigger far from the deleted object? could you replace the trigger area condition by a simple distance to object?

- why not applying the addAction to the object instead of the player (see also BIKI orange framed comment for conditions)? So, no need to think about respawning players.

 

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×