SA-MP Forums Archive
Help with /eat - 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: Help with /eat (/showthread.php?tid=427640)



Help with /eat - EiresJason - 02.04.2013

Hi there!

Okay. I have a command (/eat) which allows players to type /eat inside a interior, at the moment, it is the pizza stack in idlewood. A dialog appears and players can scroll between five different 'meals' which costs a different price, and heals a different amount of hp.

Everything works perfectly apart one thing. When a player eats a meal which would increase their HP above 100.
For example; I have 85 HP, and i want to buy a supersize meal which heals 40 health. I would end up with 125 hp.

I have it so if you purchase a meal after you have exceeded 100hp, it will bring it back down to 100 hp.
Example; I have 85 HP, and i have just bought a meal that would heal me for 40 health, i end up with 125 hp and i think to myself, "Il eat another meal, so that way i would have 165 hp". If a player does this, their HP is set to 100.

To sum it up, i need to fix my script so peoples HP do not exceed 100 health.

Any help would be greatly appreciated!

Thanks a lot.

This is my /eat command.
pawn Код:
CMD:eat(playerid, params[])
{   //new hp = GetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
    if(IsPlayerInRangeOfPoint(playerid, 2.0,375.3056,-119.3129,1001.4995)) //idlewood pizza stack
    {
        GetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
        SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
        ShowPlayerDialog(playerid, DIALOG_IDLESTACKEAT, DIALOG_STYLE_LIST, ""COL_WHITE"Please choose a meal!", ""COL_WHITE"Small meal: $5\nMedium meal: $8\nLarge meal: $10\nExtra large meal: $12\nSupersize meal: $15", "Purchase", "Cancel");
        //if(hp >= 100) return SetPlayerHealth(playerid,100);
    }
    return 1;
}
This is my code for when you click on a meal.
pawn Код:
Fixed.
I removed the rest of the other cases to keep the code neater and shorter.

Again, thanks for any help.


Re: Help with /eat - glbracer - 02.04.2013

That's called health stacking, for future reference.
Try putting this under OnPlayerUpdate (it prevents health from going over 100 at any point.)
pawn Код:
new Float:health;
GetPlayerHealth(playerid, health);
if(health > 100) { SetPlayerHealth(playerid, 100); }



Re: Help with /eat - EiresJason - 02.04.2013

Thanks a lot for the reply.

I tried your code but it didn't work .

I tried to update it with the following code but it still doesnt work.

pawn Код:
new Float:health;
    GetPlayerHealth(playerid, health);
    PlayerInfo[playerid][pHealth] = health;
    if(health >= 100)
    {
        SetPlayerHealth(playerid, 100);
        PlayerInfo[playerid][pHealth] = 100;
    }



Re: Help with /eat - glbracer - 02.04.2013

Do you have some sort of command to see your health? Or is there any way to see it in game?


Re: Help with /eat - brawrr - 02.04.2013

try this

PHP код:
case DIALOG_IDLESTACKEAT:
        {
            new 
cash GetPlayerMoney(playerid);
            new 
price;
            if(!
response) return 1;
            if(
response)
            {
                switch(
listitem)
                {
                    case 
0:
                    {
                        new 
Float:health;
                        
GetPlayerHealth(playeridhealth);
                        
price 5;
                        if(
cash price) return SCM(playeridCOLOR_RED"You cannot afford that!");
                        
SCM(playerid,COLOR_LIGHTBLUE"You have purchased a small meal!");
                        
PlayerInfo[playerid][pHealth] = health+15;
                        
SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
                        
GivePlayerMoney(playerid, -price);
                        
                        
// fix
                        
GetPlayerHealth(playeridhealth);
                        if(
health 100)
                        {
                            
PlayerInfo[playerid][pHealth] = 100;
                            
SetPlayerHealth(playeridPlayerInfo[playerid][pHealth] );
                        }
                        
// fix
                    
}
                }
            }
        } 



Re: Help with /eat - EiresJason - 02.04.2013

I tried it Brawl but it didnt work either

I don't have a way to find my HP ingame but i could add it to my /stats command to see it


Re: Help with /eat - brawrr - 02.04.2013

whats not worked? after eat hp > 100? or what?


Re: Help with /eat - EiresJason - 02.04.2013

The same problem what i have been having, if i have 90 hp and buy a meal that heals 15 hp, it still goes to 105 instead of staying at 100


Re: Help with /eat - brawrr - 02.04.2013

hm.......... try this...

PHP код:
case DIALOG_IDLESTACKEAT:
        {
            new 
cash GetPlayerMoney(playerid);
            new 
price;
            if(!
response) return 1;
            if(
response)
            {
                switch(
listitem)
                {
                    case 
0:
                    {
                        new 
Float:health;
                        
GetPlayerHealth(playeridhealth);
                        
price 5;
                        if(
cash price) return SCM(playeridCOLOR_RED"You cannot afford that!");
                        
SCM(playerid,COLOR_LIGHTBLUE"You have purchased a small meal!");
                        
GivePlayerMoney(playerid, -price);
                        
PlayerInfo[playerid][pHealth] = health+15;
                        if(
PlayerInfo[playerid][pHealth] > 100)
                        {
                            
PlayerInfo[playerid][pHealth] = 100;
                            
SetPlayerHealth(playeridPlayerInfo[playerid][pHealth] );
                        }
                        else
                        {
                            
SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
                        }
                    }
                }
            }
        } 



Re: Help with /eat - EiresJason - 02.04.2013

Awesome man thanks, it works

Thanks to anyone who tried to help


Re: Help with /eat - RajatPawar - 02.04.2013

Try checking before buying the meal, the player's health. Then, if the players health is above 60, he obviously will have extra health, so just do
pawn Код:
new Float: health; GetPlayerHealth ( playerid , health ); SetPlayerHealth ( playerid, 100 - health ) ;
and if not, (health < 60), just set it to health + 40.


Re: Help with /eat - EiresJason - 02.04.2013

Thanks Rajat but Brawl got it working perfectly