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
#2

#1 when saving houses:
format(string3, sizeof(string3), "South-WestRP/Houses/%s.ini", idx) -- while idx is an integer.

#2 Same mistake at loading:
format(string2, sizeof(string2), "South-WestRP/Houses/%s.ini", idx) idx is an integer, not a string.


As for the newlines not appearing, use another text editor.


If you feel to rewrite your code, Y_Inis or MySQL provide great flexibility when it comes to data manipulation. Especially SQL queries.
Same for sscanf and commands.
Reply
#3

Quote:
Originally Posted by CuervO
Посмотреть сообщение
#1 when saving houses:
format(string3, sizeof(string3), "South-WestRP/Houses/%s.ini", idx) -- while idx is an integer.

#2 Same mistake at loading:
format(string2, sizeof(string2), "South-WestRP/Houses/%s.ini", idx) idx is an integer, not a string.


As for the newlines not appearing, use another text editor.


If you feel to rewrite your code, Y_Inis or MySQL provide great flexibility when it comes to data manipulation. Especially SQL queries.
Same for sscanf and commands.
Could you please give me an example of how I should use idx? Also I know notepad doesn't show the lines correctly I just ment it wasn't saving the coordinates or anything.. Is that because of how idx is used on saving/loading like you said?
Reply
#4

Change %s into %d and it'll work. You're rendering a string with an integer.
Reply
#5

Ok sorry I did ds.ini and not %d.ini

I've done that and now when I do /createhouse it saves 0.ini up to 999.ini all at once. But the stuff inside the houses file I made looks messed up..



What's going on?
Reply
#6

Are you sure you put %d and not %ds or ds alone?
Reply
#7

Quote:
Originally Posted by CuervO
Посмотреть сообщение
Are you sure you put %d and not %ds or ds alone?
Just edited
Reply
#8

Well, SaveHouses just loops from 0 to what I assume is the max houses array size (1000).

I recommend adding a new variable to the house info which determines if the house is created or not, and save/load based on that variable.

Also, your save code uses %s on all fields, while some are floats and other are integers,
And your load code uses strval on all fields, while some are strings and others are floats.
Reply
#9

How can I go about adding a variable to my house info checking if a house is created or not? Not really too sure how I would go about doing that. Could you show an example?

I've fixed everything else thankyou very much for you time! I will +rep you as soon as it lets me again x)

EDIT: I seem to also have another problem. I /createhouse and it does it fine and saves it fine to the correct file corresponding to the ID I input and even when I /buyhouse it saves fine. But when shutting down the server and restarting it just puts that house ID coordinates to 0.0 0.0 0.0 in the game but in the file it's still set how it was saved. I think I have a problem when loading. Here's my updated code for save/load/create and also /buy

SAVE

pawn Код:
forward SaveHouses();
public SaveHouses()
{
    new string3[128];
    for(new idx; idx < sizeof(HouseInfo); idx++)
    {
        format(string3, sizeof(string3), "South-WestRP/Houses/%d.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=%f\n", HouseInfo[idx][hEnterX]);fwrite(hFile, var);
            format(var, 32, "hEnterY=%f\n", HouseInfo[idx][hEnterY]);fwrite(hFile, var);
            format(var, 32, "hEnterZ=%f\n", HouseInfo[idx][hEnterZ]);fwrite(hFile, var);
            format(var, 32, "hExitX=%f\n", HouseInfo[idx][hExitX]);fwrite(hFile, var);
            format(var, 32, "hExitY=%f\n", HouseInfo[idx][hExitY]);fwrite(hFile, var);
            format(var, 32, "hExitZ=%f\n", HouseInfo[idx][hExitZ]);fwrite(hFile, var);
            format(var, 32, "EnterInterior=%d\n", HouseInfo[idx][EnterInterior]);fwrite(hFile, var);
            format(var, 32, "EnterWorld=%d\n", HouseInfo[idx][EnterWorld]);fwrite(hFile, var);
            format(var, 32, "hPrice=%d\n", HouseInfo[idx][hPrice]);fwrite(hFile, var);
            format(var, 32, "hLocked=%d\n", HouseInfo[idx][hLocked]);fwrite(hFile, var);
            format(var, 32, "hProducts=%d\n", HouseInfo[idx][hProducts]);fwrite(hFile, var);
            format(var, 32, "hNumber=%d\n", HouseInfo[idx][hNumber]);fwrite(hFile, var);
            format(var, 32, "hType=%d\n", HouseInfo[idx][hType]);fwrite(hFile, var);
            format(var, 32, "hOwned=%d\n", HouseInfo[idx][hOwned]);fwrite(hFile, var);
            fclose(hFile);
        }
    }
    return 1;
}
LOAD

