Jump to content
Sign in to follow this  
rip31st

how can I subract time for a players death?

Recommended Posts

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

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

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

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

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

<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];

smile_o.gif

Share this post


Link to post
Share on other sites

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;

};

banghead.gif

Share this post


Link to post
Share on other sites

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

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

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

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.  banghead.gif

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";

crazy_o.gif

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

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  wink_o.gif

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  

×