foreach problem or somthing - 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: foreach problem or somthing (
/showthread.php?tid=655051)
foreach problem or somthing -
LevelT - 12.06.2018
PHP код:
GangJoinSetup(playerid, action[])
{
new bool:found, string[256];
new gangid = strval(action);
foreach(new i : Gangs)
{
if(i == gangid) found = true;
else found = false;
}
if(found == false) return SendClientMessage(playerid, -1, "Gang ID not found !");
else if(found == true)
{
foreach(Player, i)
{
if(pInfo[i][pGangID] == gangid)
{
if(pInfo[i][pGangRank] >= 3)
{
SendClientMessage(playerid, -1, "Request sent.");
gJoinRequest[playerid] = gangid;
}
}
}
return 1;
}
i don't know why its show me Gang ID not found and everything loaded succesfully and its working when i do ganglist
exemple when i do /gjoin id its show GANG ID not Found and when i do /glist it show me all gang in it
CODE of GANG LIST:
PHP код:
GangListSetup(playerid)
{
new string[256];
new Cache:result = mysql_query(g_SQL, "SELECT * FROM `gangs`");
new rows = cache_num_rows();
SendClientMessage(playerid, -1, "GANG LIST");
if(rows != 0)
{
foreach(new i : Gangs)
{
format(string, sizeof string, "(ID: %d) %s - SCORE: %d\n", Gang[i][gID], Gang[i][gName], Gang[i][gScore]);
SendClientMessage(playerid, -1, string);
}
}
else
{
SendClientMessage(playerid, -1, "There is no gang !");
}
cache_delete(result);
SendClientMessage(playerid, -1, "-----------");
return 1;
}
Re: foreach problem or somthing -
Dayrion - 12.06.2018
Break your loop when you have found what you are looking for:
PHP код:
foreach(new i : Gangs)
{
if(i == gangid)
{
found = true;
break;
}
}
Your function could be rewritten. Plus, don't use
foreach(Player,i) but
foreach(new i : Player)
Re: foreach problem or somthing -
Calisthenics - 12.06.2018
According to GangListSetup function, "Gangs" iterator contains used slots of array but Gang[i][gID] is different.
In GangJoinSetup function, you will need to send a query to check if gang ID is found in database and if it does, then your loop searches which slot of "Gangs" iterator is equal to gangid player input.
Re: foreach problem or somthing - poppingrose - 12.06.2018
I have the same issues.