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

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

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

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

Anyway since it's your first, keep it up!
Reply
#4

thank you
Reply
#5

you should be reading tutorials not making them
Reply
#6

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

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

yep it sure should be and yes you should read more tutorials
Reply
#9

thanks for the help i edited the tutorial
Reply
#10

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

Newbie read Tutorials?

not

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

thanks for the help
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)