Hunger Problem -
nLs - 06.12.2012
Okay, for some reason when I go in-game and type /eat (even at the position) it says i'm not at the restaurant. Can somebody help me?
Код:
#include <a_samp>
#include <zcmd>
#define FILTERSCRIPT
//--------------------------[Configuration]------------------------------------|
#undef MAX_PLAYERS // |
#define MAX_PLAYERS 40 //Change this to your player slot amount |
#define N2E_TIME 10000 //Edit this value to change the timer, now = 10 mins |
#define LOOSING_HP 5 //The HP the player will lose |
//-----------------------------------------------------------------------------|
#define COLOR_RED 0xFF6347AA
//Forwards
forward NeedToEat(playerid);
//Arrays
new FirstSpawn[MAX_PLAYERS];
new Float:CurHealth[MAX_PLAYERS];
public OnFilterScriptInit()
{
}
public OnFilterScriptExit()
{
}
public OnPlayerSpawn(playerid)
{
FirstSpawn[playerid] += 1;
new Float:health;
GetPlayerHealth(playerid, health);
CurHealth[playerid] = health;
if(FirstSpawn[playerid] == 1)
SetTimerEx("NeedToEat",N2E_TIME,1,"i",playerid);
return 1;
}
public NeedToEat(playerid)
{
new Float:health;
GetPlayerHealth(playerid, health);
if(CurHealth[playerid] >= health)
{
SendClientMessage(playerid,COLOR_RED,"-| Your stomach starts to feel hungry, go eat something! |-");
SetPlayerHealth(playerid,health-LOOSING_HP);
CurHealth[playerid] = health;
}
else
{
CurHealth[playerid] = health;
}
}
CMD:eat(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, 376.4745,-67.4357,1001.5078,358.0285))
{
SendClientMessage(playerid, COLOR_RED, "Thanks for visiting! Enjoy!");
GivePlayerMoney(playerid, -10);
SetTimerEx("NeedToEat",N2E_TIME,1,"i",playerid);
SetPlayerHealth(playerid, 100);
}
else
{
SendClientMessage(playerid, COLOR_RED, "You're not at a restaurant!");
}
return 1;
}
Re: Hunger Problem -
Threshold - 06.12.2012
Try this,
Код:
CMD:eat(playerid, params[])
{
if(!IsPlayerInRangeOfPoint(playerid, 10, 376.4745,-67.4357,1001.5078)) return SendClientMessage(playerid, COLOR_RED, "You're not at a restaurant!");
SendClientMessage(playerid, COLOR_RED, "Thanks for visiting! Enjoy!");
GivePlayerMoney(playerid, -10);
SetTimerEx("NeedToEat",N2E_TIME,1,"i",playerid);
SetPlayerHealth(playerid, 100);
return 1;
}
Re: Hunger Problem -
nLs - 06.12.2012
Thank you so much!
One problem though, The timer doesn't restart and therefore it keeps going. So if I eat, ten seconds later i'm hungry again.
Re: Hunger Problem -
PlayLSX_Founder - 06.12.2012
Shouldn't you be killing timers here?
Re: Hunger Problem -
nLs - 06.12.2012
Yeah, that's what I meant.
Re: Hunger Problem -
DaRk_RaiN - 06.12.2012
if you wanna kill he timer you need this:
Use this
PHP код:
new HungerTimer;
HungerTimer = SetTimerEx("NeedToEat",N2E_TIME,1,"i",playerid);
//when you wanna kill it use
KillTimer(HungerTimer);
Re: Hunger Problem -
nLs - 08.12.2012
Uhhh, how would I go about to get the timer restarted AFTER they type /eat and the timer is killed all in the same command? If that is possible, of course.
Re: Hunger Problem -
DaRk_RaiN - 08.12.2012
Didn't understand what you mean,so you want the timers to only work once?then change this
pawn Код:
SetTimerEx("NeedToEat",N2E_TIME,1,"i",playerid);
to this
pawn Код:
SetTimerEx("NeedToEat",N2E_TIME,0,"i",playerid);
Re: Hunger Problem -
nLs - 08.12.2012
No, I want it so when you type /eat the timer restarts.
Re: Hunger Problem -
nLs - 09.12.2012
BUMP (Very sorry, but I REALLY want this done)
Can anybody help me with my situation?