How to set a timer to start 20 seconds after the player spawns?
#1

I am having a problem with a weapon saver,the system saves the weapons and puts them into the players .ini,then when i relog it spawns them back,the problem is when i set a timer (I want to set a timer that will save the weapon's ammo and the guns on you.) sometimes when i log it removes the weapons,i guess it is because the timer starts before the player gets the weapons,then i want the timer to have a little delay.

OnPlayerSpawn()
SetTimer("saveweapon",1000,1);

I don't want to change the SetTimer time,i just want it to have a delay before the player gets the weapons.
Reply
#2

Create another function that sets the that timer (saveweapon). Then OnPlayerSpawn set a timer (new one) for 20 seconds that calls the function (the one you created).
Untested
pawn Код:
// Top of script
forward DelayTimer(/*playerid*/);

public DelayTimer(/*playerid*/)
{
    /*new
        name[20];

    GetPlayerName(playerid, name, 20);
    printf("[Update] Player %s has spawned, and retreived their weapons!", Name);*/

    SetTimer("saveweapon", 1000, true);
    return true;
}

public OnPlayerSpawn(playerid)
{
    SetTimer("DelayTimer(/*playerid*/)", 20000, false); // My bad =P
    return true;
}
Reply
#3

Quote:
Originally Posted by Aber▲
Create another function that sets the that timer (saveweapon). Then OnPlayerSpawn set a timer (new one) for 20 seconds that calls the function (the one you created).
Thanks
I thought about that!
Reply
#4

Quote:
Originally Posted by Uniqueee
Quote:
Originally Posted by Aber▲
Create another function that sets the that timer (saveweapon). Then OnPlayerSpawn set a timer (new one) for 20 seconds that calls the function (the one you created).
Thanks
I thought about that!
Glad you got it, even I got confused in that post.
Reply
#5

Quote:
Originally Posted by Aber▲
Quote:
Originally Posted by Uniqueee
Quote:
Originally Posted by Aber▲
Create another function that sets the that timer (saveweapon). Then OnPlayerSpawn set a timer (new one) for 20 seconds that calls the function (the one you created).
Thanks
I thought about that!
Glad you got it, even I got confused in that post.
Thanks again but it didn't work..the timer starts again when OnPlayerSpawn callback runs.
I did SetClientMessage too and it printed the message,i have added a command /wep and
it shows the new weapons that the player gets when the timer is ON,and
i gave myself a weapon and checked it after 2 secs and it saved it.
I tried your code too,but still the same problem :[

EDIT:
ah lol,you put the DelayTimer in OnPlayerSpawn without any timer ;p
lemme check if your code works now.

EDIT2:
It worked,thanks!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)