Jump to content
Sign in to follow this  
vapour

Script problem in multiplayer

Recommended Posts

Hi, I'm afraid this one of the questions about scripts that run fine until they are put in multiplayer, then it all turns to custard.

I've tried to get my head around ? !(local server):exit and public, private varuables and such, but I guess I'm just too thick to understand it all.

What I've got here is a couple of scripts that run off an addAction. One that I've placed on a radio in the mission, the other on an AI.

With the radio script, one of the players walks up to the radio and uses it to call for extraction details.

The talking can be heard via an ogg file and a new marker appears on the map showing the extraction point.

sub2 = createMarker ["extract", getMarkerpos "SubMove"];
"extract" setMarkerType "end";
"extract" setMarkerText "Extraction";

_caller = _this select 1;

_caller say "Extract";

Radio1 removeaction 0;

The radio is variable Radio1

The addAction command sends the player who used the radio as variable _caller

Works great in single player testing, but when tested with other players, the ogg file is only getting heard by the person who activated the radio.

Tried adding a Server gamelogic and putting the "if not server" stuff at the beginning of the script, but then it prevents any of the players from being able to execute the script at all.

Similar problem with the second addAction script. Only the person who initialised the talk with the AI can hear or see the conversation happenning.

PL say "A_Greet";

PL removeaction 0;

OBJ_LIAISE SetTaskState "SUCCEEDED";

Also the removeaction is only happenning on the initialising players computer, as all the other players are still able to use the same addAction after the initial person has.

So I assume that what is happenning is that the script is only getting executed by the players computer, and what I need is for it to execute on everyones computer?

I think some of the script may need to be executed on the server as well, such as createMarker and OBJ_LIAISE SetTaskState "SUCCEEDED", but I'm not really sure.

If someone can guide me in the right direction with this, I'd be very grateful.

Share this post


Link to post
Share on other sites

a theory, try this:

if (isPlayer) then {Radio1 removeaction 0};

try same for the say part.

Share this post


Link to post
Share on other sites

Here is the full deal. addAction is a local command. Obviously, putting in the initline of the object runs it for every machine. So every person locally does it. Do to the local nature, it also only is able to run and be removed on that persons machine. In order for everyone to hear the noise, your going to have to use addPublicVariableEventHandler to broadcast a request to everyones computer to play that noise.

So basically, establish the event handler like it explains here:

http://community.bistudio.com/wiki/addPublicVariableEventHandler

Then to request all the machines to play the sound, your going to want the variable that the event handler is monitoring to be broadcasted via publicVariable "variable" on the callers machine.

Also, make sure you play the sound on the callers machine in the script because the event handler wont play on the broadcasters machine.

Share this post


Link to post
Share on other sites

Thanks heaps for your reply tacticalnuggets.

I'm obviously as thick as two planks though, because I mainly get what you're saying about that it's only executing the actual script on the callers machine, but that addPublicVariableEventHandler has got me completely miffed.

I don't know anything about Event Handlers, and trying to read through that link has completely twisted my head in.

Are you able to (:o grovel 'please') add into my script the appropriate bits so that I can actually see what needs to be in there?

Share this post


Link to post
Share on other sites

Put this in your init script:

"actionpv" addPublicVariableEventHandler {_var=_this select 1;_var select 0 say (_var select 1);_var select 2 removeAction 0};

Modify your action script like so:

sub2 = createMarker ["extract", getMarkerpos "SubMove"];
"extract" setMarkerType "end";
"extract" setMarkerText "Extraction";

_caller = _this select 1;
_caller say "Extract";
Radio1 removeaction 0;

actionpv=[_caller,"Extract",Radio1];
publicVariable "actionpv";

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  

×