Problem with (IsPlayerConnected)
#1

PHP код:
CMD:stats(playerid, params[])
{
    new 
id;
    if(
connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
    if(!
IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) The player is not connected!");
    if(
sscanf(params, "u", id)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /stats [id]");
    {
    new 
string[900], stats[900],str[129], iString[150];
    
format (iString, sizeof(iString), "{CECEF6}* You are viewing /stats of %s", PlayerName[playerid]);
    
SendClientMessage(playerid, -1, iString);
    
format(str, sizeof(str), "{FFFFFF}%s {4286f4}database id {FFFFFF}%i\n\n", PlayerName[id], pInfo[id][ID]);
    
strcat(stats, str);
    
format(string, sizeof(string), "{4286f4}Admin Level: ( {FFFFFF}%i {4286f4})\n", pInfo[id][Admin]);
    
strcat(stats, string);
    
format(string, sizeof(string), "{4286f4}Score: ( {FFFFFF}%i {4286f4})\n", pInfo[id][Score]);
    
strcat(stats, string);
    
format(string, sizeof(string), "{4286f4}Points: ( {FFFFFF}%i {4286f4})\n", pInfo[id][Points]);
    
strcat(stats, string);
    
format(string, sizeof(string), "{4286f4}Respect: ( {FFFFFF}%i {4286f4})\n", pInfo[id][Respect]);
    
strcat(stats, string);
    
format(string, sizeof(string), "{4286f4}Kills: ( {FFFFFF}%i {4286f4})\n", pInfo[id][Kills]);
    
strcat(stats, string);
    
format(string, sizeof(string), "{4286f4}Deaths: ( {FFFFFF}%i {4286f4})\n", pInfo[id][Deaths]);
    
strcat(stats, string);
    
format(string, sizeof(string), "{4286f4}Ratio K/D: ( {FFFFFF}%.2f {4286f4})\n", floatdiv(pInfo[id][Kills], pInfo[id][Deaths]));
    
strcat(stats, string);
    
ShowPlayerDialog(playerid, 55, DIALOG_STYLE_MSGBOX, "Player statistics", stats, "Ok", "");
    }
      return 
1;
} 
So all works, except the one last thing, if i do /Stats 3 (id 3= not connected) , it just keep showing id 0 and then unknown command under.
Look's like the code is done correctly, do you guys got any ideas :&
Reply
#2

Because you don't retrieve player id from params. You should use sscanf to done the job.
Reply
#3

You need to check if is null return 0; or SCM
Edit: wops read that wrong, maybe check if is player connected? AFTER sscanf
Reply
#4

just add this.
PHP код:
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) Player not found!"); 
Reply
#5

Quote:
Originally Posted by Mugala
Посмотреть сообщение
just add this.
PHP код:
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) Player not found!"); 
Reply


Forum Jump:


Users browsing this thread: