PDA

View Full Version : Trying to learn how to make an admin script


_Vortex
05/09/2009, 12:07 AM
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.

Zezombia
05/09/2009, 12:44 AM
For an accounts system, I suggest you use dini for your scriptfiles.
#include <dini>

Creating a PlayerInfo array.
enum pInfo
{
logged,
admin
}

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

_________________________________________________

For the regster command:

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:
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.
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).
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.
format(string, sizeof(string), "Welcome %s, you may now /login", pname);
SendClientMessage(playerid, yellow, string);
return 1;
}

_________________________________________________

For the login command:

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:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");

dini_Get gets a string from a file.
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:
PlayerInfo[playerid][logged] = 1;

dini_Int gets an integer from a file. Set their admin level:
PlayerInfo[playerid][admin] = dini_Int(string, "admin");

And finish the command:
return 1;
}

_________________________________________________

Simple /kick command:

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:
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;
}

_________________________________________________

FYI:

strval
Gets the value of a string.

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!

_Vortex
05/09/2009, 01:04 AM
Thanks! This really helps :D

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

shady91
05/09/2009, 01:05 AM
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 :D

_Vortex
05/09/2009, 01:17 AM
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 :D


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 :?:

JaTochNietDan
05/09/2009, 01:24 AM
Vortex ]
Btw, I cant find anything on enums :?:


enum pInfo
{
AdminLevel,
Level,
};
new AInfo[MAX_PLAYERS][pInfo];

:)

_Vortex
05/09/2009, 02:05 AM
Vortex ]
Btw, I cant find anything on enums :?:


enum pInfo
{
AdminLevel,
Level,
};
new AInfo[MAX_PLAYERS][pInfo];

:)

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

JaTochNietDan
05/09/2009, 02:10 AM
With the enum I provided you with, you could do things like

AInfo[playerid][AdminLevel] = 1;

Do you see now what I mean? :)

_Vortex
05/09/2009, 02:13 AM
With the enum I provided you with, you could do things like

AInfo[playerid][AdminLevel] = 1;

Do you see now what I mean? :)


Kinda, I'm still pretty new to scripting :P Thanks

Zeex
05/09/2009, 02:21 AM
I think this will help you - http://wiki.sa-mp.com/wiki/Creating_A_Simple_Administration_FilterScript

Zezombia
05/09/2009, 04:36 AM
Enums are simple, its just:

enum test
{
var1,
var2
}

So now you have an enum (that is holding 2 factors) called test. What to do with it?

new Variable[test];

So now you have Variable, which can be used as seprate variables: Variable[var1], and Variable[var2]. Which is your case is PlayerInfo[playerid][logged] and PlayerInfo[playerid][admin].
You can also add like deaths, kills, stuff like that.


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 :D


That's probably an IE glitch or something. I use firefox and it dosn't do that.

_Vortex
05/09/2009, 03:56 PM
Wow thanks for all your help :D

mickos
06/05/2012, 09:15 PM
it help me to thanks