pawn Код:
forward LoadHouses();
public LoadHouses()
{
    new string2[128];
    for(new idx; idx < sizeof(HouseInfo); idx++)
    {
        format(string2, sizeof(string2), "South-WestRP/Houses/%d.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] = floatstr( val ); }
                if( strcmp( key , "hEnterY" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hEnterY] = floatstr( val ); }
                if( strcmp( key , "hEnterZ" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hEnterZ] = floatstr( val ); }
                if( strcmp( key , "hExitX" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hExitX] = floatstr( val ); }
                if( strcmp( key , "hExitY" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hExitY] = floatstr( val ); }
                if( strcmp( key , "hExitZ" , true ) == 0 ) { val = ini_GetValue( Data ); HouseInfo[idx][hExitZ] = floatstr( 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];
                new housetype[128];
                if(HouseInfo[idx][hOwned] == 0)
                {
                    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\nHouse for Sale\nAvailable Price is $%d", housetype,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
                {
                    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

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", id, id2, id3);
                SendClientMessage(playerid, COLOR_SYSTEM, string);
                SaveHouses();
                new housetype[128];
                if(HouseInfo[id][hOwned] == 0)
                {
                    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\nHouse for Sale\nAvailable Price is $%d", housetype,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
                {
                    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;
            }
        }
BUY

pawn Код:
if(strcmp(cmd, "/buyhouse", true) == 0)
        {
            new house = IsPlayerNearHouse(playerid);
            if(house == -1) return SendClientMessage(playerid, COLOR_CORAL, "You are not at the location");
            if(HouseInfo[house][hOwned] == 1) return SendClientMessage(playerid, COLOR_CORAL, "This House is already owned");
            if(PlayerInfo[playerid][pHouse1] < 999 && PlayerInfo[playerid][pHouse2] < 999)
            {
                SendClientMessage(playerid, COLOR_SYSTEM, "You already own 2 houses.");
                return 1;
            }
            if(GetPlayerCash(playerid) >= HouseInfo[house][hPrice])
            {
                DestroyDynamicPickup(housepickup[house]);
                Delete3DTextLabel(housetext[house]);
                new housetype[128];
                if(HouseInfo[house][hType] != 0)
                {
                    if(HouseInfo[house][hType] == 1) { housetype = "Un-Furnished"; }
                    else if(HouseInfo[house][hType] == 2) { housetype = "Furnished"; }
                }
                else { housetype = "Empty House"; }
                format(string, sizeof(string), "%s\nOwner: %s\n%s House", HouseInfo[house][hName],GetPlayerNameEx(playerid),housetype);
                housetext2[house] = Create3DTextLabel(string,COLOR_LAWNGREEN,HouseInfo[house][hEnterX], HouseInfo[house][hEnterY], HouseInfo[house][hEnterZ],40.0,0);
                housepickup2[house] = CreateDynamicPickup(1272, 23,  HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],-1,-1,-1,40.0);
                GivePlayerCash(playerid, -HouseInfo[house][hPrice]);
                if(PlayerInfo[playerid][pHouse1] == 999)
                {
                    HouseInfo[house][hOwned] = 1;
                    PlayerInfo[playerid][pHouse1] = house;
                    HouseInfo[house][hProducts] = 500;
                    HouseInfo[house][hOwner] = GetPlayerNameEx(playerid);
                    strmid(HouseInfo[house][hOwner], GetPlayerNameEx(playerid), 0, strlen(GetPlayerNameEx(playerid)), 255);
                    SaveHouses();
                    InfoBoxForPlayer(playerid, "You bought a house, you can view your house commands using /househelp");
                    return 1;
                }
                if(PlayerInfo[playerid][pHouse2] == 999)
                {
                    HouseInfo[house][hOwned] = 1;
                    PlayerInfo[playerid][pHouse2] = house;
                    HouseInfo[house][hProducts] = 500;
                    HouseInfo[house][hOwner] = GetPlayerNameEx(playerid);
                    strmid(HouseInfo[house][hOwner], GetPlayerNameEx(playerid), 0, strlen(GetPlayerNameEx(playerid)), 255);
                    SaveHouses();
                    InfoBoxForPlayer(playerid, "You bought a house, you can view your house commands using /househelp");
                    return 1;
                }
            }
        }
Reply
#10

When creating: hCreated = 1.
Load only if the file exists, set hCreated to 1 when the house loads.

Aaand that's pretty much it, save only if hCreated == 1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)