SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/09/2016, 03:48 PM   #1
Josh_Main
Huge Clucker
 
Josh_Main's Avatar
 
Join Date: Mar 2012
Location: Exclusive Gaming
Posts: 443
Reputation: 12
Default If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Hey,

I'm currently working on my own hunger system..

I've never really used timers before and I'm a little confused at the moment. If someone could help me out, I'd appreciate it alot!

pawn Code:
stock randomEx(min, max)
{
    new rand = random(max-min)+min;
    return rand;
}

CMD:foodsearch(playerid,params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 50, 375.962463,-65.816848,1001.507812) || IsPlayerInRangeOfPoint(playerid, 50, 369.579528,-4.487294,1001.858886) || IsPlayerInRangeOfPoint(playerid, 50, 373.825653,-117.270904,1001.499511))
    {
    if(Hungry[playerid] > 5)
        {
            new rand = randomEx(1,3); //please verify this gives a 50/50 chance :)
            if(rand == 1)
            {
                SendClientMessage(playerid, COLOR_WHITE, "You find some food behind the counter and begin to eat it.");
                SendClientMessage(playerid, COLOR_WHITE, "You are no longer hungry!");
                ApplyAnimation(playerid,"FOOD","EAT_Burger",4.1,0,1,1,1,1);
                PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                Hungry[playerid] = 0;
            }
            else
            {
                SendClientMessage(playerid, COLOR_WHITE, "You did not find any food inside this store! Try again later!");
//I want to set a timer here, so the player won't be able to use /foodsearch again for a certain amount of time...Preferably about 5 minutes
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_WHITE, "You are not hungry. You do not need to eat!");
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, "You can only search for food inside a Clucking Bell, Pizza Stack or Burger Shot!");
    }
    return 1;
}

