bn880 5 Posted November 7, 2001 In one of my MP missions I have: 1. ceated random time of day after loading mission 2. created a random length fog in the morning 3. a random overcast to occur during a 24h period The problem is that the Random() function is used to generate random times for all these functions. If I put a Random() in a trigger or script, it is executed on all client machines seperatly giving different random numbers. I tried using PublicVariable and that does not help. Â Is there a simple way to pass Variables in this sim? The solution I came up with is placing a GameLogic Object at some known coords on the map with a placement radius of 1/2 of what I want the maximum random number to be. Â Reading the X Â or Z coords of the GameLogic objects after the mission starts and doing some subtracting will provide a random number that all clients can access. Anyway, there should and probably is a proper way to pass variables to all clients. Share this post Link to post Share on other sites
DEMONIAC 0 Posted November 8, 2001 This is a very simple script to change the weather, fog level, date and time of day at the start of the mission. It can be useful to add variability to missions. Script "environment.sqs" ----- ; Set weather type: _W = Random 1 0 setovercast _W ; Set fog level: _F = Random 1 0 setfog _F ; Change date (note 8760 = 365days * 24 hours): _D = Random 8760 skiptime _D ; Exit the script exit ------ It is important to set the date and time of the level in which you use this script to January 1st, at 0000hrs as it uses the SkipTime function to add a random number of hours to this time. You can call this through another initialise script, or by placing the following line into a "true" trigger or unit's Initialize line: [] exec "environment.sqs" One thing I'll add is that you might want to change the fog random number to 0.5 instead of 1. I tried a mission last night which had a fog level of 0.98 - it was practically impossible to play - I couldn't see 3ft in front of me! i found this somewhere might be helpfull to ya Share this post Link to post Share on other sites
bn880 5 Posted November 8, 2001 Thanks but this script will still create different weather and time for every client in a MP game. As far as I know. The trick I am looking for is to make sure it is the same on all clients. Share this post Link to post Share on other sites
DEMONIAC 0 Posted November 8, 2001 ahh ok ill look into that Share this post Link to post Share on other sites
Shirson 0 Posted November 8, 2001 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">Quote: from bn880 on 8:39 am on Nov. 8, 2001 Thanks but this script will still create different weather and time for every client in a MP game. As far as I know. The trick I am looking for is to make sure it is the same on all clients. <span id='postcolor'> Try this idea. Create two 5t trucks named tFog and tOvercast and place far away. (or put underground) After start mission start script [tFog, tOvercast] exec "enviroment.sqs" ;------------------------- _Fog = _this select 0 _Over = _thist select 1 _fog setdammage random 1 _Over setdammage random 1 ; ~1 0 setfog getdammage _fog 0 setovercast getdammage _Over exit ;------------------------- Heh. Å¡Using two trucks for global variables. P.S. How u using publicVariable? Like this? ;------------------------- _fog=random1 _over = random 1 PublicVariable _fog PublicVariable _over ~1 0 setfog _fog 0 setover _fog exit ;------------------------- (Edited by Shirson at 6:52 pm on Nov. 8, 2001) Share this post Link to post Share on other sites
bn880 5 Posted November 8, 2001 Yes well that's alot like placing GameLogic objects in a random pos and getting their X|Y|Z. I think your way is simpler but generates a number from 0 to 1, I actually need different maximum value random numbers such as 0-2 and 0-24. I guess I can just multiply the truck damage by 2 or 24. I used public variable like this: --------------------------------- PublicVariable "startOvercast" startOvercast = Random 24 . . --------------------------------- Even your method is just a workaround to something that should or is implemented in the game (passing variables) 8¬) Share this post Link to post Share on other sites
zovirl 0 Posted November 16, 2001 How exactly does it work in MP when everyone has different random numbers? Everyone gets different time/weather/fog and play continues normally? What happens if you try to do something like a SetPos with a random number? The bad guy is in a different spot for everyone? Seems like this would start to break things... Share this post Link to post Share on other sites
bn880 5 Posted November 16, 2001 Yes, this means there is different time/rain/fog for everyone... If you do SetPos then the object position will be the same for everyone. If two clients do a SetPos then the one that executes later is going to determine the final position of the object. I am sure even this can break multiplayer games. Share this post Link to post Share on other sites
HappyG 0 Posted November 19, 2001 I also have the same problem. I think that solution with vehicles is quite s**tty, also in 24 players game there would be 24 clients trying to change the position of the vehicle... Is there any chance to check out if script is running on server or on client, so we could perform random functions only on server? I would also like to get the answer from one of the developers... Share this post Link to post Share on other sites
zovirl 0 Posted November 19, 2001 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">Quote: from HappyG on 6:51 pm on Nov. 19, 2001 I also have the same problem. I think that solution with vehicles is quite s**tty, also in 24 players game there would be 24 clients trying to change the position of the vehicle... Is there any chance to check out if script is running on server or on client, so we could perform random functions only on server? I would also like to get the answer from one of the developers...<span id='postcolor'> I saw this on one of the boards. I haven't had a chance to try it yet, so hopefully someone more knowledgable will comment if I make a mistake with it Make a game logic item on your map, call it Server. Now, you can use the Local command to see if the map is on the server or not ? (local Server) : goto "Server" ? !(local Server) : goto "Client" #Server //Server Code Here #Client //Client code here Share this post Link to post Share on other sites
HappyG 0 Posted November 19, 2001 Thank you very much! OK guys here you have it: Put an empty jeep named "server" somewhere on the map, than run those 2 scripts... server-vars.sqs ----------------------- !? (local server) : goto "exit" time = random 12 weather = random 1 fog = random 0.8 publicvariable "time" publicvariable "weather" publicvariable "fog" #exit exit environment.sqs --------------------- ~0.5 skiptime time 0 setovercast weather 0 setfog fog It works perfectly! Have fun, HappyG Share this post Link to post Share on other sites
bn880 5 Posted November 24, 2001 Okay, that sure is a better way of doing it. Thanks, I'll try it. Share this post Link to post Share on other sites
Jason Alaska 0 Posted November 26, 2001 Phuue! Let us know if that works! (Edited by Jason Alaska at 1:30 pm on Nov. 26, 2001) Share this post Link to post Share on other sites
Noodles067 0 Posted August 31, 2002 Hello, i know the answer is right in front of me, but i cant make sense of it. How do i make the server run the two scripts? []exec "server-vars.sqs"; ?? Also are there two scripts, as in two different .sqs files in the mission map or are there two scripts running under the same name? And if i already have a game logic as a server for vehicle repsawn does that mean i cannot have random weather too? Hope You can help me thanks a lot, Noodles Share this post Link to post Share on other sites
bn880 5 Posted August 31, 2002 WOW, aincient thread man... ok, BTW, I was using PublicVariable incorrectly before PublicVariable does not create a network shared variable, it broadcasts the variable over the network only when it is called. (I was thinking (C++ Java variable declaration) Noodles, try this instead: In init.sqs do:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ztime = -1; ?!(local server) : goto "wait" ztime = random 24 weather = random 1 fog = random 0.8 publicvariable "weather" publicvariable "fog" publicvariable "ztime" #wait @(ztime != -1) skiptime ztime 0 setovercast weather 0 setfog fog <span id='postcolor'> This should do it (not tested, but corrected) Share this post Link to post Share on other sites
Noodles067 0 Posted August 31, 2002 ok thx for ur quick reply but it get an error. It says that the !? (local server) : goto "wait" is an invalid number when u get to briefing. and 1 more question if only want the weather to be random and fog level and time set what do i change> Thx a million Share this post Link to post Share on other sites
bn880 5 Posted August 31, 2002 Yea, sorry I cut and pasted the above script and changed it... use this line ?!(local Server): goto "wait" At this point you have to try and understand what's going on there... it's not hard. Anyway, just for a quick answer you can erase some of the bottom 3 lines to your likings. Don't forget the game logic named 'server' Share this post Link to post Share on other sites
Noodles067 0 Posted August 31, 2002 Thanx a lot u made my day Share this post Link to post Share on other sites
Noodles067 0 Posted August 31, 2002 Hey it works...........kinda. Only problem is that when i run mission with ur code in the init.sqs is that the mission wont end. My guess is that it has something to do with the word time that it maybe confuses time (i.e. hour of the day) with time( duration of game). They both have the same name. So plz tell me what i need to change to get that sorted. Apart from that it works. Thx a lot Noodles Share this post Link to post Share on other sites
bn880 5 Posted August 31, 2002 Hmmm, what do you mean the mission won't end? How are you ending it? Share this post Link to post Share on other sites
bn880 5 Posted August 31, 2002 Yes, time is a reserved variable, rename it. This is the last time I trust someone elses code that much... 2 errors like that is ... bad EDIT: will change that post... Share this post Link to post Share on other sites
The_Captain 0 Posted September 1, 2002 Heh, I spent about a month on just this problem, and i still happens on slower machines (desyncing). Took me a hell of a long time to fix. =) Of course, then a thread like this comes along adn solve sit after the fact. =) Share this post Link to post Share on other sites