PDA

View Full Version : Server/Client Timers


SoSilencer
9th Oct 2001, 07:33 PM
I know what I need to do, but I'm not quite sure how to do it. I'll try to explain as best I can.

.5 second timer
{
do code only on server/host of game
replicate/update variables to clients
}

.1 second timer
{
do this code on all machines, using variables from server
}

That is it really. It's for my rockets. Every half second the server calculates the changes and tells the clients "fly here". Every .1 seconds the rockets figure out by themselves how to fly there (which should be the same on all clients since they are all using the same variables in the same calculations). I can't quite figure out how to tell the code that "this should be done every half second and only on the server" and "this should be done every tenth of a second on all machines". Anyone know how to do that?

Bytekeeper
9th Oct 2001, 08:18 PM
make something like:

int count;

simulated event beginplay()
{
settimer( 0.1, true );
}

simulated event Timer()
{
count= ( count + 1 ) % 5;
if ( !count && role == role_authority )
{
// Called on server only
}
// Code which every machine should do
}

SoSilencer
9th Oct 2001, 11:33 PM
That's kinda what I'm doing now but it's not working right. It is all in a "function Timer()", does it need to be "simulated event Timer()" instead? What is the difference between those two?

I think one of my problems is that the rockets change physics mode. They start in PHYS_Falling when the rockets are ejected from the gun. About a half second later the rockets ignite and switch to PHYS_Projectile, only to run out of gas about 7 seconds later and switch back to PHYS_Faling. I can't seem to get the physics to replicate (or anything else for that matter) so the rockets just fall forward out of the gun and that's it.

Bytekeeper
10th Oct 2001, 06:25 AM
Simulated means, that the function can be called on the client. For events etc. to be called clientside your actor has to be role_simulatedproxy, so check if it is too.
If you call a nonsimulated function clientside it will not be processed, so remember, every actor < ROLE_AutonomousProxy needs a simulated before the function call if you want it to be called clientside.
Hmm, the physics are only replicated once to the client, and that's when you spawn a new rocket.

You could set bSimFall= true, that would replicate Velocity, Accelerarion, bBounce and Physics to the client.
Or you let the client decide on it's own when to set the physics by replicating gas etc.

ca
11th Oct 2001, 03:12 PM
If you want a timer called client-side just make sure you call SetTimer from a simulated function, otherwise it won't work. :)

Bytekeeper
11th Oct 2001, 06:07 PM
And the Timer() function must be simulated for sure as well for this to work.