PDA

View Full Version : Problem with setting cmd's for admin


niere
02/03/2012, 09:53 AM
After i do this on my player it don't set me as Level 1 admin ,could anyone help me?

CMD:setlevel(playerid, params[])
{
if(PlayerInfo[playerid][Adminlevel] == 1 || IsPlayerAdmin(playerid))
{
new id, lvl;
if(sscanf(params, "ui", id, lvl)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"/setlevel / "#COL_SGREY#"[PlayerID/PartOfName] [Level]");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "Invalid ID");
else if(lvl > 1) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_ORANGE#"[ADMIN]"#COL_LRED#" Administrator level cannot be higher then 1!");
else
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][Adminlevel]);
INI_Close(File);
PlayerInfo[id][Adminlevel] = lvl;
}
}
return 1;
}

milanosie
02/03/2012, 09:59 AM
kind of obvious:


CMD:setlevel(playerid, params[])
{
if(PlayerInfo[playerid][Adminlevel] == 1 || IsPlayerAdmin(playerid))
{
new id, lvl;
if(sscanf(params, "ui", id, lvl)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"/setlevel / "#COL_SGREY#"[PlayerID/PartOfName] [Level]");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "Invalid ID");
else if(lvl > 1) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_ORANGE#"[ADMIN]"#COL_LRED#" Administrator level cannot be higher then 1!");
else
{
new INI:File = INI_Open(UserPath(playerid));
PlayerInfo[id][Adminlevel] = lvl;
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][Adminlevel]);
INI_Close(File);
}
}
return 1;
}

niere
02/03/2012, 10:05 AM
Now i made all as you stated and ingame im setting it for me ,and when i try use

CMD:freeze(playerid, params[])
{

new targetid, string[128];
if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"Only "#COL_SGREY#"Administrators can use this command");
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"/freeze"#COL_SGREY#"[PlayerID/PartOfName]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_ORANGE#"[ERROR]"#COL_LRED#" Player not connected!");
new pTargetName[24], pName[24];
GetPlayerName(playerid,pName,24);
GetPlayerName(targetid,pTargetName,24);
format(string, sizeof(string), ""#COL_ORANGE#"[SERVER]"#COL_LRED#" %s has been frozen by Administrator %s.",pTargetName, pName);
SendClientMessageToAll(COLOR_RED,string);
TogglePlayerControllable(targetid, 0);

return 1;
}

It shows me: Only Administrators can use this command

milanosie
02/03/2012, 10:08 AM
my mistake:


CMD:setlevel(playerid, params[])
{
if(PlayerInfo[playerid][Adminlevel] == 1 || IsPlayerAdmin(playerid))
{
new id, lvl;
if(sscanf(params, "ui", id, lvl)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"/setlevel / "#COL_SGREY#"[PlayerID/PartOfName] [Level]");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "Invalid ID");
else if(lvl > 1) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_ORANGE#"[ADMIN]"#COL_LRED#" Administrator level cannot be higher then 1!");
else
{
new INI:File = INI_Open(UserPath(id));
PlayerInfo[id][Adminlevel] = lvl;
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(id));
INI_WriteInt(File,"Kills",PlayerInfo[id][Kills]);
INI_WriteInt(File,"Deaths",PlayerInfo[id][Deaths]);
INI_WriteInt(File,"Adminlevel",PlayerInfo[id][Adminlevel]);
INI_Close(File);
}
}
return 1;
}


u used playerid instead of id

niere
02/03/2012, 10:14 AM
At that you have right ,got another prob with saving it on concrete player id in scriptfiles


[data]
Cash = 0
Kills = 0
Deaths = 0
Adminlevel = 1

It saved it as New account not on my player's nickname:

[data]
Password = 143983218
Cash = 100000
Kills = 2340
Deaths = 0
Adminlevel = 0

milanosie
02/03/2012, 10:17 AM
Uhm for that I am not the best with Y_ini, Never used it actually.
So Sorry but I can't help you with that:(

niere
02/03/2012, 10:20 AM
Uhm for that I am not the best with Y_ini, Never used it actually.
So Sorry but I can't help you with that:(
Okay thanks for helping me anyway ;) I just will wait for other opinions in this case
Rep+

FuTuяe
02/03/2012, 11:21 AM
CMD:setlevel(playerid, params[])
{
if(PlayerInfo[playerid][Adminlevel] == 1 || IsPlayerAdmin(playerid))
{
new id, lvl;
if(sscanf(params, "ui", id, lvl)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"/setlevel / "#COL_SGREY#"[PlayerID/PartOfName] [Level]");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "Invalid ID");
else if(lvl > 1) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_ORANGE#"[ADMIN]"#COL_LRED#" Administrator level cannot be higher then 1!");
else
{
new INI:File = INI_Open(UserPath(id));
PlayerInfo[id][Adminlevel] = lvl;
INI_WriteInt(File,"Adminlevel",PlayerInfo[id][Adminlevel]);
INI_Close(File);
}
}
return 1;
}

When you're updating the admin level you're also updating other stats like money which is useless.

niere
02/03/2012, 11:35 AM
CMD:setlevel(playerid, params[])
{
if(PlayerInfo[playerid][Adminlevel] == 1 || IsPlayerAdmin(playerid))
{
new id, lvl;
if(sscanf(params, "ui", id, lvl)) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_DGREY#"/setlevel / "#COL_SGREY#"[PlayerID/PartOfName] [Level]");
else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "Invalid ID");
else if(lvl > 1) return SendClientMessage(playerid, COLOR_WHITE, ""#COL_ORANGE#"[ADMIN]"#COL_LRED#" Administrator level cannot be higher then 1!");
else
{
new INI:File = INI_Open(UserPath(id));
PlayerInfo[id][Adminlevel] = lvl;
INI_WriteInt(File,"Adminlevel",PlayerInfo[id][Adminlevel]);
INI_Close(File);
}
}
return 1;
}

When you're updating the admin level you're also updating other stats like money which is useless.

Every time when i use the command it's not creating it for player but only as new .txt document :/

Gamer_Z
02/03/2012, 11:45 AM
Every time when i use the command it's not creating it for player but only as new .txt document :/

Well don't expect people to help if you don't show proper code!


INI_Open(UserPath(id));


there's your problem, you didn't post UserPath function here,
don't just copy paste code from anywhere, try to understand it first, probably will help ya in fixing the problem on your own.

niere
02/03/2012, 11:52 AM
Well don't expect people to help if you don't show proper code!


INI_Open(UserPath(id));


there's your problem, you didn't post UserPath function here,
don't just copy paste code from anywhere, try to understand it first, probably will help ya in fixing the problem on your own.

Actually i tried to fix it for long time posted it here because i knew people can help me to understand it ,thanks for reply anyway ,ill try

Gamer_Z
02/03/2012, 12:15 PM
Actually i tried to fix it for long time posted it here because i knew people can help me to understand it ,thanks for reply anyway ,ill try

if the UserPath function still fails after your 'repair' attempts, you are always welcome to post :P