Gathering variables
#4

Before you start to tackle this I would recommend you educate yourself on file saving systems like y_ini.

You can setup an enum that will hold the players data. Keep in mind this is very basic and not a good RP example.

So here is an enumerator. I don't know how to explain these real well, so I suggest you ****** it if you're confused to this point.
pawn Код:
enum Info
{
    pApples,
    pOranges
}
new PlayerInfo[MAX_PLAYERS][Info];
So since you have an enum let's make a command.

Buy apple command.

pawn Код:
CMD:buyapple(playerid,params[])
{
    if(GetPlayerMoney(playerid) < 20) // Checks if the player has at lease 20 dollars.
    {
        return SendClientMessage(playerid,-1,"You don't have enough money to buy an apple!");
    }
    else // If he does have more than 20 dollars then the next code will run.
    {
        GivePlayerMoney(playerid. -20); // Takes away 20 dollars from the player.
        PlayerInfo[playerid][pApples]++; // Adds 1 to the variable pApples
        SendClientMessage(playerid,-1,"You have bought an apple.");
        return 1;
    }
}
Now that the player has an apple, maybe make a command that makes him eat the apple?
pawn Код:
CMD:eatapple(playerid,params[])
{
    if(PlayerInfo[playerid][pApples] == 0) // Checks if the player has zero apples.
    {
        return SendClientMessage(playerid,-1,"You don't have any apples to eat.");
    }
    else // If the player does have more than 0 apples then this will run.
    {
        new Float:health; // Makes a new float that will store the players health.
        GetPlayerHealth(playerid,health); // Assigns the float to the players health.
        if(GetPlayerHealth(playerid,health) == 100) // If a player's health is full, then they can't eat more apples.
        {
            return SendClientMessage(playerid,-1,"You are full, and can't eat anymore apples.");
        }
        else
        {
            SetPlayerHealth(playerid,health + 10) // Sets the players health to their current health but adds 10.
            PlayerInfo[playerid][pApples]--; // Subtracts one from the player's apple variable.
            return 1;
        }
    }
    return 1;
}
I hope I helped you gain a better understanding.
Reply


Messages In This Thread
Gathering variables - by falor - 01.03.2012, 22:40
Re: Gathering variables - by Walsh - 01.03.2012, 22:55
Re : Gathering variables - by falor - 02.03.2012, 00:27
Re: Gathering variables - by Walsh - 02.03.2012, 00:46
Re : Gathering variables - by falor - 02.03.2012, 00:49
Re: Gathering variables - by Walsh - 02.03.2012, 00:53
Re : Gathering variables - by falor - 02.03.2012, 00:56
Re: Gathering variables - by Walsh - 02.03.2012, 01:01
Re : Gathering variables - by falor - 02.03.2012, 01:08
Re: Gathering variables - by Walsh - 02.03.2012, 01:21

Forum Jump:


Users browsing this thread: 2 Guest(s)