24.12.2010, 08:49
Before starting
--------------
With this tutorial, you will be able to create an administration filterscript without any includes required!
First, start Pawno>File>New. Delete everything in there. Then add this at the top of your script:
#include <a_samp>
This will include the SA-MP library with the normal natives and callbacks.
[edit]
Defining the Admin functions
In order to make this script, you'll need to define variables to make the script. Add this anywhere at the top, but below the a_samp include (always do so when defining anything):
enum Info
{
AdminLevel,
}
new PlayerInfo[MAX_PLAYERS][Info];
The reason why it's enum is because you will need this when the Login system tutorial is finished. PlayerInfo is the variable you're defining.
[edit]
Making an admin command
Now, I will show you how to make a command that will make you admin. Add the following to the OnPlayerCommandText callback.
new cmd[256], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/makeadmin", true) == 0)
{
new string[128];
new tmp[256];
new player[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME];
new giveplayerid;
if (IsPlayerAdmin(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, ORANGE, "USAGE: /makeadmin [playerid] [level]");
SendClientMessage(playerid, ORANGE, "FUNCTION: Player will be an admin.");
return 1;
}
giveplayerid = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
new level = strval(tmp);
if(giveplayerid != INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, player, sizeof(player));
PlayerInfo[giveplayerid][AdminLevel] = level;
printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
format(string, sizeof(string), "You are now an administrator level %d thanks to %s.", level, player);
SendClientMessage(giveplayerid, 0x00C2ECFF, string);
format(string, sizeof(string), "You have given %s level %d admin.", giveplayer,PlayerInfo[giveplayerid][AdminLevel]);
SendClientMessage(playerid, 0x00C2ECFF, string);
}
else if(giveplayerid == INVALID_PLAYER_ID)
{
format(string, sizeof(string), "%i is not an active player.", giveplayerid);
SendClientMessage(playerid, 0xE60000FF, string);
}
}
else
{
SendClientMessage(playerid, 0xE60000FF, "You are not a lead admin!");
}
return 1;
}
Usage: /makeadmin playerid level This will make the player an admin with the level you entered. NOTE: This requires ReturnUser, strtok and IsNumeric
ON THE LAST LINE YOU CAN SEE "ReturnUser" WHEN I USE THIS SCRIPT IT WAS WRITTEN "Undefined symbol :ReturnUser" HOW TO FIX IT? PLEASE HELP ME
--------------
With this tutorial, you will be able to create an administration filterscript without any includes required!
First, start Pawno>File>New. Delete everything in there. Then add this at the top of your script:
#include <a_samp>
This will include the SA-MP library with the normal natives and callbacks.
[edit]
Defining the Admin functions
In order to make this script, you'll need to define variables to make the script. Add this anywhere at the top, but below the a_samp include (always do so when defining anything):
enum Info
{
AdminLevel,
}
new PlayerInfo[MAX_PLAYERS][Info];
The reason why it's enum is because you will need this when the Login system tutorial is finished. PlayerInfo is the variable you're defining.
[edit]
Making an admin command
Now, I will show you how to make a command that will make you admin. Add the following to the OnPlayerCommandText callback.
new cmd[256], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/makeadmin", true) == 0)
{
new string[128];
new tmp[256];
new player[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME];
new giveplayerid;
if (IsPlayerAdmin(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, ORANGE, "USAGE: /makeadmin [playerid] [level]");
SendClientMessage(playerid, ORANGE, "FUNCTION: Player will be an admin.");
return 1;
}
giveplayerid = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
new level = strval(tmp);
if(giveplayerid != INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, player, sizeof(player));
PlayerInfo[giveplayerid][AdminLevel] = level;
printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
format(string, sizeof(string), "You are now an administrator level %d thanks to %s.", level, player);
SendClientMessage(giveplayerid, 0x00C2ECFF, string);
format(string, sizeof(string), "You have given %s level %d admin.", giveplayer,PlayerInfo[giveplayerid][AdminLevel]);
SendClientMessage(playerid, 0x00C2ECFF, string);
}
else if(giveplayerid == INVALID_PLAYER_ID)
{
format(string, sizeof(string), "%i is not an active player.", giveplayerid);
SendClientMessage(playerid, 0xE60000FF, string);
}
}
else
{
SendClientMessage(playerid, 0xE60000FF, "You are not a lead admin!");
}
return 1;
}
Usage: /makeadmin playerid level This will make the player an admin with the level you entered. NOTE: This requires ReturnUser, strtok and IsNumeric
ON THE LAST LINE YOU CAN SEE "ReturnUser" WHEN I USE THIS SCRIPT IT WAS WRITTEN "Undefined symbol :ReturnUser" HOW TO FIX IT? PLEASE HELP ME