Official Soldat Forums
Server Talk => Scripting Discussions and Help => Topic started 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:
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.
-
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)
-
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.
-
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.
-
OnPlayerDamage loops rest on spawning bullets that hit bot/player constantly. Your loop can look like this:
repeat
sleep(10);
FastAppOnIdle;
until false;
...and it shouldn't stop at 83. (things you want every centiseconds goes to procedure FastAppOnIdle)
-
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.
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.
-
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.
-
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 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
-
Deadly polygons are better, they execute 60 times per sec :).
-
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 :(