Trying to learn how to make an admin script
#1

Hey, I want to create an admin system, but include it with my gamemode, but, I've never made an admin script, what I plan on doing is making a basic admin script with 5 levels, and commands to go with each level. and then the basics (/register, /login, /stats)

Can someone give me a few pointers, ideas, support?

Anything would be appreciated.
Reply
#2

For an accounts system, I suggest you use dini for your scriptfiles.
pawn Код:
#include <dini>
Creating a PlayerInfo array.
pawn Код:
enum pInfo
{
    logged,
    admin
}

new PlayerInfo[MAX_PLAYERS][pInfo];
You should look up about enums if you don't understand.

_________________________________________________

[size=15px]For the regster command:[/size]

pawn Код:
if(strcmp("/register", cmdtext, true, 9) == 0)
    {
        new pname[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(string, sizeof(string), "accounts/%s.acc", pname); //format "string" as where you save the account too
        //this isn't nessessary but it makes life easyer.
Check if they're already logged:
pawn Код:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");
dini_Exists tells you weather or not their account (file with their name) already exists.
pawn Код:
if(dini_Exists(string) == 1) return SendClientMessage(playerid, red, "Your account is registered, please /login"); // account already exists
        if(strlen(cmdtext[10]) == 0) return SendClientMessage(playerid, red, "Usage: /register [password]");
        if(strlen(cmdtext[12]) == 0) return SendClientMessage(playerid, red, "Your password is not long enough"); // their pass must be more then 2 chars
dini_Create creates their account (a file). dini_Set sets a String into their account (file). dini_IntSet sets an Integer into their account (file).
pawn Код:
dini_Create(string); // create their account
        dini_Set(string, "password", cmdtext[10]); // put their pass in it
        dini_IntSet(string, "admin", 0); // create an admin level variable
And finally tell them to login.
pawn Код:
format(string, sizeof(string), "Welcome %s, you may now /login", pname);
        SendClientMessage(playerid, yellow, string);
        return 1;
    }
_________________________________________________

[size=15px]For the login command:[/size]

pawn Код:
if(strcmp("/login", cmdtext, true, 6) == 0)
    {
        new pname[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(string, sizeof(string), "accounts//%s.acc", pname);
Check if they're already logged:
pawn Код:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");
dini_Get gets a string from a file.
pawn Код:
if(dini_Exists(string) == 0) return SendClientMessage(playerid, red, "You do not have an account, please /register"); // their account (file with their name) does not exist
        if(strlen(cmdtext[7]) == 0) return SendClientMessage(playerid, red, "Usage: /login [password]");
        if(strcmp(dini_Get(string, "password"), cmdtext[7], true) != 0) return SendClientMessage(playerid, red, "Passwords did not match"); // pass they entered and pass in the file
Set them to logged:
pawn Код:
PlayerInfo[playerid][logged] = 1;
dini_Int gets an integer from a file. Set their admin level:
pawn Код:
PlayerInfo[playerid][admin] = dini_Int(string, "admin");
And finish the command:
pawn Код:
return 1;
    }
_________________________________________________

[size=15px]Simple /kick command:[/size]

pawn Код:
if(strcmp("/kick", cmdtext, true, 5) == 0)
    {
        new pname[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(string, sizeof(string), "accounts//%s.acc", pname);
Check their level is correct:
pawn Код:
if(dini_Int(string, "admin") != 1) return SendClientMessage(playerid, red, "You are not a level 1 admin!"); // they where not level 1

        // include more checks to see if they're connected and all that

        Kick(strval(cmdtext[5])); // kick them

        //tell everyone they're kicked

        return 1;
    }
_________________________________________________

[size=15px]FYI:[/size]

pawn Код:
strval
Gets the value of a string.

pawn Код:
new string[128];
         0123456789
string =        "hello 11aa".
string[6] (6 = char in which to start) would be "11aa". The value of it would be 11.

Make sure to set their admin level to 0 when they login!
Reply
#3

Thanks! This really helps

Also, I tried looking up enums on wiki, but found nothing. I'll keep looking
Reply
#4

wow you must of sent ages making that post lol as when you go over like a certian ammount of letters in post box it sticks to the top so you cant see what your typing lol
Reply
#5

Quote:
Originally Posted by Shady91
wow you must of sent ages making that post lol as when you go over like a certian ammount of letters in post box it sticks to the top so you cant see what your typing lol
Yes, it was very nice of him to write that for me. Most people would have just told me to look myself, give me stupid answers, etc.

Btw, I cant find anything on enums
Reply
#6

Quote:
Originally Posted by [B
Vortex ]
Btw, I cant find anything on enums
pawn Код:
enum pInfo
{
   AdminLevel,
   Level,
};
new AInfo[MAX_PLAYERS][pInfo];
Reply
#7

Quote:
Originally Posted by JaTochNietDan
Quote:
Originally Posted by [B
Vortex ]
Btw, I cant find anything on enums
pawn Код:
enum pInfo
{
  AdminLevel,
  Level,
};
new AInfo[MAX_PLAYERS][pInfo];


Yes but he told me if I don't understand to look it up.
Reply
#8

With the enum I provided you with, you could do things like

pawn Код:
AInfo[playerid][AdminLevel] = 1;
Do you see now what I mean?
Reply
#9

Quote:
Originally Posted by JaTochNietDan
With the enum I provided you with, you could do things like

pawn Код:
AInfo[playerid][AdminLevel] = 1;
Do you see now what I mean?
Kinda, I'm still pretty new to scripting :P Thanks
Reply
#10

I think this will help you - https://sampwiki.blast.hk/wiki/Creating_...n_FilterScript
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)