SA-MP Forums Archive
Timer problem ( simple ) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Timer problem ( simple ) (/showthread.php?tid=599506)



Timer problem ( simple ) - Mikeydoo - 26.01.2016

Ok so i've been working with timers for a day and still don't know all the pawno syntax and all.

What I wanna do is, when timer reach 0 seconds : it destroy the dynamic object CowFence. It creates it when the timer starts and when its going down. But it doesnt destroy it at 0 but it do kill the timer.

Any help is highly apreciated

PHP код:
forward CowTimeCooldown(playerid);
public 
CowTimeCooldown(playerid)
{
    if(
CowTime[playerid] > 0)
    {
        
CowTime[playerid] --;
    }
    else if(
CowTime[playerid] == 0)
    {
        new 
string[128], cow;
        
CowFence CreateDynamicObject(19833, -380.1285,-1472.2924,25.7266, -0.0000031.099999, -68.199905,0);
        
PlayerInfo[playerid][pCow][cow] = PlayerInfo[playerid][pCow][cow] += 50;
        
format(stringsizeof(string), "* %s has fed his cow and it got bigger by 50 lbs"RPN(playerid));
        
SendNearbyMessage(playerid15stringCOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLE);
        
DestroyDynamicObject(CowFence);
        
KillTimer(CowCooldown[playerid]);
       }
    return 
1;




Re: Timer problem ( simple ) - itsCody - 26.01.2016

Why are you recreating the cow fence again when the timer hits 0?


Re: Timer problem ( simple ) - Mikeydoo - 26.01.2016

PHP код:
forward CowTimeCooldown(playerid);
public 
CowTimeCooldown(playerid)
{
    if(
CowTime[playerid] > 0)
    {
           
CowFence CreateDynamicObject(19833, -380.1285,-1472.2924,25.7266, -0.0000031.099999, -68.199905,0);
        
CowTime[playerid] --;
    }
    else if(
CowTime[playerid] == 0)
    {
           new 
string[128], cow;
        
PlayerInfo[playerid][pCow][cow] = PlayerInfo[playerid][pCow][cow] += 50;
        
format(stringsizeof(string), "* %s has fed his cow and it got bigger by 50 lbs"RPN(playerid));
        
SendNearbyMessage(playerid15stringCOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLE);
        
DestroyDynamicObject(CowFence);
        
KillTimer(CowCooldown[playerid]);
       }
    return 
1;

Sorry this is how it really is. Still doesnt work


Re: Timer problem ( simple ) - Mikeydoo - 26.01.2016

Anyone ?


Re: Timer problem ( simple ) - AmigaBlizzard - 26.01.2016

Now you're re-creating the fence everytime the counter is counting down.
Create it once (usually where/when the timer is started) and don't create any additional ones.

Or if you really insist on having the creation of the fence inside the timer, check if the variable has been set to 0 before creating the fence.
PHP код:
forward CowTimeCooldown(playerid);
public 
CowTimeCooldown(playerid)
{
    if(
CowTime[playerid] > 0)
    {
        if (
CowFence == 0// If the fence object is already created, the value stored inside CowFence won't be 0, this will keep the timer from creating extra ones each iteration of the timer
        
{
            
CowFence CreateDynamicObject(19833, -380.1285,-1472.2924,25.7266, -0.0000031.099999, -68.199905,0);
        }
        
CowTime[playerid] --;
    }
    else 
// Cowtime isn't higher than 0 anymore, so we can assume it's at 0 now (no need for extra if-statements)
    
{
        new 
string[128], cow;
        
PlayerInfo[playerid][pCow][cow] = PlayerInfo[playerid][pCow][cow] += 50;
        
format(stringsizeof(string), "* %s has fed his cow and it got bigger by 50 lbs"RPN(playerid));
        
SendNearbyMessage(playerid15stringCOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLE);
        
DestroyDynamicObject(CowFence);
        
KillTimer(CowCooldown[playerid]);
        
CowFence 0// Reset the variable so the timer can re-create the fence object by itself once when started again
    
}
    return 
1;




Re: Timer problem ( simple ) - Mikeydoo - 26.01.2016

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Now you're re-creating the fence everytime the counter is counting down.
Create it once (usually where/when the timer is started) and don't create any additional ones.
Ok let me try


Re: Timer problem ( simple ) - Mikeydoo - 26.01.2016

No I don't care about where it is. But still I take notes on what you've shown me.

Anyway, it worked, stupid mistake I made I dont know why I didn't realized it.