21.08.2016, 15:31
(
Last edited by NealPeteros; 21/08/2016 at 09:54 PM.
Reason: Buf Fixes Credits: Stinged
)
SETTING A PLAYER'S DATA WITH A COMMAND
INFORMATIONHi, 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
- -/setstat
- -/setlevel
- -/setpoints
- -/setkills
- -/setdeath
- -/setvip
- -And a whole lot more!
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
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
PHP Code:
new PlayerInfo[MAX_PLAYERS][pInfo]; //This will create a PlayerInfo variable
PHP Code:
enum pInfo
{
pLevel
};
new PlayerInfo[MAX_PLAYERS][pInfo];
PHP Code:
CMD:setlevel(playerid, params[]) //This will create the command /setlevel
PHP Code:
{ //Opening tag
PHP Code:
new giveplayerid, amount; //This creates 2 variables namely giveplayerid and amount
PHP Code:
if(sscanf(params, "ud", giveplayerid, amount)) //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(playerid, COLOR_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
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.
PHP Code:
} //Closing tag
PHP Code:
CMD:setlevel(playerid, params[])
{
new giveplayerid, amount;
if(sscanf(params, "ud", giveplayerid, amount))
if (giveplayerid == INVALID_PLAYER_ID) // Checks if the ID entered is offline/invalid
return SendClientMessage(playerid, -1, "Player is not connected.");
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setlevel [playerid] [amount]");
return 1;
}
PlayerInfo[giveplayerid][pLevel] = amount;
return 1;
}