rip31st 98 Posted April 21, 2008 Here's the code I have now for the timer that counts down in secs. I want to be able to subracts 10 seconds for each time any player on the server dies. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _timeRemaining = 3600; //time in seconds while {_timeRemaining != 0} do { hint format ["Time remaining: %1", _timeRemaining]; _timeRemaining = _timeRemaining - 1; sleep 1; }; any ideas? thx Share this post Link to post Share on other sites
dachevs 1 Posted April 21, 2008 maybe something like <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_timeRemaining = 3600; while {alive player} do { hint format["Time Remaining: %1", _timeremaining]; }else{ _timeremaining = _timeremaining - 10; { hint format["Time Remaining: %1, _timeremaining"]; Sleep 1; }; Share this post Link to post Share on other sites
rip31st 98 Posted April 21, 2008 I tried that but nothing tells it to count down besides a player not alive. Share this post Link to post Share on other sites
rip31st 98 Posted April 21, 2008 Well I tried every which way to china to get it to work including adding addeventhandler "killed" to track the dead and just couldnt get it to come up right. Share this post Link to post Share on other sites
dachevs 1 Posted April 21, 2008 what about <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (!alive player) do (... Share this post Link to post Share on other sites
Rommel 2 Posted April 22, 2008 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player addEventHandler ["killed",TIMER = TIMER - 100]; Share this post Link to post Share on other sites
dachevs 1 Posted April 22, 2008 ah ok thats good to know. Share this post Link to post Share on other sites
rip31st 98 Posted April 22, 2008 well I plopped the addeventhandler killed into the script...no errors, just doesnt subract time the way I thought it would. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _timeRemaining = 3600; //time in seconds while {_timeRemaining != 0} do { hint format ["Seconds Left: %1", _timeRemaining]; player addeventhandler ["killed", {_timeRemaining = timeRemaining - 10}]; _timeRemaining = _timeRemaining - 1; sleep 1; }; Share this post Link to post Share on other sites
Rommel 2 Posted April 23, 2008 Its because unfortunately, an Eventhandler needs to have a global variable, and your using both private and global variables there. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> timeRemaining = 3600; //time in seconds player addeventhandler ["killed", {timeRemaining = timeRemaining - 10}]; //eventHandler while {timeRemaining != 0} do { hint format ["Seconds Left: %1", timeRemaining]; timeRemaining = timeRemaining - 1; sleep 1; }; Share this post Link to post Share on other sites
rip31st 98 Posted April 24, 2008 ah thanks...I also found out arma isn't very good at keeping track of time. We had 5 people on the server, each one had a slighty different time displayed. Share this post Link to post Share on other sites
LtCmdrBoon 0 Posted April 27, 2008 that is because the variable is local to each machine. you need to make it public (ie broadcast it across every connected player & server so they remain the same). so in your code, next to where you change its value (ie the player dies) put publicvariable "timeRemaining" also to note, your player dying looses 10 seconds, and you have a != 0 which obviously cud result in 6 seconds left, dying, and jumping to -4 seconds and so forth. Share this post Link to post Share on other sites
rip31st 98 Posted April 30, 2008 Ok I added the public variable...everyone that enters the mission from the beginning gets the same time...HOWEVER...as the mission goes along they lose sync. Â Some players mission ends as much as 18 seconds prior to when other players finish. Â If someone else joins the server after the mission starts, they get full initial amount of time. Â There's got to be some way of updating the clients that join in progress and another way to keep them all synced together. Â Here's my game logic that calls the timer script: Â <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">tmr = [] execVM "scripts\timer.sqf" Here's the timer script itself again: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_timeRemaining = 5400; //time in seconds while {_timeRemaining != 0} do { hint format ["ESTIMATED TIME: %1", _timeRemaining]; _timeRemaining = _timeRemaining - 1; publicvariable " _timeRemaining"; sleep 1; }; hint "MISSION CONTROL: Launch activation sequence detected"; this exec "kaboom.sqs"; Do I need to add anything else to this script that checks with the server and clients to get it to work right? thx for the help! Share this post Link to post Share on other sites
InqWiper 0 Posted April 30, 2008 Because people have different FPS players will loop at different speeds. You subract time from the timeremaining variable based on the amount of loops in the script which is different on every machine. Im quite sure that if you use the "time" command to subtract from the timeremaining variable you will get perfect sync. TimeRemaining = InitTimeRemaining - Time. -edit I suspect the time command to be local so you might have to run another script on the server to get the JIPs in sync. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {true} do { ServerTime = time; publicVariable "ServerTime"; sleep 10; }; and for the clients <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {true} do { TimeDiff = ServerTime - Time; timeRemaining = initTimeRemaining - (time + TimeDiff); hint format ["Time remaining: %1",timeRemaining]; sleep 1; }; Im a little tired but I hope I didnt screw up somewhere  Share this post Link to post Share on other sites