Issue with IsPlayerConnected and GetPlayerID - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Issue with IsPlayerConnected and GetPlayerID (
/showthread.php?tid=621311)
Issue with IsPlayerConnected and GetPlayerID -
justjamie - 09.11.2016
Hello,
so i want to obtain the name of the player, but ONLY if the player is offline.
This doesn't work, and I have no idea why.
Can someone help me?
ty
PHP код:
/* ============================================================================= */
COMMAND:foff(playerid,params[])
{
if(!Player[playerid][Faction]) return SendClientError(playerid,"You are not in a faction.");
new query[200];
format(query,sizeof(query),"SELECT * FROM accounts WHERE Faction='%i'",Player[playerid][Faction]);
mysql_tquery(connection,query,"foff","d",playerid);
return 1;
}
/* ============================================================================= */
forward foff(playerid);
public foff(playerid)
{
new name[35];
for(new i=0; i<cache_get_row_count(); i++)
{
cache_get_field_content(i,"Username",name);
if(IsPlayerConnected(GetPlayerID(name))) return 1;
SendClientMessage(playerid,-1,sprintf("%i",i));
}
return 1;
}
/* ============================================================================= */
stock GetPlayerID(playername[])
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new playername2[MAX_PLAYER_NAME];
GetPlayerName(i, playername2, sizeof(playername2));
if(strcmp(playername2, playername, true, strlen(playername)) == 0)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
/* ============================================================================= */
So, nothing gets send to the chat (sendclientmessage doesn't work.)
Re: Issue with IsPlayerConnected and GetPlayerID -
Lloyde - 09.11.2016
What command is that to kick that player while the player is offline am i right ? because i did'nt understand what your saying you have bad english
Re: Issue with IsPlayerConnected and GetPlayerID -
Konstantinos - 09.11.2016
In other words you want to show the name of the offline players for that faction and skip the connected?
First of all, returning a value in a loop breaks it completely. Store the rows to a variable instead of keep calling
cache_get_row_count in every iteration.
I don't get why you are trying to send the rowid as a client message and not the name of the player.
Use sscanf to check if a player is connected than
GetPlayerID +
IsPlayerConnected functions, much faster. If you insist on using your way, at least use
GetPlayerPoolSize or even better foreach/y_iterate for the player-loops.
Last, if you want only to retrieve the name then don't select all the data in the query but this certain column:
"SELECT Username FROM ..."