loop not working properly?
#1

pawn Код:
CMD:npirkti(playerid,params[])
{
    for(new h=0; h < sizeof(HouseInfo); h++)
    {
        printf("h = %d - sizeof = %d", h , sizeof(HouseInfo));
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, sizeof(pName));
        if(strcmp(HouseInfo[h][hOwnerName], pName, false ) == 1)
        {
            if(IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY] , HouseInfo[h][hEnterZ]))
            {
                if(HouseInfo[h][hOwned] == 0)
                {
                    if(GetPlayerMoney(playerid) > HouseInfo[h][hPrice])
                    {
                        strmid(HouseInfo[h][hOwnerName], pName, 0, strlen(pName),MAX_PLAYER_NAME);
                        HouseInfo[h][hOwned] = 1;
                        GivePlayerMoney(playerid,-HouseInfo[h][hPrice]);
                        SendClientMessage(playerid, COL_RED,"Sveikiname, nusipirkote nama! Visas komandas rasite /namai.");
                        HouseInfo[h][hIsRented] = 0;
                        new labelstring[500];
                        DestroyDynamic3DTextLabel(HouseInfo[h][hLabel]);
                        DestroyDynamicMapIcon(HouseInfo[h][hIcon]);
                        DestroyDynamicPickup(HouseInfo[h][hPickup]);

                        format(labelstring, sizeof(labelstring),""TCCYAN"Savininkas: "TCRED"%s\n"TCCYAN"Nuoma: "TCRED"%s\n"TCCYAN"Nuomos kaina: "TCRED"%d\n"TCCYAN"Adresas: "TCRED"%s", HouseInfo[h][hOwnerName],HouseInfo[h][hRenter],HouseInfo[h][hRentPrice],HouseInfo[h][hAddress]);
                        HouseInfo[h][hLabel] = CreateDynamic3DTextLabel(labelstring, COL_GREEN, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ], 20);
                        HouseInfo[h][hPickup] = CreateDynamicPickup(1272, 1, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]);
                        HouseInfo[h][hIcon] = CreateDynamicMapIcon(HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ], 32, 0,0);
                        SaveHouseData(h);
                        return 1;
                    }
                    else { SendClientMessage(playerid, COL_RED, "Jums neuztenka pinigu ipirkti siam namui!"); return 1; }
                }
                else { SendClientMessage(playerid, COL_RED, "Sis namas jau nupirktas!Jei jis nuomuojamas gali ji nuomuoti."); return 1; }
            }
            else { SendClientMessage(playerid, COL_RED, "Jus nesate prie parduodamo namo!"); return 1; }
        }
        else { SendClientMessage(playerid, COL_RED, "Tu jau turi namus!"); return 1; }
    }
    return 1;
}
Why i can only buy house with id 0?

DEBUG:

Код:
[02:04:11] Number of vehicle models: 0
[02:05:52] Incoming connection: 192.168.1.1:50174
[02:05:52] [join] Interneto_Tiekejas has joined the server (0:192.168.1.1)
[02:06:47] h = 0 - sizeof = 100
[02:06:48] h = 0 - sizeof = 100
[02:07:02] Interneto_Tiekejas paliko serveri [Isejo]
[02:07:02] [part] Interneto_Tiekejas has left the server (0:1)
Reply
#2

Quote:

for(new h=0; h < sizeof(HouseInfo); h++)

The HouseInfo is probably the enum.
You need to define the max amount of houses and use that define in replace of the HouseInfo
Reply
#3

Yeajh i tried with MAX_HOUSES , still same...if i change h to 1 or 2 i can buy house with id 1 or 2 , i want to loop for every house...
Reply
#4

Код:
for(new h=1; h < MAX_HOUSES; h++)
Try that?
Reply
#5

Quote:
Originally Posted by Blademaster680
Посмотреть сообщение
Код:
for(new h=1; h < MAX_HOUSES; h++)
Try that?
Now i can only buy house with id 1
Reply
#6

how many houses have you ?
can you post how are your houses loaded
Reply
#7

Код:
for(new h;h < MAX_HOUSES; h++)
Try that?
Reply
#8

My house are loading all good.And currently i have created three houses:

Код:
[02:04:11]  
[02:04:11]  
[02:04:11] House ID 0 EnterX: -2644.247558 EnterY: 708.685363 EnterZ: 27.779293
[02:04:11] House ID 1 EnterX: -2647.647705 EnterY: 705.526855 EnterZ: 27.775972
[02:04:11] House ID 2 EnterX: -2653.083740 EnterY: 706.030761 EnterZ: 27.778476
[02:04:11] \
-----------------------\
[02:04:11] \SFR-RP - Beta!-\
[02:04:11] \-------------------------\

[02:04:11] Number of vehicle models: 0
[02:05:52] Incoming connection: 192.168.1.1:50174
[02:05:52] [join] Interneto_Tiekejas has joined the server (0:192.168.1.1)
[02:06:47] h = 0 - sizeof = 100
[02:06:48] h = 0 - sizeof = 100
[02:07:02] Interneto_Tiekejas paliko serveri [Isejo]
[02:07:02] [part] Interneto_Tiekejas has left the server (0:1)
Reply
#9

Quote:
Originally Posted by Blademaster680
Посмотреть сообщение
Код:
for(new h;h < MAX_HOUSES; h++)
Try that?
Nope
Reply
#10

Omg masters... just remove all return 1; after SendClientMessage and after SaveHouseData because loop is stopping
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)