Jump to content
Sign in to follow this  
{USI}_Zombie

Random waypoints changing?

Recommended Posts

I have a squad, where the group leader has a placement radius of 3500, and I make a random waypoint by using this

init="groupred = group this; [this, ""teamleader""] call (compile (preprocessFileLineNumbers ""init_loadout.sqf"")); [groupred, 1] setWaypointPosition [position u1, 2500];  ";

in his init. That all works fine, the problem is, when another player loads the map, it will change the waypoint. Playtesting this on my computer, hosting, I will load the map 1st, then when another player finally gets it downloaded and all, the waypoint will move. I can tell even before I launch the waypoint has moved because I also use this

"lz" setMarkerPos getWPPos [groupred,1];
"stp" setmarkerpos getpos leader groupred;

and it works too. I can't figure why the setwaypointposition would be re-called by another player when I am only running it from 1 of them.

Share this post


Link to post
Share on other sites

init lines are executed by every client, even by people who JIP in. So in effect every client is running that random command and they come up with different values, and then set the WPPos to that. Big problem.

So a basic rule is when you're using random is to let the server handle random number creation, and have the clients wait until the server broadcasts that number to them.

some code out of my head (might be wrong)

if (isServer) then
{
 randomNum =  random 10;
 publicVariable "randomNum";
};
waitUntil { !isNil "randomNum" };

and now you can start using the random number in your script, because only 1 machine made the random number, and sends it to everyone. Btw, the value of the variable when it got publicVariabled will be synched on JIP, so this should work fine.

Edited by Mike84

Share this post


Link to post
Share on other sites

thanks mike, but that is not exactly the problem. I didn't know about what you posted so I did learn something though.

The issue is the game is creating a random number somewhere. All units have a placement radius of 3500, which adds a random variable somewhere. Then the command :

[groupred, 1] setWaypointPosition [position u1, 2500];  

if I understand it, sets groupred's waypoint 0 (in the editor it's wp 0) to a random position in the radius of 2500, centered on unit u1, again somewhere in the background.

Can I put my above code in the init.sqf prefaced with if (isServer) then ?

if (isServer) then
{
[groupred, 1] setWaypointPosition [position u1, 2500];
};

?

Share this post


Link to post
Share on other sites

Waypoint 0 in the editor is also waypoint 0 in the script last time I checked...

So you set the only waypoint a unit has with [groupred, 0] setWaypointPosition [position u1, 2500], I would guess...

Share this post


Link to post
Share on other sites
Waypoint 0 in the editor is also waypoint 0 in the script last time I checked...

So you set the only waypoint a unit has with [groupred, 0] setWaypointPosition [position u1, 2500], I would guess...

Actually I tested it and the 1st waypoint is called 0 in the editor, but the script does need 1 as I did originally. Got the syntax from this thread

Share this post


Link to post
Share on other sites

Got it working by using

if (isServer) then
{
[groupred, 1] setWaypointPosition [position u1, 2500];
};

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  

×