House Save/Load System
#1

I have a problem with my House System.

First of all here is my SAVE HOUSE CODE

pawn Код:
forward SaveHouses();
public SaveHouses()
{
    new string3[128];
    for(new idx; idx < sizeof(HouseInfo); idx++)
    {
        format(string3, sizeof(string3), "South-WestRP/Houses/%s.ini", idx);
        new File: hFile = fopen(string3, io_write);
        if (hFile)
        {
            new var[32];
            format(var, 32, "hName=%s\n", HouseInfo[idx][hName]);fwrite(hFile, var);
            format(var, 32, "hOwner=%s\n", HouseInfo[idx][hOwner]);fwrite(hFile, var);
            format(var, 32, "hEnterX=%s\n", HouseInfo[idx][hEnterX]);fwrite(hFile, var);
            format(var, 32, "hEnterY=%s\n", HouseInfo[idx][hEnterY]);fwrite(hFile, var);
            format(var, 32, "hEnterZ=%s\n", HouseInfo[idx][hEnterZ]);fwrite(hFile, var);
            format(var, 32, "hExitX=%s\n", HouseInfo[idx][hExitX]);fwrite(hFile, var);
            format(var, 32, "hExitY=%s\n", HouseInfo[idx][hExitY]);fwrite(hFile, var);
            format(var, 32, "hExitZ=%s\n", HouseInfo[idx][hExitZ]);fwrite(hFile, var);
            format(var, 32, "EnterInterior=%s\n", HouseInfo[idx][EnterInterior]);fwrite(hFile, var);
            format(var, 32, "EnterWorld=%s\n", HouseInfo[idx][EnterWorld]);fwrite(hFile, var);
            format(var, 32, "hPrice=%s\n", HouseInfo[idx][hPrice]);fwrite(hFile, var);
            format(var, 32, "hLocked=%s\n", HouseInfo[idx][hLocked]);fwrite(hFile, var);
            format(var, 32, "hProducts=%s\n", HouseInfo[idx][hProducts]);fwrite(hFile, var);
            format(var, 32, "hNumber=%s\n", HouseInfo[idx][hNumber]);fwrite(hFile, var);
            format(var, 32, "hType=%s\n", HouseInfo[idx][hType]);fwrite(hFile, var);
            format(var, 32, "hOwned=%s\n", HouseInfo[idx][hOwned]);fwrite(hFile, var);
            fclose(hFile);
        }
    }
    return 1;
}
LOAD HOUSE CODE

pawn Код:
forward LoadHouses();
public LoadHouses()
{
    new string2[128];
    for(new idx; idx < sizeof(HouseInfo); idx++)
    {
        format(string2, sizeof(string2), "South-WestRP/Houses/%s.ini", idx);
        new File:example = fopen(string2, io_read);
        if(example)
        {
            new key[ 256 ] , val[ 256 ];
            new Data[ 256 ];
            while ( fread( example , Data , sizeof( Data ) ) )
            {
                key = ini_GetKey( Data );
                if( strcmp( key , "hName" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hName] = strval( val ); }
                if( strcmp( key , "hOwner" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hOwner] = strval( val ); }
                if( strcmp( key , "hEnterX" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hEnterX] = strval( val ); }
                if( strcmp( key , "hEnterY" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hEnterY] = strval( val ); }
                if( strcmp( key , "hEnterZ" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hEnterZ] = strval( val ); }
                if( strcmp( key , "hExitX" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hExitX] = strval( val ); }
                if( strcmp( key , "hExitY" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hExitY] = strval( val ); }
                if( strcmp( key , "hExitZ" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hExitZ] = strval( val ); }
                if( strcmp( key , "EnterInterior" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][EnterInterior] = strval( val ); }
                if( strcmp( key , "EnterWorld" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][EnterWorld] = strval( val ); }
                if( strcmp( key , "hPrice" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hPrice] = strval( val ); }
                if( strcmp( key , "hLocked" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hLocked] = strval( val ); }
                if( strcmp( key , "hProducts" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hProducts] = strval( val ); }
                if( strcmp( key , "hNumber" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hNumber] = strval( val ); }
                if( strcmp( key , "hType" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hType] = strval( val ); }
                if( strcmp( key , "hOwned" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hOwned] = strval( val ); }
                new string[128];
                if(HouseInfo[idx][hOwned] == 0)
                {
                    format(string, sizeof(string), "%s\nHouse for Sale\nAvailable Price is $%d", HouseInfo[idx][hName],HouseInfo[idx][hPrice]);
                    housetext[idx] = Create3DTextLabel(string,COLOR_ORANGERED,HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],40.0,0, 1);
                    housepickup[idx] = CreateDynamicPickup(1273, 23,  HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],-1,-1,-1,40.0);
                }
                else
                {
                    new housetype[128];
                    if(HouseInfo[idx][hType] != 0)
                    {
                        if(HouseInfo[idx][hType] == 1) { housetype = "Un-Furnished"; }
                        else if(HouseInfo[idx][hType] == 2) { housetype = "Furnished"; }
                    }
                    else { housetype = "Empty House"; }
                    format(string, sizeof(string), "%s\nOwner: %s\n%s House", HouseInfo[idx][hName],HouseInfo[idx][hOwner],housetype);
                    housetext2[idx] = Create3DTextLabel(string,COLOR_LAWNGREEN,HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],40.0,0, 1);
                    housepickup2[idx] = CreateDynamicPickup(1272, 23,  HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],-1,-1,-1,40.0);
                }
                fclose(example);
            }
        }
    }
    return 1;
}
CREATE HOUSE CODE

