foreach problem or somthing
#1

PHP код:
GangJoinSetup(playeridaction[])
{
    new 
bool:foundstring[256];
    new 
gangid strval(action);
    foreach(new 
Gangs)
    {
        if(
== gangidfound true;
        else 
found false;
    }
    
    if(
found == false) return SendClientMessage(playerid, -1"Gang ID not found !");
    else if(
found == true)
    {
        foreach(
Playeri)
        {
            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 
Gangs)
        {
            
format(stringsizeof string"(ID: %d)  %s - SCORE: %d\n"Gang[i][gID], Gang[i][gName], Gang[i][gScore]);
            
SendClientMessage(playerid, -1string);
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"There is no gang !");
    }
    
cache_delete(result);
    
SendClientMessage(playerid, -1"-----------");
    return 
1;

Reply
#2

Break your loop when you have found what you are looking for:
PHP код:
foreach(new Gangs

    if(
== gangid)
    {
        
found true
        break;
    }

Your function could be rewritten. Plus, don't use foreach(Player,i) but foreach(new i : Player)
Reply
#3

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.
Reply
#4

I have the same issues.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)