PDA

View Full Version : Problem CMD


KamilPolska
06/04/2019, 03:02 PM
Hello. I have a question.

CMD:giveleaderorg(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return 1;
new id=-1, family;
if( sscanf(params, "dK<fix>(-1)", family, id)) return SendClientMessage(playerid, -1, "USAGE /giveleaderorg [ORG ID] [ID]");
if(family < 0 || family > MAX_ORG-1) return 1;
if(id != -1)
{
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "No such player!");
if(GetPlayerFraction(id) != 0 || GetPlayerOrg(id) != 0) return SendClientMessage(playerid, -1, "This player has factions or family!");
orgInvitePlayer(id, family);
gPlayerOrgLeader[id] = true;
}
new str[128];
if(id != -1)
{
new orgUID = orgID(family);
if(orgUID != 0xFFFF)
{
format(str, sizeof(str), "%s give control over family to %d player %s", GetNick(playerid), family, GetNick(id));
SendClientMessageToAll(-1, str);

PlayerInfo[id][pTeam] = 5;
gTeam[id] = 5;
}
else
{
SendClientMessage(playerid, -1, "ERROR! An error occured.");
}
}
else
{
SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

format(str, 128, "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
mysql_query(g_SQL, str);

new nick[24];
new results = cache_num_rows();

if(results > 0)
{
for(new i = 0; i < results; i++)
{
cache_get_value_name(i, "Nick", nick);

sscanf(str, "p<|>s[24]", nick);

SendClientMessage(playerid, -1, nick);
}
SendClientMessage(playerid, -1, "================ END ================");
}
}
return 1;
}

The command works as an entry /giveleaderorg 45 0
What is this all about? Why he does not work or show me the list.

else
{
SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

format(str, 128, "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
mysql_query(g_SQL, str);

new nick[24];
new results = cache_num_rows();

if(results > 0)
{
for(new i = 0; i < results; i++)
{
cache_get_value_name(i, "Nick", nick);

sscanf(str, "p<|>s[24]", nick);

SendClientMessage(playerid, -1, nick);
}
SendClientMessage(playerid, -1, "================ END ================");
}
}

Private200
06/04/2019, 03:32 PM
It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://forum.sa-mp.com/showthread.php?t=602923

It won't show the list because most likely, you are putting a valid player id?

KamilPolska
06/04/2019, 05:29 PM
It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://forum.sa-mp.com/showthread.php?t=602923

It won't show the list because most likely, you are putting a valid player id?
I think so. The command works nicely and gives me the leader of the organization only I do not know what's going on in this code what I showed. It does not show me messages, for example SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

else
{
SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

format(str, 128, "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
mysql_query(g_SQL, str);

new nick[24];
new results = cache_num_rows();

if(results > 0)
{
for(new i = 0; i < results; i++)
{
cache_get_value_name(i, "Nick", nick);

sscanf(str, "p<|>s[24]", nick);

SendClientMessage(playerid, -1, nick);
}
SendClientMessage(playerid, -1, "================ END ================");
}
}

KamilPolska
06/04/2019, 05:34 PM
What is `k<fix>`?
Eg.
CMD:makeleader - k<fix>d - para1, level
CMD:giveleaderorg - dK<fix>(-1) - family, id

SSCANF:fix(string[])
{
new ret = INVALID_PLAYER_ID;

if(IsNumeric(string))
{
new p = strval(string);
if(IsPlayerConnected(p))
ret = p;
}
else
{
foreach(Player, p)
{
if(strfind(GetNick(p), string, true) != -1)
{
ret = p;
break;
}
}
}

return ret;
}

TheToretto
06/04/2019, 07:07 PM
Eg.
CMD:makeleader - k<fix>d - para1, level
CMD:giveleaderorg - dK<fix>(-1) - family, id

SSCANF:fix(string[])
{
new ret = INVALID_PLAYER_ID;

if(IsNumeric(string))
{
new p = strval(string);
if(IsPlayerConnected(p))
ret = p;
}
else
{
foreach(Player, p)
{
if(strfind(GetNick(p), string, true) != -1)
{
ret = p;
break;
}
}
}

return ret;
}


Have you ever heard of the specifier "u"?

EDIT:

new targetid;
if(sscanf(params, "du", family, targetid))
return SendClientMessage(playerid, -1, "USAGE /giveleaderorg [ORG ID] [ID]");

KamilPolska
07/04/2019, 01:47 AM
Yes, I know rarely use "u". I can not fix the list of leaders. Only one message shows SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");.
And the rest of the message does not show, for example SendClientMessage(playerid, -1, PlayerInfo[id][Nick]); and SendClientMessage(playerid, -1, "================ END ================");

CMD:giveleaderorg(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return 1;
new id = -1, family;
if( sscanf(params, "du", family, id)) return SendClientMessage(playerid, -1, "USAGE /giveleaderorg [ORG ID] [ID]");
if(family < 0 || family > MAX_ORG-1) return 1;
if(id != -1)
{
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "No such player!");
if(GetPlayerFraction(id) != 0 || GetPlayerOrg(id) != 0) return SendClientMessage(playerid, -1, "This player has factions or family!");
orgInvitePlayer(id, family);
gPlayerOrgLeader[id] = true;
}
new str[128];
if(id == 9)
{
new orgUID = orgID(family);
if(orgUID != 0xFFFF)
{
format(str, sizeof(str), "%s give control over family to %d player %s", GetNick(playerid), family, GetNick(id));
SendClientMessageToAll(-1, str);

PlayerInfo[id][pTeam] = 5;
gTeam[id] = 5;
}
else
{
SendClientMessage(playerid, -1, "ERROR! An error occured.");
}
}
else
{
new query[500];
//new nick[24];
//new results = cache_num_rows();

mysql_format(g_SQL, query, sizeof(query), "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
mysql_query(g_SQL, query);

new rows;
cache_get_row_count(rows);

GetPlayerName(id, PlayerInfo[id][Nick], MAX_PLAYER_NAME);

SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

if(rows)
{
new loaded;
while(loaded < rows)
{
cache_get_value_name(loaded, "Nick", PlayerInfo[id][Nick], 24);

sscanf(str, "p<|>s[24]", PlayerInfo[id][Nick]);

SendClientMessage(playerid, -1, PlayerInfo[id][Nick]);
loaded++;
}
SendClientMessage(playerid, -1, "================ END ================");
}

/*
GetPlayerName(id, PlayerInfo[id][Nick], MAX_PLAYER_NAME);

mysql_format(g_SQL, query, sizeof(query), "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
mysql_query(g_SQL, query);

SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

if(results > 0)
{
for(new i = 0; i < results; i++)
{
cache_get_value_name(i, "Nick", PlayerInfo[id][Nick], 24);

sscanf(str, "p<|>s[24]", PlayerInfo[id][Nick]);

SendClientMessage(playerid, -1, PlayerInfo[id][Nick]);
}
SendClientMessage(playerid, -1, "================ END ================");
}
*/
}
return 1;
}