PDA

View Full Version : Set a player's admin level in game.


Sebz
11/12/2015, 09:34 AM
This is basically how the system is set up, it saves these values to a .ini for each player. Up until now, I have had to manually enter a value into the .ini file to set an admin level. I'd like to be able to do it VIA a cmd in game.

enum PlayerInfo
{
Pass[129], //User's password
Adminlevel, //User's admin level
VIPlevel, //User's vip level
Money, //User's money
Scores, //User's scores
Kills, //User's kills
Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo]; /*This will create a new variable so we can later use it to saving/loading user's info.*/

All I want to know is how to /setlevel a player in game. I use izcmd.

So, for example, if I were to do "/setlevel NAME/ID 3", it would set the player's Adminlevel to 3.

Thanks ahead of time for your assistance!

thefirestate
11/12/2015, 11:25 AM
The most simple way:

CMD:makeadmin(playerid, params[])
{
if(IsPlayerAdmin(playerid) || pInfo[playerid][Adminlevel] == 5) // I am asuming you have 5 different admin levels, not sure how exactly you have.
{
new toid, level;
if(!sscanf(params, "ui", toid, level))
{
pInfo[toid][Adminlevel] = level;
new string[50];
format(string, sizeof(string), "You have been set as level %d administrator.", level);
SendClientMessage(toid, -1, string);
new name[25];
GetPlayerName(toid, name, sizeof(name));
format(string, sizeof(string), "You have set %s's admin level to %d.", name, level);
}
else return SendClientMessage(playerid, -1, "USAGE: /makeadmin [playerid/partofname] [level]");
}
else return SendClientMessage(playerid, -1, "Access denied.");
}

If you have any questions, ask.

Sjn
11/12/2015, 11:44 AM
The most simple way:

CMD:makeadmin(playerid, params[])
{
if(IsPlayerAdmin(playerid) || pInfo[playerid][Adminlevel] == 5) // I am asuming you have 5 different admin levels, not sure how exactly you have.
{
new toid, level;
if(!sscanf(params, "ui", toid, level))
{
pInfo[toid][Adminlevel] = level;
new string[50];
format(string, sizeof(string), "You have been set as level %d administrator.", level);
SendClientMessage(toid, -1, string);
new name[25];
GetPlayerName(toid, name, sizeof(name));
format(string, sizeof(string), "You have set %s's admin level to %d.", name, level);
}
else return SendClientMessage(playerid, -1, "USAGE: /makeadmin [playerid/partofname] [level]");
}
else return SendClientMessage(playerid, -1, "Access denied.");
}

If you have any questions, ask.

Well, you do realize he said he want to save the player's admin level in a file, right? With your code, it only sets player's level temporarily in-game which gets cleared after player disconnects.

OP: Which file reading/writing system are you using?

xTURBOx
11/12/2015, 12:06 PM
i think he is using Y_INI.
If you dont save data onplayerdisconnect, like Sjn said, it will set player's level temporarily in-game which gets cleared after player disconnects.

Sebz
11/12/2015, 12:09 PM
Oh, of course it saves on disconnect.

Question answered, thank you everyone.