pawn Код:
if(strcmp(cmd, "/createhouse", true) == 0)
        {
            if (PlayerInfo[playerid][pAdmin] >= 4)
            {
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_SYSTEM, "[CMDINFO] - /createhouse [id] [type] [price] [name]");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 1 Un-Furnished");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 2 Furnished");
                    return 1;
                }
                new id = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_SYSTEM, "[CMDINFO] - /createhouse [id] [type] [price] [name]");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 1 Un-Furnished");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 2 Furnished");
                    return 1;
                }
                new Float:x,Float:y,Float:z;
                GetPlayerPos(playerid, x, y, z);
                HouseInfo[id][hEnterX] = x;
                HouseInfo[id][hEnterY] = y;
                HouseInfo[id][hEnterZ] = z;
                new id2;
                id2 = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_SYSTEM, "[CMDINFO] - /createhouse [id] [type] [price] [name]");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 1 Un-Furnished");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 2 Furnished");
                    return 1;
                }
                new id3;
                id3 = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_SYSTEM, "[CMDINFO] - /createhouse [id] [type] [price] [name]");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 1 Un-Furnished");
                    SendClientMessage(playerid, COLOR_SYSTEM, "Type: 2 Furnished");
                    return 1;
                }
                new length = strlen(cmdtext);
                while ((idx < length) && (cmdtext[idx] <= ' '))
                {
                    idx++;
                }
                new offset = idx;
                new result[64];
                while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                {
                    result[idx - offset] = cmdtext[idx];
                    idx++;
                }
                result[idx - offset] = EOS;
                HouseInfo[id][hType] = id2;
                strmid(HouseInfo[id][hName], (result), 0, strlen((result)), 128);
                HouseInfo[id][hPrice] = id3;
                if(HouseInfo[id][hType] == 1)
                {
                    HouseInfo[id][hExitX] = 116.51876068115;
                    HouseInfo[id][hExitY] = 1347.8156738281;
                    HouseInfo[id][hExitZ] = 1027.0693359375;
                    HouseInfo[id][EnterWorld] = id;
                    HouseInfo[id][EnterInterior] = 9;
                }
                if(HouseInfo[id][hType] == 2)
                {
                    HouseInfo[id][hExitX] = 223.48486328125;
                    HouseInfo[id][hExitY] = 1287.5721435547;
                    HouseInfo[id][hExitZ] = 1082.140625;
                    HouseInfo[id][EnterWorld] = id;
                    HouseInfo[id][EnterInterior] = 1;
                }
                format(string, sizeof(string), "[INFO:] House ID %d, Is a Type %d House and Cost %d, Named - %s", id, id2, id3, result);
                SendClientMessage(playerid, COLOR_SYSTEM, string);
                SaveHouses();
                if(HouseInfo[id][hOwned] == 0)
                {
                    format(string, sizeof(string), "%s\nHouse for Sale\nAvailable Price is $%d.00", HouseInfo[id][hName],HouseInfo[id][hPrice]);
                    Move3DTextLabel(housetext[id], string, COLOR_ORANGERED, x, y, z);
                    housepickup[idx] = CreateDynamicPickup(1273, 23,  HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],-1,-1,-1,40.0);
                }
                else
                {
                    new housetype[128];
                    if(HouseInfo[idx][hType] != 0)
                    {
                        if(HouseInfo[idx][hType] == 1) { housetype = "Un-Furnished"; }
                        else if(HouseInfo[idx][hType] == 2) { housetype = "Furnished"; }
                    }
                    else { housetype = "Empty House"; }
                    format(string, sizeof(string), "%s\nOwner: %s\n%s House", HouseInfo[id][hName],HouseInfo[id][hOwner],housetype);
                    Move3DTextLabel(housetext2[id], string, COLOR_LAWNGREEN, x, y, z);
                    housepickup2[idx] = CreateDynamicPickup(1272, 23,  HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],-1,-1,-1,40.0);
                }
                return 1;
            }
        }
SCREENSHOT OF SAVED FILE AFTER CREATE HOUSE



As you can see the file saves with no name .ini and also there is a weird 9S below it.

I haven't done much of this so any help would be very appreciated!
Reply


Messages In This Thread
House Save/Load System - by Phil_Cutcliffe - 14.02.2014, 15:21
Re: House Save/Load System - by CuervO - 14.02.2014, 15:26
Re: House Save/Load System - by Phil_Cutcliffe - 14.02.2014, 15:30
Re: House Save/Load System - by CuervO - 14.02.2014, 15:36
Re: House Save/Load System - by Phil_Cutcliffe - 14.02.2014, 15:41
Re: House Save/Load System - by CuervO - 14.02.2014, 15:51
Re: House Save/Load System - by Phil_Cutcliffe - 14.02.2014, 15:55
Re: House Save/Load System - by CuervO - 14.02.2014, 16:00
Re: House Save/Load System - by Phil_Cutcliffe - 14.02.2014, 16:35
Re: House Save/Load System - by CuervO - 14.02.2014, 17:04

Forum Jump:


Users browsing this thread: 3 Guest(s)