Always creating house 0?
#1

Ok In my createhouse command its always creating house ID of 0 Here's my code. I want it to create house 0 then 1 then 2 etc. And if a house gets deleted for example house 2 and we have 0 1 and 3 it will create house 2 again. At the moment each time I create a house it creates house 0 all the time.

pawn Код:
stock GetHouses()
{
    new file[60];
    for(new i = 0; i < MAX_HOUSES;i++)
    {
        format(file,sizeof(file),"Houses/houseid%i.ini",i);
        if(!DOF2_FileExists(file)) return i;
    }
    return -1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
              switch(dialogid)
    {
        case 28:
        {
            if(!response)
            {
                SendClientMessage(playerid, 0x42F3F198, "Well this lift has its ups and downs.");
                return 1;
            }
            switch(listitem)
            {
                case 0:
                {
                    new housewep[256];
                    new houseid;
                    houseid = GetHouses()+1;
                    format(housewep, sizeof(housewep), "Houses/housewepid%d",GetHouses()+1);
                    new house[256];
                    format(house, sizeof(house), "Houses/houseid%d",houseid);
                    if(!DOF2_FileExists(housewep))
                    {
                        DOF2_CreateFile(housewep);
                        DOF2_SetInt(housewep, "wep1", 0);
                        DOF2_SetInt(housewep, "wep2", 0);
                        DOF2_SetInt(housewep, "wep3", 0);
                        DOF2_SetInt(housewep, "wep4", 0);
                        DOF2_SetInt(housewep, "wep5", 0);
                        DOF2_SetInt(housewep, "wep6", 0);
                        DOF2_SetInt(housewep, "wep7", 0);
                        DOF2_SetInt(housewep, "wep8", 0);
                        DOF2_SetInt(housewep, "wep9", 0);
                        DOF2_SetInt(housewep, "wep10", 0);
                        DOF2_SetInt(housewep, "wep1ammo", 0);
                        DOF2_SetInt(housewep, "wep2ammo", 0);
                        DOF2_SetInt(housewep, "wep3ammo", 0);
                        DOF2_SetInt(housewep, "wep4ammo", 0);
                        DOF2_SetInt(housewep, "wep5ammo", 0);
                        DOF2_SetInt(housewep, "wep6ammo", 0);
                        DOF2_SetInt(housewep, "wep7ammo", 0);
                        DOF2_SetInt(housewep, "wep8ammo", 0);
                        DOF2_SetInt(housewep, "wep9ammo", 0);
                        DOF2_SetInt(housewep, "wep10ammo", 0);
                        DOF2_WriteFile();
                    }
                    if(!DOF2_FileExists(house))
                    {
                        DOF2_CreateFile(house);
                        format(hInfo[houseid][hOwnerName], 24, "For Sale");
                        DOF2_SetString(house, "OwnerName", "For Sale");
                        format(hInfo[houseid][hRenter], 24, "For Rent");
                        DOF2_SetString(house, "RenterName", "For Rent");
                        hInfo[houseid][hOwned] = 0;
                        DOF2_SetInt(housewep, "Owned", 0);
                        hInfo[houseid][hRented] = 0;
                        DOF2_SetInt(housewep, "Rented", 0);
                        hInfo[houseid][hLocked] = 1;
                        DOF2_SetInt(housewep, "Locked", 1);
                        hInfo[houseid][hWeed] = 0;
                        DOF2_SetInt(housewep, "Weed", 0);
                        hInfo[houseid][hCocoaine] = 0;
                        DOF2_SetInt(housewep, "Cocoaine", 0);
                        hInfo[houseid][hCocoaine] = 0;
                        DOF2_SetInt(housewep, "Cocoaine", 0);
                        hInfo[houseid][hInt] = CHInt[playerid];
                        DOF2_SetInt(housewep, "Interior", CHInt[playerid]);
                        hInfo[houseid][hVW] = GetHouses()+1;
                        DOF2_SetInt(housewep, "VirtualWorld", GetHouses()+1);
                        hInfo[houseid][hArmour] = 0;
                        DOF2_SetFloat(housewep, "Armour", 0);
                        hInfo[houseid][hEnterPointX] = CHEntX[playerid];
                        DOF2_SetFloat(housewep, "EnterX", CHEntX[playerid]);
                        hInfo[houseid][hEnterPointY] = CHEntY[playerid];
                        DOF2_SetFloat(housewep, "EnterY", CHEntY[playerid]);
                        hInfo[houseid][hEnterPointZ] = CHEntZ[playerid];
                        DOF2_SetFloat(housewep, "EnterZ", CHEntZ[playerid]);
                        hInfo[houseid][hIntX] = CHIntX[playerid];
                        DOF2_SetFloat(housewep, "IntX", CHIntX[playerid]);
                        hInfo[houseid][hIntY] = CHIntY[playerid];
                        DOF2_SetFloat(housewep, "IntY", CHIntY[playerid]);
                        hInfo[houseid][hIntZ] = CHIntZ[playerid];
                        DOF2_SetFloat(housewep, "IntZ", CHIntZ[playerid]);
                        DOF2_WriteFile();
                    }
                }
                case 1:
                {
                    SendClientMessage(playerid, 0x42F3F198, "/gotolastpos to go back to your last position.");
                    SetPlayerPos(playerid,CHIntX[playerid],CHIntY[playerid],CHIntZ[playerid]);
                    SetPlayerInterior(playerid,CHInt[playerid]);
                }
            }
        }
    }
}
Reply
#2

Why are you checking if the file exists and return the i? shouldn't it be checking if the file does not exists and return the i, so it can locate a new House ID, this should work.

pawn Код:
stock GetHouses()
{
    new file[60];
    for(new i = 0; i < MAX_HOUSES;i++)
    {
        format(file,sizeof(file),"Houses/houseid%i.ini",i);
        if(!DOF2_FileExists(file)) return i;
    }
    return -1;
}
Reply
#3

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Why are you checking if the file exists and return the i? shouldn't it be checking if the file does not exists and return the i, so it can locate a new House ID, this should work.

pawn Код:
stock GetHouses()
{
    new file[60];
    for(new i = 0; i < MAX_HOUSES;i++)
    {
        format(file,sizeof(file),"Houses/houseid%i.ini",i);
        if(!DOF2_FileExists(file)) return i;
    }
    return -1;
}
I already tried that but it still did the creating house 0
Reply
#4

pawn Код:
for(new i = 0;
Of course it's going to start with 0 because that's what you've told it to do!
Reply
#5

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
for(new i = 0;
Of course it's going to start with 0 because that's what you've told it to do!
Its ment to go up through the files and see if the house exists if not create the file.
Reply
#6

Exactly. It's going to start with ID 0. If house ID 0 doesn't exist, then it's going to create it. If you don't want 0 to be a valid house ID, then change "new i = 0" to "new i = 1".
Reply
#7

Ye, It creates house 0 over and over even tho its already made.
Reply
#8

Fixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)