[Tutorial] How to make simple buy health and buy armour commands.
#11

Well i spotted a issue with your code, instead of
pawn Код:
CMD:buyhealth(playerid, params[])
{
if(GetPlayerMoney(playerid) > 5500)
{
     GivePlayerMoney(playerid, -5500);
}
        SetPlayerHealth(playerid,100); // we heal him a.k.a give him full health
        SendClientMessage(playerid,-1,"You paid 5500$ to heal your self !");
 } else  SendClientMessage(playerid,-1,"You don't have 5500$ !");
 return 1;
}
it would be better with:
pawn Код:
CMD:buyhealth(playerid, params[])
{
    if(GetPlayerMoney(playerid) <= 5499) return SendClientMessage(playerid, -1, "You don't have enough cash to buy heal."); //This detects if player have enough money or not. If he don't he can't go to the next step.
    else if(GetPlayerMoney(playerid) >= 5500) //Instead of just putting an else statement, I rather prefer to detect if he more than $5500 so it won't be messed up.
    {
        new string[128]; //It's a string, simple as that.
        format(string, sizeof(string), "You have been healed from %f to 100 for $5500!", GetPlayerHealth(playerid)); //We are using the format function, which does formats a string to include variables and other strings inside it.
        SendClientMessage(playerid, -1, string); //We are sending the string out to the specfied playerid about the message above.
        SetPlayerHealth(playerid, 100); //Set's player health, simple as that.
                GivePlayerMoney(playerid, -5500);
    }
    return true;
}
I hope you see the difference with your code and my code. And the detection to check player health, might not be working correctly.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)