25.06.2016, 02:57
Код:
CMD:spec(playerid,params[]) { if(pInfo[playerid][Admin]>=2) { new pID,string[128],string3[128],Name[MAX_PLAYER_NAME]; if(sscanf(params,"u",pID))return SendClientMessage(playerid,COLOR_GREEN,"/spec [id]"); if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid,0xFF0000FF,"Please enter a valid player id."); GetPlayerName(pID,Name,sizeof(Name)); format(string,sizeof(string),"You're now spectating %s",Name);//ERROR LINE GetPlayerName(playerid,Name,sizeof(Name)); for(new i=0;i<GetMaxPlayers();i++) { if(IsPlayerConnected(i)) { if(pInfo[i][Admin]>=1) { format(string3,sizeof(string3),"A: %s [LEVEL %i] used the SPEC command.",Name,pInfo[playerid][pAdmin]); SendClientMessage(i,COLOR_ORANGE,string3); } } } SendClientMessage(playerid,COLOR_LIGHTBLUE,string); TogglePlayerSpectating(playerid,1); PlayerSpectatePlayer(playerid,pID,SPECTATE_MODE_NORMAL); } else { SendClientMessage(playerid,0xFF0000FF,"<!>You are not authorized to use this command!"); } return 1; }
String var is a different var it's not a array.
You didn't check if the Target ID is valid or not it would have caused that command to crash.
Added code for that too.
Код:
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid,0xFF0000FF,"Please enter a valid player id.");