Jump to content
Sign in to follow this  
TMan10K

Action Locality

Recommended Posts

Hello all.

I have a script called from an addaction command that needs to affect global objects. The addaction starts on an object added by the editor, which all players can see. Once an individual selects the action, the script only runs on their computer.

Other players can see the effects of this script, which is fine, however the script adds actions to new objects in the script, which only that player can select in the menu. I understand that's probably because only that player called the script, but even using global variables (i.e without an underscore prefix) for objects and adding actions, it still remains only on the original caller's system.

I used a hint format for X/Y of the object. On their screen it gives the co-ordinates whereas on my screen it errors due to the object claiming not to exist, even though I can see it.

If there's some way of adding actions and so on globally rather than just that player, I'd be grateful for some help.

Here's some snippets to give a rough idea of what I'm trying to do, though obviously I've made it a bland example (sqs format)

object1 = nearestobject [(_this select 1),"objectstring"]

object2 = "objectstring" createVehicle [(getpos object1 select 0), (getpos object1 select 1), 0]

object2 addaction ["string","script.sqs",null,-1,false,true]

Thank you in advance. smile_o.gif

Share this post


Link to post
Share on other sites

There's a big difference between locallity.

Variable locallity describes in which scope variables are seen

Function locallity describes the effect of the result of the functions

Object locallity describes which computer handles the object

_test = 1;

test = 1;

Both variables are only available on the computer where you execute it. _test is only available inside the script where you defined it. test is available in any script because it's a global variable.

You will have to work out a system with triggers (or alike) and thus execute the addAction command on every computer.

addAction is a local command, basicly meaning that the effect is not broadcasted to other computers.

If you addAction in init.sqf or other global scripting fields, it will mean that the addAction command is executed on every machine. As soon as a player executes the action, the action/script only executes on his computer and as such the changes are only visible on his computer and not on the others.

You can resolve this by using a network engine that executes commands on every computer, v1.09 compatible example (Initialize in init.sqf): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"T_EXEC" addPublicVariableEventHandler { _v = _this select 1; (_v select 0) call (_v select 1)  };

T_fSend = { T_EXEC = this; publicVariable "T_EXEC"; (_this select 0) call (_this select 1) };

Now all you gotto do is change the code for remove/addAction to use this T_fSend function in this manner (example), Change: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">object1 = nearestobject [(_this select 1),"objectstring"]

object2 = "objectstring" createVehicle  [(getpos object1 select 0), (getpos object1 select 1), 0]

object2 addaction ["string","script.sqs",null,-1,false,true]

Into: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">object1 = nearestobject [(_this select 1),"objectstring"]

object2 = "objectstring" createVehicle  [(getpos object1 select 0), (getpos object1 select 1), 0]

[object2, {_this addAction ["string","script.sqs",null,-1,false,true]}] call T_fSend;

You can find a scripting guide for MP in my signature.

Share this post


Link to post
Share on other sites

Thank you for the reply. I knew it was do to with locality as it was only being executed on that particular player's machine. I'll give the publicvariable code you described a go today and report back.

Cheers again.

Edit: It seems the event handler function is only available in v1.09, so I'll have to wait until then.

Share this post


Link to post
Share on other sites
Thank you for the reply. I knew it was do to with locality as it was only being executed on that particular player's machine. I'll give the publicvariable code you described a go today and report back.

Cheers again.

Edit: It seems the event handler function is only available in v1.09, so I'll have to wait until then.

As Advertised smile_o.gif

And NP smile_o.gif

Instead of the addPublicVariableEventHandler method, you could create other solutions, e.g. with setVehicleInit and processInitCommands. Or with 2 publicVariables and a waitUntil loop on the receiver ends to wait for variable updates.

In any case, I do believe waiting for the final v1.09/or whatever patch it's gonna be, is the better choice, because the solutions available are a lot cleaner and better in 1.09 smile_o.gif

You could simply use the beta though, at least while developing it?

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
Sign in to follow this  

×