Help with timers (again, sorry)
#1

PHP код:
forward SearchTimer(playerid);
public 
SearchTimer(playerid)
{
    
GameTextForPlayer(playerid"Searching for \nfood..."30001);
    
ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,,0,0,0,0,1);
    return 
1;
}
CMD:foodsearch(playerid,params[])
{
    if(
LastSFood[playerid]>gettime()) return SendClientMessage(playerid, -1"You have recently searched for food. Wait 5 minutes!");
    if(
IsPlayerInRangeOfPoint(playerid50375.962463,-65.816848,1001.507812) || IsPlayerInRangeOfPoint(playerid50369.579528,-4.487294,1001.858886) || IsPlayerInRangeOfPoint(playerid50373.825653,-117.270904,1001.499511))
    {
      if(
Hungry[playerid] > 5)
        {
            
SetTimerEx("SearchTimer",3000,0,"i",playerid);
            new 
rand randomEx(1,3); 
            if(
rand == 1)
            {
                new 
string[128];
                
format(stringsizeof(string), "%s scavenges through the store, searching for food."GetName(playerid));
                
//I want the timer to run here, and wait before sending the text below.. Same with finding no food etc.
                
new string2[128];
                
format(stringsizeof(string), "%s finds some food and eats it."GetName(playerid));
                
ProxDetector(20.0playeridstring,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
ProxDetector(20.0playeridstring2,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessage(playeridCOLOR_WHITE"You are no longer hungry!");
                
ApplyAnimation(playerid,"FOOD","EAT_Burger",4.1,0,1,1,1,1);
                
PlayerPlaySound(playerid10520.00.00.0);
                
Hungry[playerid] = 0;
            }
            else
            {
                
SetTimerEx("SearchTimer",3000,0,"i",playerid);
                new 
string3[128];
                
format(string3sizeof(string3), "%s scavenges through the store, searching for food."GetName(playerid));
                new 
string4[128];
                
format(string4sizeof(string4), "%s reveals a confused expression, whilst shaking his head. (( /foodsearch failed ))"GetName(playerid));
                
ProxDetector(20.0playeridstring3,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
ProxDetector(20.0playeridstring4,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessage(playeridCOLOR_WHITE"You did not find any food inside this store! Try again in 5 minutes!");
                
LastSFood[playerid] = gettime()+60+60+60+60+60;
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_WHITE"You are not hungry. You do not need to eat!");
        }
    }
    else
    {
        
SendClientMessage(playeridCOLOR_WHITE"You can only search for food inside a Clucking Bell, Pizza Stack or Burger Shot!");
    }
    return 
1;

At the moment, the timer waits 3 seconds, and then the animation + game text is applied... The text saying "You did not find any food" or "You found food" etc shows up before the timer (therefore before the animation, gametext).. How can I fix this timer so that after typing the command, the animation and gametext show and when the timer runs out (3 seconds) it will give the player the result "you found food" or "you didnt find food" blah blah... Any help is appreciated. Thanks again!
Reply
#2

Take this as example and give a try

PHP код:
//At top of script
new Timer[MAX_PLAYERS];
new 
FoodTimer[MAX_PLAYERS];
//OnPlayerConnect and Disconnect
FoodTimer[playerid] = 0;
KillTimer(Timer[playerid);
forward SearchTimer(playerid);
public 
SearchTimer(playerid)
{
    
GameTextForPlayer(playerid"Searching for \nfood..."30001);
    
ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,,0,0,0,0,1);
    if(
FoodTimer[playerid] != 0)
    {
        
FoodTimer[playerid]--;
        if(
FoodTimer[playerid] == 0)
        {
            if()
//Found foood
            
{
                
GameTextForPlayer(playerid"Food Founded..."30001);
            }
            else
            {
                
GameTextForPlayer(playerid"Food Not Founded..."30001);
            }
            
KillTimer(Timer[playerid]);
        }
    }
    return 
1;
}
CMD:foodsearch(playerid,params[])
{
    if(
LastSFood[playerid]>gettime()) return SendClientMessage(playerid, -1"You have recently searched for food. Wait 5 minutes!");
    if(
IsPlayerInRangeOfPoint(playerid50375.962463,-65.816848,1001.507812) || IsPlayerInRangeOfPoint(playerid50369.579528,-4.487294,1001.858886) || IsPlayerInRangeOfPoint(playerid50373.825653,-117.270904,1001.499511))
    {
      if(
Hungry[playerid] > 5)
        {
            
Timer[playerid] = SetTimerEx("SearchTimer",1000,1,"i",playerid);
            
FoodTimer[playerid] = 15// You can increase the timer;
            
new rand randomEx(1,3);
            if(
rand == 1)
            {
                new 
string[128];
                
format(stringsizeof(string), "%s scavenges through the store, searching for food."GetName(playerid));
                
//I want the timer to run here, and wait before sending the text below.. Same with finding no food etc.
                
new string2[128];
                
format(stringsizeof(string), "%s finds some food and eats it."GetName(playerid));
                
ProxDetector(20.0playeridstring,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
ProxDetector(20.0playeridstring2,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessage(playeridCOLOR_WHITE"You are no longer hungry!");
                
ApplyAnimation(playerid,"FOOD","EAT_Burger",4.1,0,1,1,1,1);
                
PlayerPlaySound(playerid10520.00.00.0);
                
Hungry[playerid] = 0;
            }
            else
            {
                
SetTimerEx("SearchTimer",3000,0,"i",playerid);
                new 
string3[128];
                
format(string3sizeof(string3), "%s scavenges through the store, searching for food."GetName(playerid));
                new 
string4[128];
                
format(string4sizeof(string4), "%s reveals a confused expression, whilst shaking his head. (( /foodsearch failed ))"GetName(playerid));
                
ProxDetector(20.0playeridstring3,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
ProxDetector(20.0playeridstring4,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessage(playeridCOLOR_WHITE"You did not find any food inside this store! Try again in 5 minutes!");
                
LastSFood[playerid] = gettime()+60+60+60+60+60;
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_WHITE"You are not hungry. You do not need to eat!");
        }
    }
    else
    {
        
SendClientMessage(playeridCOLOR_WHITE"You can only search for food inside a Clucking Bell, Pizza Stack or Burger Shot!");
    }
    return 
1;

Reply
#3

Thanks heaps!!

Ahhh, I'm thinking into it too much and I'm getting a little confused. If someone could edit that code for me a bit for me to paste it in that'd be great. Don't want to sound like a noob, but I've been trying to figure this out for so long haha.

Thanks in advanced!
Reply
#4

Take this code fully corrected and as you said

PHP код:
//At top of script
new Timer[MAX_PLAYERS];
new 
FoodTimer[MAX_PLAYERS];
//OnPlayerConnect and Disconnect
FoodTimer[playerid] = 0;
KillTimer(Timer[playerid);
forward SearchTimer(playerid);
public 
SearchTimer(playerid)
{
    
GameTextForPlayer(playerid"Searching for \nfood..."30001);
    
ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,,0,0,0,0,1);
    if(
FoodTimer[playerid] != 0)
    {
        
FoodTimer[playerid]--;
        if(
FoodTimer[playerid] == 0)
        {
            new 
rand randomEx(1,3);
            
            if(
rand == 1)
            {
                new 
string[128];
                
format(stringsizeof(string), "%s scavenges through the store, searching for food."GetName(playerid));
                
//I want the timer to run here, and wait before sending the text below.. Same with finding no food etc.
                
new string2[128];
                
format(stringsizeof(string), "%s finds some food and eats it."GetName(playerid));
                
ProxDetector(20.0playeridstring,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
ProxDetector(20.0playeridstring2,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessage(playeridCOLOR_WHITE"You are no longer hungry!");
                
ApplyAnimation(playerid,"FOOD","EAT_Burger",4.1,0,1,1,1,1);
                
PlayerPlaySound(playerid10520.00.00.0);
                
Hungry[playerid] = 0;
            }
            else
            {
                new 
string3[128];
                
format(string3sizeof(string3), "%s scavenges through the store, searching for food."GetName(playerid));
                new 
string4[128];
                
format(string4sizeof(string4), "%s reveals a confused expression, whilst shaking his head. (( /foodsearch failed ))"GetName(playerid));
                
ProxDetector(20.0playeridstring3,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
ProxDetector(20.0playeridstring4,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessage(playeridCOLOR_WHITE"You did not find any food inside this store! Try again in 5 minutes!");
                
LastSFood[playerid] = gettime()+60+60+60+60+60;
            }
            
KillTimer(Timer[playerid]);
        }
    }
    return 
1;
}
CMD:foodsearch(playerid,params[])
{
    if(
LastSFood[playerid]>gettime()) return SendClientMessage(playerid, -1"You have recently searched for food. Wait 5 minutes!");
    if(
IsPlayerInRangeOfPoint(playerid50375.962463,-65.816848,1001.507812) || IsPlayerInRangeOfPoint(playerid50369.579528,-4.487294,1001.858886) || IsPlayerInRangeOfPoint(playerid50373.825653,-117.270904,1001.499511))
    {
          if(
Hungry[playerid] > 5)
          {
            
Timer[playerid] = SetTimerEx("SearchTimer",1000,1,"i",playerid);
            
FoodTimer[playerid] = 15// You can increase the timer
            
        
}
        else
        {
            
SendClientMessage(playeridCOLOR_WHITE"You are not hungry. You do not need to eat!");
        }
    }
    else
    {
        
SendClientMessage(playeridCOLOR_WHITE"You can only search for food inside a Clucking Bell, Pizza Stack or Burger Shot!");
    }
    return 
1;

Reply
#5

Thank you so much! Gave you rep man!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)