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; }
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 ================"); } }
It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://sampforum.blast.hk/showthread.php?tid=602923
It won't show the list because most likely, you are putting a valid player id? |
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 ================"); } }
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; }
Eg.
CMD:makeleader - k<fix>d - para1, level CMD:giveleaderorg - dK<fix>(-1) - family, id Code:
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; } |
new targetid;
if(sscanf(params, "du", family, targetid))
return SendClientMessage(playerid, -1, "USAGE /giveleaderorg [ORG ID] [ID]");
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; }