Gathering variables
#1

Hello,
I want to make a command, but i don't know how to gather information for player

Something like : "/changeplate oldplate newplate"

And i want to be able to define newplate in a temporary var (like : new oldplate[MAX_PLAYERS]; oldplate[playerid] = *from what the user tiped*) and same thing for new plates

Код:
CMD:changeplate(playerid, params[])
{
	
	return 1;
}
Can you help me please?
Once you'll i'll be able to create my own commands from this scheme!
Reply
#2

Are you asking specifically about changing a vehicle plate? Or just accessing player variables in general? You should specify more, and I'll be more than happy to help.
Reply
#3

I'm just asking how to access player variables in general

(with this model i'll be able to reproduce for another case later)

Thanks for your help!!
Reply
#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
#5

I know how to do this stuff, i'm making my server in sql, how to backup is not a problem

I just don't know how to gather the vars from a cmd like that : /cmd var1 var2

I just want to understand how can i get the value of var 1 and var 2 to exploit them later in my system

Thank you for you reply!
Reply
#6

Do you mean like typing a command which shows you the variable that you want?
Reply
#7

Not, just to gather what the player wrote

For example if he wants to change his plate he will wrote "/changeplate OLDPLATE NEWPLATE"

But i have to understand how to gather OLDPLATE to select the right car in my database and to gather NEWPLATE to update the corresponding car plate

Do you understand?
Reply
#8

Oh damn, this is complicated. You would have to use fread and use a loop to read the vehicle database line by line and search for the string you typed in and use a strreplace stock. This is far more complicated than I can explain. I thought I could explain this. Sorry man. Goodluck.
Reply
#9

Noooooooooooooooooooo

I know how to do all the stuff

The only thing that i'm not capable of is GETTING WHAT THE PLAYER TIPPED IN HIS COMMAND

(Used very often : ex in Godfather :/makeleader id numberoffaction

And I just want that the player tipe "/change OLDPLATE NEWPLATE"

Example : /change MYFOLDPLATE FALOR

So with what i tipped just above i just want to exploit "Myfoldplate" and "falor"

To make my system

Just tell me how to do this simple usage (but depends of what the player wrote) :

printf("your oldplate was myfoldplate")
printf("you new plate is falor")

But to print this i have to take data from player command !

You understand?
Reply
#10

You need to use format.

pawn Код:
new PlateString[MAX_PLAYERS][124]; // This is the license plate string.

CMD:setplate(playerid,params[])
{
    new string[124];
    if(isnull(params))
    {
        return SendClientMessage(playerid,-1,"USAGE: /setplate [platetext]");
    }
    else
    {
        new msgstring[124];
        PlateString[playerid] = string; // Sets the players plate string to what was typed.
        format(msgstring,sizeof(msgstring),"You have set your plate to %s",string); // Formats so you could see what was typed
        SendClientMessage(playerid,-1,msgstring); // Sends the formatted message.
        return 1;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)