Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: Hacktank on March 07, 2009, 05:00:22 pm

Title: OnPlayerDamage loop (events every milisecond)
Post by: Hacktank on March 07, 2009, 05:00:22 pm
I need to be able to preform events every milisecond (or tenth of one or whatever) and i know one of the only ways is an onplayerdamage loop so i made a little test script to see how it would work. It seems to work fine but it only does it 83 times then stops...

Here is the test script:

Code: [Select]
var testing: boolean;
timestested: integer;
testid: byte;

procedure ActivateServer();
begin
testing := false;
timestested := 0;
end;

function OnCommand(ID: Byte; Text: string): boolean;
begin
if getpiece(text,' ',0) = '/test' then begin
if testing = false then begin
testing := true;
testid := ID;
dodamage(1,-111);
exit;
end;
if testing = true then begin
testing := false;
writeconsole(ID,'It tested it ' + inttostr(timestested) + ' times!',$ffffffff);
timestested := 0;
exit;
end;
end;
end;

function OnPlayerDamage(Victim,Shooter: Byte;Damage: Integer) : integer;
begin
result := damage;
if (shooter = victim) AND (damage = -111) AND (testing = true) AND (getplayerstat(shooter,'human') = false) then begin
result := 0;
inc(timestested,1);
writeconsole(testid,'Tested - ' + inttostr(timestested),$ffffffff);
sleep(10);
dodamage(shooter,-111);
end;
end;

No matter how many miliseconds I sleep it only goes up to 83. What am I doing wrong? Also it it true using sleep() will cause my server to crash randomly constantly?

Thank you.
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: danmer on March 07, 2009, 05:15:01 pm
sleep() stops all server actions, so it creates a lag effect and might cause floodkicks. So it's a no-no at any rate, no matter where you stick it <.<
Threading it is an option, but itll break almost any linux server.

I heard some people drop a bullet on a dummy bot, but never tried it myself. Dig some older scripts, you should find an implementation (the portal script might be using it, check it if its available somewhere)
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: iDante on March 07, 2009, 06:21:53 pm
What is it you are trying to do every millisecond?
The simple answer is that it won't happen reliably with threads, so find another way to mimic it. You can try something that danmer suggested, but if that doesn't work then don't expect anything to.
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: Hacktank on March 07, 2009, 06:38:43 pm
I am trying to make things like sentry turrets that fire more than once a second (i know there is one that uses dnmrs suggested method), and various skill effects. But i like to do it myself, and i want to do all things earthly possible to not have a dummy bot. Why does my test script stop at 83? That makes no sense.
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: Gizd on March 08, 2009, 03:13:23 am
OnPlayerDamage loops rest on spawning bullets that hit bot/player constantly. Your loop can look like this:
Code: [Select]
repeat
  sleep(10);
  FastAppOnIdle;
until false;
...and it shouldn't stop at 83. (things you want every centiseconds goes to procedure FastAppOnIdle)
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: tk on March 08, 2009, 04:11:35 am
Use createbullet. Sleep used too many times crashes the server (propably thats why it stops at 83).

There's not better way for fastidle than bot hurted by bullets.
If you dont like this idea, use 1hz AppOnIdle and live with it.
Finally, don't use fast idle more frequent than 5 times per second, especially in such a big script as ZRPG.

Quote
repeat
  sleep(10);
  FastAppOnIdle;
until false;
Forget about it. Something like this threaded will crash your server after 10 seconds. If you put "sentry turrets that fire more than once a second, and various skill effects" inside it will crash after two seconds.
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: Hacktank on March 08, 2009, 05:03:02 am
OK I will just spawn a flame on the player that is casting, the turret and such just wont be able to fire when the player is dead.

EDIT: I tried it with a flame but it only works when the player is standing still even though the flame is clearly hitting them, using a rambo arrow seems to be working well.
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: Dr.Thrax on March 13, 2009, 05:09:33 am
I used a Dummy in a special room that was standing on a hurting polygon and set the damage to 0 for this dummy and i created a procedure FastApponIdle that executed itself 32 times a second and that worked with no lags and problems
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: shantec on March 13, 2009, 05:52:48 pm
I used a Dummy in a special room that was standing on a hurting polygon and set the damage to 0 for this dummy and i created a procedure FastApponIdle that executed itself 32 times a second and that worked with no lags and problems

I tried something like that,  over 100 executes in a second...
Also, nice lagg'n'crash effect :D
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: Gizd on March 14, 2009, 01:34:41 am
Deadly polygons are better, they execute 60 times per sec  :).
Title: Re: OnPlayerDamage loop (events every milisecond)
Post by: Dr.Thrax on March 14, 2009, 04:45:48 am
but i would like to have a faster aponidle without having a bot around... so i guess this is not possible without lags and server crashes  :(