Problem with a timer :|
#1

Hay, i have doing this script for a weed system but i have a problem with a timer and don't know the solution:

pawn Код:
CMD:plantseed(playerid,params[])
{
    if(pinfo[playerid][seeds] < 5) return SendClientMessage(playerid,-1,"[SERVER] You haven't enought seeds");
    if(IsPlayerInVehicle(playerid,GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,-1,"[SERVER] You can't do it in a vehicle");
    if(limite == MAX_WEED_PER_PLAYER) return SendClientMessage(playerid,-1,"[SERVER] You can't plant more of 3 seeds");
    new id = plantcount;
    GetPlayerPos(playerid,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz]);
    mariaobject[id] = CreateDynamicObject(3409,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz]-1,0.0,0.0,0.0,-1,-1,-1,100.0,0.0);
    ApplyAnimation(playerid,LIBRARY,ANIMATION,4.1,false,false,false,false,3000,false);
    winfo[id][labelweed] = CreateDynamic3DTextLabel("On Harvest",0xFF0000FF,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz],100.0);
    pinfo[playerid][seeds] = pinfo[playerid][seeds] - 5;
    plantcount++;
    limit++;
    SetTimer("harvesttimer",30000,false);
    return 1;

}
this is a timer function:

pawn Код:
forward harvesttimer();
public harvesttimer()
{
    for(new i = 0; i < MAX_WEED; i++)
    {
        winfo[i][finita] = 1;
        UpdateDynamic3DTextLabelText(winfo[i][labelweed],0xFF0000FF,"Harvest");
    }
    return 1;

}
The problem occurred when i send a command /plantseed... for each command the timer have to restart, but it applies to only once, so when i send the command and when i resend the command after 10 seconds, when the first timer finish the second finish together with the first. what i wrong ??
Reply
#2

Because the timer is of 30 seconds (30000ms). So, after 10 seconds, this still will be processing.

If you want to continue as that, I recommend to retype the command just after 30 seconds.

Otherwise, if many people will use the command on your server, I'd suggest you to use this function:

https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

Quote:
Originally Posted by Fel486
Посмотреть сообщение
Because the timer is of 30 seconds (30000ms). So, after 10 seconds, this still will be processing.

If you want to continue as that, I recommend to retype the command just after 30 seconds.

Otherwise, if many people will use the command on your server, I'd suggest you to use this function:

https://sampwiki.blast.hk/wiki/SetTimerEx
Ok but there isn't a method for to do that when the command has been send one more time the timer of the second command start from 0. So if a one plant has been harvest the second plant have to wait the difference of the seconds that missing for harvest?
Reply
#4

I think yes, you have to wait, since it's the same callback you're requesting.

If you want to call multiple times, you should create other callbacks.

For multiple players, use SetTimerEx.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)