SA-MP Forums Archive
loop help ~ selects first on on the list - 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: loop help ~ selects first on on the list (/showthread.php?tid=526325)



loop help ~ selects first on on the list - jeffery30162 - 16.07.2014

I have a list of saved houses and I want it to when a player logs in it checks the list of houses to see if he owns one. But when I run the code I have it only checks the first house on the list when there is more to be checked. Please help me.

Here is what I have: (there are no spaces in the actual coding)
Код:
   			for(new idxx=1; idxx<MAX_HOUSE; idxx++)
			{
			    new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
				GetPlayerName(playerid, name, sizeof(name));
				if(strcmp(HouseInfo[idxx][hOwner],name,true)!=0) //does not own
				{
				    SendClientMessage(playerid, COLOR_ORANGE, "YOUR HOUSE HAS BEEN SOLD DUE TO INACTIVITY");
				    PlayerInfo[playerid][Houses] = 0;
				    return 1;
				}
				else
				{
				    SendClientMessage(playerid, COLOR_ORANGE, "YOUR HOUSE AUTO-SELL TIME HAS BEEN SET TO 14 DAYS FROM NOW");
                                    ///code will soon be placed here
				    return 1;
				}

    		}
please help me


Re: loop help ~ selects first on on the list - Hanger - 16.07.2014

arrays start with a zero!

HouseInfo[0][Owner] = FirstHouse

In your loop it starts to count from 1

Код:
for(new idxx=0; idxx<MAX_HOUSE; idxx++)



Re: loop help ~ selects first on on the list - jeffery30162 - 16.07.2014

it does start at one, this is not the problem


Re: loop help ~ selects first on on the list - Vince - 16.07.2014

Do not return inside a loop. How do you know a player doesn't own a house, before having gone through the entire list? You don't. That's why that part is supposed to be placed after and outside the loop.


Re: loop help ~ selects first on on the list - jeffery30162 - 16.07.2014

yes, but when I do that it displays the messages for each house on the list.
I need it to go down the list, when it finds a name match it does something. If it gets to the end of the list and it doesnt find a match. it also does something


Re: loop help ~ selects first on on the list - R0 - 16.07.2014

try this:
pawn Код:
for(new idxx=1; idxx<MAX_HOUSE; idxx++)
            {
                new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
                GetPlayerName(playerid, name, sizeof(name));
                if(PlayerInfo[playerid][Houses] > 0)
                {
                    if(strcmp(HouseInfo[idxx][hOwner],name,true)!=0) //does not own
                    {
                        SendClientMessage(playerid, COLOR_ORANGE, "YOUR HOUSE HAS BEEN SOLD DUE TO INACTIVITY");
                        PlayerInfo[playerid][Houses] = 0;
                        return 1;
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_ORANGE, "YOUR HOUSE AUTO-SELL TIME HAS BEEN SET TO 14 DAYS FROM NOW");
                                        ///code will soon be placed here
                        return 1;
                    }
                }

            }



Re: loop help ~ selects first on on the list - Hanger - 16.07.2014

Or just dont loop then
Код:
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
                GetPlayerName(playerid, name, sizeof(name));
                if(PlayerInfo[playerid][Houses] > 0)
                {
                    if(strcmp(HouseInfo[PlayerInfo[playerid][Houses]][hOwner],name,true)!=0) //does not own
                    {
                        SendClientMessage(playerid, COLOR_ORANGE, "YOUR HOUSE HAS BEEN SOLD DUE TO INACTIVITY");
                        PlayerInfo[playerid][Houses] = 0;
                        return 1;
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_ORANGE, "YOUR HOUSE AUTO-SELL TIME HAS BEEN SET TO 14 DAYS FROM NOW");
                                        ///code will soon be placed here
                        return 1;
                    }
                }