[Tutorial] Making a simple command to set a player's data
#1

SETTING A PLAYER'S DATA WITH A COMMAND
INFORMATION
Hi, guys! I'm actually so bored right now, and I'm home alone. So, I decided to create my ever first tutorial here on SAMP Forums. As this will be my first tutorial, I'd like to apologize to all who are offended especially to advanced C Language scripters, who take this tutorial for newbies. Yes, I can accept those kinds of replies, since I'm only a 13 year-old beginner-medium scripter. This tutorial is for beginners who are confused on how to make commands like these.

Learning Objectives
In this tutorial, we are able to learn how to create a simple command to set a player's data. In this example, we'll choose
pawn Code:
/setlevel
as our example, but actually, there are alot of commands that can be used. Here's some:
  • -/setstat
  • -/setlevel
  • -/setpoints
  • -/setkills
  • -/setdeath
  • -/setvip
  • -And a whole lot more!
So, what are we waiting for? Let's go straight to the tutorial!


In the beginning, we'll create a #define to define the max players. Put this in below include <a_samp> and ontop of the next includes
Sample
PHP Code:
#include <a_samp> 
#undef MAX_PLAYERS 
#define MAX_PLAYERS 100 
#include <sscanf2> 
// #include ... 
PHP Code:
#undef MAX_PLAYERS 
#define MAX_PLAYERS 100 
Then, we will create an enumerator to store player's data.
PHP Code:
enum pInfo //This will create an enumerator named pInfo to store data about your player. 
PHP Code:
//Opening tag 
PHP Code:
    pLevel//You can add more here like pKill pDeath, etc. 
PHP Code:
}; // Closing tag 
Here, we'll create a variable named PlayerInfo
PHP Code:
new PlayerInfo[MAX_PLAYERS][pInfo]; //This will create a PlayerInfo variable 
So, in the end, our enumerator with the variable will look like this
PHP Code:
enum pInfo
{
    
pLevel
};
new 
PlayerInfo[MAX_PLAYERS][pInfo]; 
Once we have that, we can now create the command. I will be using ZCMD as my command processor.
PHP Code:
CMD:setlevel(playeridparams[]) //This will create the command /setlevel 
PHP Code:
//Opening tag 
PHP Code:
    new giveplayeridamount//This creates 2 variables namely giveplayerid and amount 
PHP Code:
    if(sscanf(params"ud"giveplayeridamount)) //If the player doesn't enter any other word after the command /setlevel 
PHP Code:
       if (giveplayerid == INVALID_PLAYER_ID// Checks if the ID entered is offline/invalid
       
return SendClientMessage(playerid, -1"Player is not connected."); 
PHP Code:
    //Then, 
PHP Code:
        SendClientMessage(playeridCOLOR_WHITE"USAGE: /setlevel [playerid] [amount]"); //It will send the player a message to show him/her how to use the command 
PHP Code:
        return 1//Stops a function and goes back to the point in code which called the function in the first place 
PHP Code:
    //Closing tag 
If the player added the correct use,
PHP Code:
    PlayerInfo[giveplayerid][pLevel] = amount//This will set the player's level to the amount given. You can add messages here to notify the player that his level was set to the amount 
PHP Code:
    return 1//Stops the command, and continues processing. 
And last, but not the least, our closing tag.
PHP Code:
//Closing tag 
In the end, our command will look like this
PHP Code:
CMD:setlevel(playeridparams[])
{
    new 
giveplayeridamount;
    if(
sscanf(params"ud"giveplayeridamount))
       if (
giveplayerid == INVALID_PLAYER_ID// Checks if the ID entered is offline/invalid 
       
return SendClientMessage(playerid, -1"Player is not connected.");  
    {
        
SendClientMessage(playeridCOLOR_WHITE"USAGE: /setlevel [playerid] [amount]");
        return 
1;
    }
    
PlayerInfo[giveplayerid][pLevel] = amount;
    return 
1;

So, this is my first tutorial in SAMP. Thanks for reading, and enjoy!
Reply


Messages In This Thread
Making a simple command to set a player's data - by NealPeteros - 21.08.2016, 15:31
Re: Making a simple command to set a player's data - by Stinged - 21.08.2016, 15:56
Re: Making a simple command to set a player's data - by NealPeteros - 21.08.2016, 16:03
Re: Making a simple command to set a player's data - by Logic_ - 22.08.2016, 12:06
Re: Making a simple command to set a player's data - by NealPeteros - 22.08.2016, 14:17
Re: Making a simple command to set a player's data - by Cerax101 - 29.08.2016, 04:47

Forum Jump:


Users browsing this thread: 1 Guest(s)