When a player fails to find food using /foodsearch (also please verify I've made it a 50/50 chance in finding food), i want them to be unable to execute the command again for about 5 minutes.

Any help is greatly appreciated. Thank you!
__________________

104.192.227.106:8630
Hosted by Evolution Servers

Apocalypse Z Roleplay - Half roleplay, half zombie apocalypse roleplay

My work
[Filterscript] Gun Store Dialog

Josh_Main is offline   Reply With Quote
Old 14/09/2016, 03:56 PM   #2
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 974
Reputation: 100
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

PHP Code:
new LastSFood[MAX_PLAYERS];
//OnPlayerConnect set it to 0

CMD:foodsearch(playerid,params[])
{
if(
LastSFood[playerid]>gettime()) return SendClientMessage(playerid, -1"{FF0000}Please wait 5 minute again to use this command");
    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)
        {
            new 
rand randomEx(1,3); //please verify this gives a 50/50 chance :)
            
if(rand == 1)
            {
                
SendClientMessage(playeridCOLOR_WHITE"You find some food behind the counter and begin to eat it.");
                
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
            {
                
SendClientMessage(playeridCOLOR_WHITE"You did not find any food inside this store! Try again later!");
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;

P.S: fix the indentation
Shinja is offline   Reply With Quote
Old 14/09/2016, 03:59 PM   #3
Stuntff
Big Clucker
 
Join Date: Feb 2016
Posts: 83
Reputation: 21
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Code:
CMD:foodsearch(playerid,params[])
{
	if(IsPlayerInRangeOfPoint(playerid, 50, 375.962463,-65.816848,1001.507812) || IsPlayerInRangeOfPoint(playerid, 50, 369.579528,-4.487294,1001.858886) || IsPlayerInRangeOfPoint(playerid, 50, 373.825653,-117.270904,1001.499511))
	{
  	if(Hungry[playerid] > 5)
		{
                      if(GetPVarInt(playerid,"food_timer") > gettime()) retrun SendClientMessage(playerid,-1,"TRY TATER"):
		    new rand = randomEx(1,3); //please verify this gives a 50/50 chance :)
			if(rand == 1)
			{
			    SendClientMessage(playerid, COLOR_WHITE, "You find some food behind the counter and begin to eat it.");
				SendClientMessage(playerid, COLOR_WHITE, "You are no longer hungry!");
		  		ApplyAnimation(playerid,"FOOD","EAT_Burger",4.1,0,1,1,1,1);
	            PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
			    Hungry[playerid] = 0;
                            
			}
			else
			{
			    SendClientMessage(playerid, COLOR_WHITE, "You did not find any food inside this store! Try again later!");
//I want to set a timer here, so the player won't be able to use /foodsearch again for a certain amount of time...Preferably about 5 minutes
			}
                        SetPVarInt(playerid,"food_timer",gettime()+300);
		}
		else
		{
		    SendClientMessage(playerid, COLOR_WHITE, "You are not hungry. You do not need to eat!");
		}
	}
	else
	{
	    SendClientMessage(playerid, COLOR_WHITE, "You can only search for food inside a Clucking Bell, Pizza Stack or Burger Shot!");
	}
	return 1;
}
Stuntff is offline   Reply With Quote
Old 14/09/2016, 04:01 PM   #4
Josh_Main
Huge Clucker
 
Josh_Main's Avatar
 
Join Date: Mar 2012
Location: Exclusive Gaming
Posts: 443
Reputation: 12
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Thanks so much! Really appreciate your help!

Is this correct?

Code:
public OnPlayerConnect(playerid)
{
    new LastSFood = 0;
}
__________________

104.192.227.106:8630
Hosted by Evolution Servers

Apocalypse Z Roleplay - Half roleplay, half zombie apocalypse roleplay

My work
[Filterscript] Gun Store Dialog

Josh_Main is offline   Reply With Quote
Old 14/09/2016, 04:05 PM   #5
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 2,003
Reputation: 473
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Quote:
Originally Posted by Josh_Main View Post
Thanks so much! Really appreciate your help!

Is this correct?

Code:
public OnPlayerConnect(playerid)
{
    new LastSFood = 0;
}
Nope thats a local var and can be only accessed in that call back
SyS is offline   Reply With Quote
Old 14/09/2016, 04:08 PM   #6
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 974
Reputation: 100
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Code:
new LastSFood[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
    LastSFood[playerid] = 0;
}
Shinja is offline   Reply With Quote
Old 14/09/2016, 04:08 PM   #7
Josh_Main
Huge Clucker
 
Josh_Main's Avatar
 
Join Date: Mar 2012
Location: Exclusive Gaming
Posts: 443
Reputation: 12
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Quote:
Originally Posted by Sreyas View Post
Nope thats a local var and can be accessed in that call back
Thanks, but how can I set it to 0 then?

I'm not familiar with that type of scripting, yet.. Trying to understand

Thank you
__________________

104.192.227.106:8630
Hosted by Evolution Servers

Apocalypse Z Roleplay - Half roleplay, half zombie apocalypse roleplay

My work
[Filterscript] Gun Store Dialog

Josh_Main is offline   Reply With Quote
Old 14/09/2016, 04:13 PM   #8
Josh_Main
Huge Clucker
 
Josh_Main's Avatar
 
Join Date: Mar 2012
Location: Exclusive Gaming
Posts: 443
Reputation: 12
Default Re: If /foodsearch doesn't find item, set wait timer (TIMER HELP)

Thank you Shinja! Fixed!
__________________

104.192.227.106:8630
Hosted by Evolution Servers

Apocalypse Z Roleplay - Half roleplay, half zombie apocalypse roleplay

My work
[Filterscript] Gun Store Dialog

Josh_Main is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is better Per Player Timer or Global timer? (issue with timer) Dokins Scripting Help 4 07/06/2016 09:50 AM
[Ajuda] Timer para Dropar Item eNtinityGaming PortuguÍs/Portuguese 1 19/02/2014 12:40 AM
Timer doesn't work Louris Scripting Help 10 04/12/2012 02:35 PM
Timer Doesn't Run! VirSpectorX Help Archive 2 25/12/2010 09:50 AM


All times are GMT. The time now is 09:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.