26.01.2016, 20:59
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.
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.000003, 1.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(string, sizeof(string), "* %s has fed his cow and it got bigger by 50 lbs", RPN(playerid));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_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;
}