Author Topic: Is there some way to make a delay?  (Read 1417 times)

function b(){for(%b=0; %b<10000; %b++)findclientbyname(jet).player.instantRespawn();}

I dont like spawning 10000 times in one second, it needs to be spread out. I just can't enjoy spawning alot if it is just in one second. :(

.schedule(%a,%b,[%c,...]) is a method that can be called on objects to delay %b method with %c parameters for %a milliseconds. For example, if I wanted to delay kicking a client with the reason "Bye" by 3 seconds, I would use %client.schedule(3000,delete,"Bye");. For non-objects, you use schedule(3000,0,echo,"Bye");. There is an extra argument between the delay and the function (just put 0).

In your case, you would do something like this:
(%b = 0, delay = 0; %b = 1, delay = 1000; etc)

Code: [Select]
function b()
{
echo("Code starting...");

for(%b = 0; %b < 60; %b++)
{
findClientByName("Jet").player.schedule(%b * 1000,instantRespawn);
schedule(%b * 1000,0,echo,"Respawning!");
}

echo("Code stopped.");
}

Echos provided so you see how the delay works - it doesn't pause execution, only delays calls.
« Last Edit: December 06, 2010, 11:56:29 PM by Truce »

I only spawned once on your code, am I supposed to figure out how to use schedule(); and that was just an example?

Shouldn't you be using
findClientByName("Jet").schedule(%b * 1000, spawnPlayer):
?

Because that's going to call instantrespawn on the player once, then the player is gone so the rest of the schedules die.

That did nothing :(

Also I would have to be dead.

I only spawned once on your code, am I supposed to figure out how to use schedule(); and that was just an example?
It only gets added to schedule once afaik. You will need to readd it after

I only spawned once on your code, am I supposed to figure out how to use schedule(); and that was just an example?

The code is making it respawn in 60 minutes. AKA, every hour it respawns. You just haven't waited long enough, I'm sure. Just change the 60 in the code to however many minutes you want it to take between spawns.

Edit: Re-read the code, and now it just confuses me... Truce's code always confuses me, but it should work.

Edit 2: Should do what I said.
« Last Edit: December 07, 2010, 01:52:03 PM by MegaScientifical »

Shouldn't you be using
findClientByName("Jet").schedule(%b * 1000, spawnPlayer):
?

Because that's going to call instantrespawn on the player once, then the player is gone so the rest of the schedules die.

Yeah, probably. I just used the code he was using to do it.
But it otherwise works fine, as the echos show. It's correct.

The code is making it respawn in 60 minutes. AKA, every hour it respawns.

The loop ends after 60 spawns. Each interval is 1 second between spawn. The %b*1000 is 1000 MILISECONDS, and there is 1000 miliseconds in 1 second. c:

But seriously, Truce it didnt work for me :(

The loop ends after 60 spawns. Each interval is 1 second between spawn. The %b*1000 is 1000 MILISECONDS, and there is 1000 miliseconds in 1 second. c:

But seriously, Truce it didnt work for me :(
Because after the first instantrespawn, the player object, which you're calling all those schedules on, doesn't exist anymore.

Read my post please.

I did and I said it didn't do anything. Neither codes worked gentlemen. I guess I could try Chrono's in a second again though, might have put it in wrong.

Ok I executed from a file this time, neither truly work.
Even though the echoes are correct, I see some things wrong with both:
Chrono - I think spawnPlayer is built for if the player is not an object.
Truce - Like Chrono said, the schedule doesnt exist anymore after the first spawn.
Jetpuff - You are bad at scripting.

So here is what I thought of, make another schedule to kill the object then spawn the object. I am too lazy to try right now, but could anyone tell me if they would agree with that? (Also thanks for all the help you guys have put toward this question.)
« Last Edit: December 07, 2010, 10:33:04 PM by Jetpuff »

Spawn player deletes any existing player before doing the rest of the function. I know because I use it in the console all the time when I want people to stop bothering me.

Spawn player deletes any existing player before doing the rest of the function. I know because I use it in the console all the time when I want people to stop bothering me.
hmm, i've been using instantrespawn, spawnplayer works? i thought that i had tried it before

In this case, you would want to repeat finding the player at the time that it is respawned, so the code you want is either a function that schedules itself, or perhaps something like this:

Code: [Select]
for(%i=0; %i<120; %i++)
  schedule(1000 * %i, 0, eval, "findclientbyname(\"jet\").player.instantRespawn();");

But the better way to do it would be

Code: [Select]
function whatever(%i)
{
    if(%i < 1)
      return;
    if([conditions])
      findclientbyname("jet").player.instantRespawn();
    schedule(1000, 0, whatever, %i - 1);
}

because then you can easily add conditions to it, or other fancy things.

Finally, it should be rewritten like this:

Code: [Select]
function whatever(%i)
{
    if(%i < 1)
      return;
    %client = findclientbyname("jet");
    if(isObject(%client) && isObject(%client.player) [&& optional extra conditions])
      %client.player.instantRespawn();
    schedule(1000, 0, whatever, %i - 1);
}

because that way it doesn't give errors if the client or player don't exist.

In that last bit, you only need isObject(%client.player), not isObject(%client)

Because if the client doesn't exist, then .player sure wont.