IsPlayerConnected Issue -
Tayab - 28.11.2013
Ok, so I made a command /setlevel and it's posted below.
pawn Код:
CMD:setlevel(playerid,params[])
{
new pID,level,rank[128];
if(!IsPlayerAdmin(playerid)) return 0;
if(sscanf(params,"ud",pID,level)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /setlevel [playerid] [level]");
if(!IsPlayerConnected(pID)) return SendClientMessage(playerid,COLOR_GREY,"Player is not connected.");
if(pInfo[pID][AdminLevel] > pInfo[playerid][AdminLevel]) return SendClientMessage(playerid,COLOR_WHITE,"You can't use this command on your colleauge");
if(pInfo[pID][AdminLevel] > level)
{
if(level == 1) return format(rank,sizeof(rank),"{FF8800}Server Moderator {FFFFFF}");
if(level == 2) return format(rank,sizeof(rank),"{0000FF}Global Moderator {FFFFFF}");
if(level == 3) return format(rank,sizeof(rank),"{FF0000}Admin {40FF00}");
if(level == 4) return format(rank,sizeof(rank),"{40FF00}Super Admin {FFFFFF}");
if(level == 5) return format(rank,sizeof(rank),"{40FF00}Head Admin {FFFFFF}");
format(string,sizeof(string),"%s has been demoted to %s by "SERVER_NAME" management.",pID,rank);
SendClientMessageToAll(COLOR_WHITE,string);
pInfo[pID][AdminLevel] = level;
}
else if(pInfo[playerid][AdminLevel] < level)
{
if(level == 1) return format(rank,sizeof(rank),"{FF8800}Server Moderator {FFFFFF}");
if(level == 2) return format(rank,sizeof(rank),"{0000FF}Global Moderator {FFFFFF}");
if(level == 3) return format(rank,sizeof(rank),"{FF0000}Admin {40FF00}");
if(level == 4) return format(rank,sizeof(rank),"{40FF00}Super Admin {FFFFFF}");
if(level == 5) return format(rank,sizeof(rank),"{40FF00}Head Admin {FFFFFF}");
format(string,sizeof(string),"%s has been promoted to %s by "SERVER_NAME" management.",pID,rank);
SendClientMessageToAll(COLOR_WHITE,string);
pInfo[pID][AdminLevel] = level;
}
return 1;
}
Which takes two parameters, playerid and the level.
Whenever I type playerid 0 which is me in the localhost server it always returns "Player is not connected." even thought I am connected. Whenever I try without the IsPlayerConnected check, it returns SERVER: Unknown command. It's so unusual.
Please help me!
Re: IsPlayerConnected Issue -
Lozzy - 28.11.2013
pawn Код:
CMD:setlevel(playerid,params[])
{
new pID,level,rank[128];
if(!IsPlayerAdmin(playerid)) return 0;
if(sscanf(params,"id",pID,level)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /setlevel [playerid] [level]");
if(!IsPlayerConnected(pID)) return SendClientMessage(playerid,COLOR_GREY,"Player is not connected.");
if(pInfo[pID][AdminLevel] > pInfo[playerid][AdminLevel]) return SendClientMessage(playerid,COLOR_WHITE,"You can't use this command on your colleauge");
if(pInfo[pID][AdminLevel] > level)
{
if(level == 1) format(rank,sizeof(rank),"{FF8800}Server Moderator {FFFFFF}");
if(level == 2) format(rank,sizeof(rank),"{0000FF}Global Moderator {FFFFFF}");
if(level == 3) format(rank,sizeof(rank),"{FF0000}Admin {40FF00}");
if(level == 4) format(rank,sizeof(rank),"{40FF00}Super Admin {FFFFFF}");
if(level == 5) format(rank,sizeof(rank),"{40FF00}Head Admin {FFFFFF}");
format(string,sizeof(string),"%s has been demoted to %s by "SERVER_NAME" management.",pID,rank);
SendClientMessageToAll(COLOR_WHITE,string);
pInfo[pID][AdminLevel] = level;
}
else if(pInfo[playerid][AdminLevel] < level)
{
if(level == 1) format(rank,sizeof(rank),"{FF8800}Server Moderator {FFFFFF}");
if(level == 2) format(rank,sizeof(rank),"{0000FF}Global Moderator {FFFFFF}");
if(level == 3) format(rank,sizeof(rank),"{FF0000}Admin {40FF00}");
if(level == 4) format(rank,sizeof(rank),"{40FF00}Super Admin {FFFFFF}");
if(level == 5) format(rank,sizeof(rank),"{40FF00}Head Admin {FFFFFF}");
format(string,sizeof(string),"%s has been promoted to %s by "SERVER_NAME" management.",pID,rank);
SendClientMessageToAll(COLOR_WHITE,string);
pInfo[pID][AdminLevel] = level;
}
return 1;
}
Re: IsPlayerConnected Issue -
Konstantinos - 28.11.2013
Without checking if the player is connected and that id is an invalid player, it's going to show the unknown command message due to the runtime error: Array index out of bounds.
I believe the problem is because of the sscanf. Try updating the plugin and include file to the latest version and re-compile the scripts. Run the server and try again.
PS: Don't use return while checking the level because the rest of the code won't be executed.
pawn Код:
CMD:setlevel(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return 0;
new pID,level,rank[128];
if(sscanf(params,"rd",pID,level)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /setlevel [playerid] [level]");
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_GREY,"Player is not connected.");
if(pInfo[pID][AdminLevel] > pInfo[playerid][AdminLevel]) return SendClientMessage(playerid,COLOR_WHITE,"You can't use this command on your colleauge");
if(pInfo[pID][AdminLevel] > level)
{
if(level == 1) format(rank,sizeof(rank),"{FF8800}Server Moderator {FFFFFF}");
else if(level == 2) format(rank,sizeof(rank),"{0000FF}Global Moderator {FFFFFF}");
else if(level == 3) format(rank,sizeof(rank),"{FF0000}Admin {40FF00}");
else if(level == 4) format(rank,sizeof(rank),"{40FF00}Super Admin {FFFFFF}");
else if(level == 5) format(rank,sizeof(rank),"{40FF00}Head Admin {FFFFFF}");
format(string,sizeof(string),"%s has been demoted to %s by "SERVER_NAME" management.",pID,rank);
}
else if(pInfo[playerid][AdminLevel] < level)
{
if(level == 1) format(rank,sizeof(rank),"{FF8800}Server Moderator {FFFFFF}");
else if(level == 2) format(rank,sizeof(rank),"{0000FF}Global Moderator {FFFFFF}");
else if(level == 3) format(rank,sizeof(rank),"{FF0000}Admin {40FF00}");
else if(level == 4) format(rank,sizeof(rank),"{40FF00}Super Admin {FFFFFF}");
else if(level == 5) format(rank,sizeof(rank),"{40FF00}Head Admin {FFFFFF}");
format(string,sizeof(string),"%s has been promoted to %s by "SERVER_NAME" management.",pID,rank);
}
SendClientMessageToAll(COLOR_WHITE,string);
pInfo[pID][AdminLevel] = level;
return 1;
}
Re: IsPlayerConnected Issue -
Tayab - 28.11.2013
Are you talking about the return in this line?
pawn Код:
if(pInfo[pID][AdminLevel] > pInfo[playerid][AdminLevel]) return SendClientMessage(playerid,COLOR_WHITE,"You can't use this command on your colleauge");
After I run the code, now if I put the right level and the id. It doesn't return anything. It's black. It also doesn't change the level.
Re: IsPlayerConnected Issue -
Jefff - 28.11.2013
pawn Код:
CMD:setlevel(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return 0;
new pID,level;
if(sscanf(params,"dd",pID,level)) SendClientMessage(playerid,COLOR_WHITE,"USAGE: /setlevel [playerid] [level]");
else if(!IsPlayerConnected(pID)) SendClientMessage(playerid,COLOR_GREY,"Player is not connected.");
else if(pInfo[pID][AdminLevel] > pInfo[playerid][AdminLevel]) SendClientMessage(playerid,COLOR_WHITE,"You can't use this command on your colleauge");
else if(!(0 < level < 6)) SendClientMessage(playerid,COLOR_WHITE,"invalid level 1-5");
else{
new rank[35];
switch(level)
{
case 1: rank = "{FF8800}Server Moderator {FFFFFF}";
case 2: rank = "{0000FF}Global Moderator {FFFFFF}";
case 3: rank = "{FF0000}Admin {40FF00}";
case 4: rank = "{40FF00}Super Admin {FFFFFF}";
default: rank = "{40FF00}Head Admin {FFFFFF}";
}
if(pInfo[pID][AdminLevel] > level)
format(string,sizeof(string),"%s has been demoted to %s by "SERVER_NAME" management.",pID,rank);
else
format(string,sizeof(string),"%s has been promoted to %s by "SERVER_NAME" management.",pID,rank);
SendClientMessageToAll(COLOR_WHITE,string);
pInfo[pID][AdminLevel] = level;
}
return 1;
}
you need to get player name in format pID,rank); // GetName(pID)
Re: IsPlayerConnected Issue -
Tayab - 29.11.2013
Thanks buddy! It fixed her.
I must say your code is really well-written!