problem with loop and foreach
#1

well, i made a function that shows a textdraw when you are at the entrance of a house, but it only show the textdraw when you are at the entrance of the last house created, that happens with foreach, when i change it to a loop with for instead of foreach, it doesnt show any textdraw even with the last house created, here is the code:

pawn Код:
funcion Pickups()
{
    new string[130];
    foreach(Player,j)
    {
        if (GetPVarInt(j,"Logueado") && GetPVarInt(j,"JugadorSpawneado"))
        {
            foreach(Casa,c)
            {
                if (EnPos(j,3,InfoCasa[c][caX],InfoCasa[c][caY],InfoCasa[c][caZ]))
                {
                    if (GetPVarInt(j,"TextPropMostrado")) return 1;
                    if(InfoCasa[c][caComprada] == 0)
                    {
                        format(string,sizeof(string),"~n~~n~~y~Costo: ~w~$ %d~n~~n~~y~Nivel: ~w~%d~n~~n~~y~Habitaciones: ~w~%d~n~~n~Usa ~p~/comprarcasa~w~.",InfoCasa[c][caCosto],InfoCasa[c][caNivel],InfoCasa[c][caHab]);
                        TextDrawSetString(InfoProp[j],string);
                        TextDrawShowForPlayer(j,CajaProp[j]);
                        TextDrawShowForPlayer(j,InfoProp[j]);
                        TextDrawShowForPlayer(j,AvisoProp[j]);
                        SetPVarInt(j,"TextPropMostrado",1);
                    }
                    else if(InfoCasa[c][caComprada] == 1)
                    {
                        if (InfoCasa[c][caRenta] == 1)
                        {
                            format(string,sizeof(string),"~n~~n~~y~Propietario: ~w~%s~n~~n~~y~Habitaciones: ~w~%d~n~~n~~y~Renta: ~w~$%d~n~~n~Usa ~p~/rentarcasa~w~.",InfoCasa[c][caProp],InfoCasa[c][caHabRes],InfoCasa[c][caRentaCos]);
                            TextDrawSetString(InfoProp[j],string);
                            TextDrawSetString(AvisoProp[j],"~b~Casa En Renta");
                            TextDrawShowForPlayer(j,CajaProp[j]);
                            TextDrawShowForPlayer(j,InfoProp[j]);
                            TextDrawShowForPlayer(j,AvisoProp[j]);
                            SetPVarInt(j,"TextPropMostrado",1);
                        }
                        else if (InfoCasa[c][caRenta] == 0)
                        {
                            format(string,sizeof(string),"~n~~n~~y~Propietario: ~w~%s~n~~n~~y~Habitaciones: ~w~%d~n~~n~~y~Precio: ~w~$%d~n~~n~No esta en renta.~w~.",InfoCasa[c][caProp],InfoCasa[c][caHab],InfoCasa[c][caCosto]);
                            TextDrawSetString(InfoProp[j],string);
                            TextDrawSetString(AvisoProp[j],"~b~Casa Comprada");
                            TextDrawShowForPlayer(j,CajaProp[j]);
                            TextDrawShowForPlayer(j,InfoProp[j]);
                            TextDrawShowForPlayer(j,AvisoProp[j]);
                            SetPVarInt(j,"TextPropMostrado",1);
                        }
                    }
                }
                else
                {
                    if (GetPVarInt(j,"TextPropMostrado"))
                    {
                        TextDrawHideForPlayer(j,CajaProp[j]);
                        TextDrawHideForPlayer(j,InfoProp[j]);
                        TextDrawHideForPlayer(j,AvisoProp[j]);
                        SetPVarInt(j,"TextPropMostrado",0);
                    }
                }
            }
        }
    }
    return 1;
}
This function is executed with a timer that is played every second, and im adding well the iterators, please help me
Reply


Messages In This Thread
problem with loop and foreach - by Trenico - 28.01.2012, 20:57
Re: problem with loop and foreach - by Trenico - 28.01.2012, 22:46

Forum Jump:


Users browsing this thread: 1 Guest(s)