SA-MP Forums Archive
[Tutorial] How to make simple buy health and buy armour commands. - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make simple buy health and buy armour commands. (/showthread.php?tid=459449)



How to make simple buy health and buy armour commands. - kjek98 - 22.08.2013

Ok so this is my first tutorial so please tell me if i make any errors because I'm new to scripting.

Ok so the first command what we are going to make is /buyhealth
so what we will need is a zcmd include it can be found here.


we will place this at the top of our script so we get the cmds to work.
Code:
#include <zcmd>
We need to add this to start the cmd
Code:
CMD:buyhealth(playerid, params[])
{
ok so now were going to add this, what it is it takes the money off the player when they use the cmd /buyhealth
Code:
 if(GetPlayerMoney(playerid) > 5500)
{
     GivePlayerMoney(playerid, -5500);
}
now we are going to add the player 100 health.
Code:
        SetPlayerHealth(playerid,100); // this give him full health
now we are going to make a message to the player after he has bought the health
Code:
        SendClientMessage(playerid,-1,"You paid 5500$ to heal your self !"); // changeme : the color you wan't , COLOR_GREEN for example
now we are going to add a message that will send if the player does not have the required money amount.
Code:
 } else  SendClientMessage(playerid,-1,"You don't have 5500$ !");
Ok we are nearly done but we need to add this before we finish the command
Code:
 return 1;
}
and here is how the command should look like
Code:
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;
}
i hope this helped im sorry if i did it wrong as i said its my first tutorial and im new at scripting.



Re: How to make simple buy health and buy armour commands. - NeskWriter - 22.08.2013

Dude, with all due respect, if you are newbie to script, you should learn scripting, and then share your experiense and show skills you got. Nevertheless, I liked it.


Re: How to make simple buy health and buy armour commands. - CrazyChoco - 22.08.2013

You honestly don't explain that much, it's more likely a copy & paste tutorial.

Anyway since it's your first, keep it up!


Re: How to make simple buy health and buy armour commands. - kjek98 - 22.08.2013

thank you


Re: How to make simple buy health and buy armour commands. - sleepysnowflake - 22.08.2013

you should be reading tutorials not making them


Re: How to make simple buy health and buy armour commands. - SuperViper - 22.08.2013

pawn Code:
if(GetPlayerMoney(playerid) > 5500)
No, this won't take the player's money. It will check if they have the money.


Re: How to make simple buy health and buy armour commands. - CrazyChoco - 22.08.2013

Quote:
Originally Posted by SuperViper
View Post
pawn Code:
if(GetPlayerMoney(playerid) > 5500)
No, this won't take the player's money. It will check if they have the money.
Indeed with SuperViper, it shall be like this instead:
pawn Code:
if(GetPlayerMoney(playerid) > 5500)
{
     GivePlayerMoney(playerid, -5500);
}



Re: How to make simple buy health and buy armour commands. - Mckarlis - 22.08.2013

yep it sure should be and yes you should read more tutorials


Re: How to make simple buy health and buy armour commands. - kjek98 - 22.08.2013

thanks for the help i edited the tutorial


Re: How to make simple buy health and buy armour commands. - JaKe Elite - 23.08.2013

I will give respect on your newbie tutorial but shouldn't

Newbie read Tutorials?

not

Newbie teach Newbie.


Re: How to make simple buy health and buy armour commands. - CrazyChoco - 23.08.2013

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.


Re: How to make simple buy health and buy armour commands. - kjek98 - 23.08.2013

thanks for the help