[Tutorial] Creating the basic of an admin-script
#1

Hello guys! this is tutorial how to make admin script!

First go to Pawno>File>New and Delete everything in there!
then add this code at top of the script:

Код:
#include <a_samp>
after define the Admin function:

Код:
enum Info
{
   AdminLevel,
}
new PlayerInfo[MAX_PLAYERS][Info];
after make the admin command. 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;
}
NOTE: This requires ReturnUser, strtok and IsNumeric!

And final Touch: we need to make sure that when a player connects, he doesn't get any admin level!
code here:

Код:
OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][AdminLevel] = 0;
    return 1;
}
Works? "Rep+" please!


-----------------------------------------

Strtok Code Here:

Код:
strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}
 
	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
"Rep+" Please!
Reply
#2

Edit name :P, "Creating the basic of an admin-script"

Nice job, it helped me. But "OnplayerConnect" has a weird function. So if an admin connects He also gets rank 0?...
Reply
#3

Quote:
Originally Posted by [WA]iRonan
Посмотреть сообщение
Nice job, it helped me. But "OnplayerConnect" has a weird function. So if an admin connects He also gets rank 0?...
yes because this need registration / login script for save this!
Reply
#4

If this is a tutorial.. Then I don't want to live on this planet anymore.... Just madness man.. The script will not work perfectily.. + you didn't explain anything!
Reply
#5

Nice, it helped me a lot as a new scripter
Reply
#6

n o he stolen from me and got banned original post --->https://sampforum.blast.hk/showthread.php?tid=526750
Reply
#7

Quote:
Originally Posted by GrandTheftAut0
Посмотреть сообщение
n o he stolen from me and got banned original post --->https://sampforum.blast.hk/showthread.php?tid=526750
Tell me this then. How the fuck is that possible when his was posted before yours?
Reply
#8

You can't tell that this is a tutorial ... it's almost nothing, not event a topic for Script Help ...
Reply
#9

May I suggest using zcmd, Its lot easy for making the simplest of commands for beginners
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)