Help with /eat
#1

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.
Reply
#2

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); }
Reply
#3

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;
    }
Reply
#4

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

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
                    
}
                }
            }
        } 
Reply
#6

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
Reply
#7

whats not worked? after eat hp > 100? or what?
Reply
#8

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
Reply
#9

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]);
                        }
                    }
                }
            }
        } 
Reply
#10

Awesome man thanks, it works

Thanks to anyone who tried to help
Reply
#11

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.
Reply
#12

Thanks Rajat but Brawl got it working perfectly
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)