Jump to content
Sign in to follow this  
Ajira

"addPublicVariableEventHandler" not working in multiplayer ?

Recommended Posts

Ok here's the problem...

on init.sqf i check if it's the server or a player that's running it.

If it's a server, it starts the following loop:

while {true} do {
        if (AreaCleared) then {

        while {NewTargetName == _OldTargetName} do {
           NewTargetName = "CombatZone" + str(ceil(random 32));
       };

       _OldTargetName = NewTargetName;
       "CombatZoneMarker" setMarkerPos (getMarkerPos NewTargetName);
       CombatZoneTrigger setPos (getMarkerPos NewTargetName);

       [West,"HQ"] sideChat "New area selected.";

// Do stuff, spawn russians, etc..

   }

   publicVariable NewTargetName;
   sleep 10;
};

This works.. a russian spawns at the marker.. if i kill it, 10 seconds later a russian spawns on another random marker. So... the trigger is moved, and the marker is also moved.

if it's a player that's running the init.sqf it runs the following code:

waitUntil {alive player};

"NewTargetName" addPublicVariableEventHandler {
   "CombatZone" setMarkerPos (getPos CombatzoneTrigger);
};

while {true} do {

   player setVehicleInit "_return = this execVM ""scripts\player_init.sqf""";
   processInitCommands;

   waitUntil {!alive player};

   hint "you died... sucks to be you, man... ";

};

This works fine in the editor, but it doesn't do jack shizzle in multiplayer. The russian guy spawns, but the marker on the map stays rock solid on the old location. For some reason it doesn't see that the variable NewTargetName changed, and so it doesn't move the marker for the user.

first of all, i thought markers were for all users, not per user ? So how come it works for player1 ( unit is "player" ), but not for player 2,3,4,5,6, etc (unit is "playable" ) ? And how come it works for player1, untill he disconnects and then reconnects ? it doesn't work anymore after that.

Any ideas guys ? :confused:

Share this post


Link to post
Share on other sites

How are the "CombatZone" and "CombatZoneMarker" markers created? Are they intended to be the same marker? If they are intended to be the same, and you created it in the editor, you should not need to use the public variable event handler on the client side. The new marker position should be broadcast to all clients.

I would check the error log on the server. I don't see any reason why this code would run any differently on a dedicated server vs a client. You might also post more of your code for us to look at. The problem may lie somewhere else.

Also, I do not think your sidechat call will be broadcast to any clients. For that, I think you will need to make use of a public variable event handler.

Share this post


Link to post
Share on other sites

You're using the command 'publicVariable' wrong, the name of the variable you want to broadcast, must be given in quotes.

publicVariable "NewTargetName";

Share this post


Link to post
Share on other sites

I think i found it.. but not sure.. will have to test in the morning..

CombatZoneTrigger setPos (getMarkerPos NewTargetName);

-vs-

CombatZoneTrigger setPos (getMarkerPos "NewTargetName");

Edited by Ajira

Share this post


Link to post
Share on other sites

using the " " with the publicVariable solved the problem!

Thanks dengibtscchon :D

---------- Post added at 11:34 ---------- Previous post was at 10:43 ----------

hmm.. now just need to figure out how to broadcast the

[West,"HQ"] sideChat "New area selected.";

to all players.

any ideas guys ? :confused:

Share this post


Link to post
Share on other sites

Broadcast it via the same publicVariable you use to trigger the marker repositioning.

Share this post


Link to post
Share on other sites

can you be more specific ? you mean making the marker do the sideChat ?

Share this post


Link to post
Share on other sites
"NewTargetName" addPublicVariableEventHandler { 
 "CombatZone" setMarkerPos (getPos CombatzoneTrigger);
 [West,"HQ"] sideChat "New area selected."; 
};

Share this post


Link to post
Share on other sites

but won't that spam the sideChat bigtime if there's 32 players ? or is it shown only for the current player ?

Share this post


Link to post
Share on other sites

Nevermind that last question.. i've made a very nice/workable solution :)

In the server "loop":

   while {NewTargetName == _OldTargetName} do {
       _random = round(random(7) +1);
       NewTargetName = "CombatZone" + (format ["%1", _random]);
   };

   _message = format ["Enemy forces have been sighted in %1.", (_villages select _random)];
   ServerMessage = [_message, "taskNew"];
   publicVariable "ServerMessage";

and then in the player init:

waitUntil {alive player};
// Update the current target.
"NewTargetName" addPublicVariableEventHandler {
"CombatZoneMarker" setMarkerPos (getPos CombatzoneTrigger);
};
"ServerMessage" addPublicVariableEventHandler {
taskHint [(ServerMessage select 0), [1, 1, 1, 1], (ServerMessage select 1)];
};
//-

Works like a charm, thanks for the tip guys :D

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  

×