Jump to content
haleks

Trigger Code Locality question

Recommended Posts

Hi guys!

 

I'm working on an MP mod wich involves triggers to run various functions.

Let's say the triggers are created on a dedicated server :

_trg = createTrigger ["EmptyDetector", _pos, true];
_trg setTriggerStatements ["(vehicle player) in thislist", "0 = [thisTrigger] spawn someFunction", ""];

The global setting for the trigger is set to true so that the trigger exists on all machines; question is : where does the function called on activation run from?

Is it always executed by the server (or the machine the triggers were created on), or does it run from the client who activated the trigger (in wich case I would need to broadcast the function...)?

 

I couldn't find any answers on the wiki nor on the forum. :/

Share this post


Link to post
Share on other sites

Triggers execute wherever their condition is met but they dont broadcast anything. They're local.

 

And since you're checking for player inside the trigger, it will never trigger on a dedicated server. Only on clients.

  • Like 1

Share this post


Link to post
Share on other sites

You dont need global object if you want it to trigger on server only. The function will run on the machine where you setTriggerStatement, doesnt matter if the trigger is global or local, this is why I'm saying might as well make it local to the server.

 

And as tajin pointed you cannot use player on server, substitute it with player object or use trigger native detection.

  • Like 1

Share this post


Link to post
Share on other sites

Triggers execute wherever their condition is met but they dont broadcast anything. They're local.

 

And since you're checking for player inside the trigger, it will never trigger on a dedicated server. Only on clients.

 

I read on the wiki that you can make them global since Arma3 v1.43.

 

Let's say I want to limit the activation code to the server only : shall I make them local and change the activation conditions?

 

EDIT : Thanks Killzone Kid, that answers it!

Share this post


Link to post
Share on other sites
You dont need
You dont need global object if you want it to trigger on server only. The function will run on the machine where you setTriggerStatement, doesnt matter if the trigger is global or local, this is why I'm saying might as well make it local to the server.

And as tajin pointed you cannot use player on server, substitute it with player object or use trigger native detection.

Hi KK. Native detection would be for example "Bluforce present" correct?

Share this post


Link to post
Share on other sites

Hi KK. Native detection would be for example "Bluforce present" correct?

Yes, the trigger activation blufor, opfor, anybody...present/notpresent etc.

Share this post


Link to post
Share on other sites

 

I read on the wiki that you can make them global since Arma3 v1.43.

 

 

 

Triggers are global by default and you can force a trigger to  be local on machine where the trigger are created ( scripted in).

 

Global means that on trigger activation the code will be executed on every machine . If you need to run the code  only on server if (isServer) statement are required.

Share this post


Link to post
Share on other sites

 

 

Global means that on trigger activation the code will be executed on every machine . If you need to run the code  only on server if (isServer) statement are required.

 

This is not true, please don't start confusion. Global trigger is just global object in game, the trigger statements are local to every machine, and need to be set up on every PC individually. If you want teh same statements everywhere, you can put trigger in editor. If you do it scripted way, you will have to manually execute setTriggerStatement on every PC and JIP

Share this post


Link to post
Share on other sites

If the trigger statements are local to every machine it is not global then?

Share this post


Link to post
Share on other sites

This is not true, please don't start confusion. Global trigger is just global object in game, the trigger statements are local to every machine, and need to be set up on every PC individually. If you want teh same statements everywhere, you can put trigger in editor. If you do it scripted way, you will have to manually execute setTriggerStatement on every PC and JIP

 

Wich makes me wonder, what is the advantage of having global triggers in the first place?

Eventhough they are global objects, we still have to deal with locality issues?

Share this post


Link to post
Share on other sites

Wich makes me wonder, what is the advantage of having global triggers in the first place?

Eventhough they are global objects, we still have to deal with locality issues?

local triggers are relatively new and apart from not causing trigger spam on the server when clients diconnect they are quite handy when only local handling is needed. Global triggers were mainly used for editor triggers, so that when mission from editor runs, the statements added to the same object everywhere. Basically for scripting purposes you can go with just local triggers, unless you want to move them about, then moving global is easier. Also radio triggers will need to be global, because radio execution is global, even if statements are still local.

  • Like 1

Share this post


Link to post
Share on other sites

Locality really screws with my head. KK can you please point me to where I can read more about triger locality and using them more effectively in a mp environment. I never thought much about it till a month ago when a editor trigger spawning units kept on firing during a coop session. I have now added if Server exit with statements in my spawning scripts but sounds to me its not the correct way to address the issue.

Share this post


Link to post
Share on other sites

Locality really screws with my head. KK can you please point me to where I can read more about triger locality and using them more effectively in a mp environment. I never thought much about it till a month ago when a editor trigger spawning units kept on firing during a coop session. I have now added if Server exit with statements in my spawning scripts but sounds to me its not the correct way to address the issue.

 

I was writing tutorials on triggers at different times as I was figuring this out for myself, feel free to poke around http://killzonekid.com/tag/triggers/ (might not be 100% correct, some changes since + i was learning myself)

  • Like 1

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

×