Load Houses -
wumpyc - 01.08.2013
This is my code I use for loading houses. It should load the house because there is all needed information in the scriptfiles, but i don't why it wont :/
pawn Код:
stock LoadHouses(houseid)
{
new fstring[10],file[40],string[256]; //The string for the file [format]
format(fstring, 10, "Houses/%d.ini", houseid); //Format the filename
if(!fexist(fstring)) return 0; //"If Houses/{houseid} not exists then return False (0)"
INI_ParseFile(file, "LoadHouseData_%s", .bExtra = true, .extra = houseid);
HouseMapIcon[houseid] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX],HouseInfo[houseid][hEnterY],HouseInfo[houseid][hEnterZ],31,-1,-1,-1,-1,100.0);
House[houseid] = CreateDynamicPickup(1272, 1, HouseInfo[houseid][hEnterX],HouseInfo[houseid][hEnterY],HouseInfo[houseid][hEnterZ]-0.5, -1, -1, -1, 50.0); //line 1458
if(HouseInfo[houseid][hOwned] == false){
format(string,sizeof(string),"{00FF00}Buy this house using /buyhouse\nHouse Price = %i\nHouse Level = %i\nHouse ID: %d",HouseInfo[houseid][hPrice],HouseInfo[houseid][hLevel],houseid);
HouseLabel[houseid] = CreateDynamic3DTextLabel(string, 0xFFFFFFFFFF, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ]+0.3,50.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0,-1,-1,-1,100.0);
}
else{
format(string,sizeof(string),"{00FF00}House Owner = %d\nHouse Level = %i\nHouse ID: %d",HouseInfo[houseid][hOwner],HouseInfo[houseid][hLevel],houseid);
HouseLabel[houseid] = CreateDynamic3DTextLabel(string, 0xFFFFFFFFFF, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ]+0.3,50.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0,-1,-1,-1,100.0);
}
return 1;
}
forward LoadHouseData_Main(houseid, name[], value[]);
public LoadHouseData_Main(houseid, name[], value[])
{
INI_Float("EnterX", HouseInfo[houseid][hEnterX]);
INI_Float("EnterY", HouseInfo[houseid][hEnterY]);
INI_Float("EnterZ", HouseInfo[houseid][hEnterY]);
INI_Int("InsideInt", HouseInfo[houseid][hInsideInt]);
INI_Int("InsideVir", HouseInfo[houseid][hInsideVir]);
INI_Int("OutsideInt", HouseInfo[houseid][hOutsideInt]);
INI_Int("OutsideVir", HouseInfo[houseid][hOutsideVir]);
INI_Int("Price", HouseInfo[houseid][hPrice]);
INI_Int("HV_Model", HouseInfo[houseid][hVecModel]);
INI_Float("HV_PosX", HouseInfo[houseid][hVecX]);
INI_Float("HV_PosY", HouseInfo[houseid][hVecY]);
INI_Float("HV_PosZ", HouseInfo[houseid][hVecZ]);
INI_Float("HV_PosA", HouseInfo[houseid][hVecA]);
INI_Bool("Owned", HouseInfo[houseid][hOwned]);
INI_String("Owner",HouseInfo[houseid][hOwner],40);
return 1;
}
public OnGameModeInit()
{
for(new i = 0; i < MAX_HOUSES; i++)
{
LoadHouses(i);
}
return 1;
}
Re: Load Houses -
ReVo_ - 01.08.2013
Houses/%d.ini
Your length is 12.
12 + (4 (if your max id is 1000)) + 1
Use 17 as size.
Anyway, be more specific but i'm sure your problem is fstring size. (If you debug your code first of post a thread here, your issues was fixed more fast by yourself)
Re: Load Houses -
wumpyc - 01.08.2013
Still doesn't load it. Here's my full house code:
pawn Код:
#define MAX_HOUSES 200
new HouseMapIcon[MAX_HOUSES],Text3D:HouseLabel[MAX_PLAYERS];
enum hInfo
{
Float:hEnterX, //Entrance X. It's an float! example: 0.0000000. I'm gonna use the same with the other entrances/exits
Float:hEnterY,
Float:hEnterZ,
hInsideInt, //The inside interior.. DUH!
hInsideVir, //Already subscribed above
hOutsideInt,
hOutsideVir,
bool:hOwned, //boolean! Is house owned? NO = False, YES = True
hOwner[MAX_PLAYER_NAME], //The house owner! I'm gonna use MAX_PLAYER_NAME, because a player can't have a longer name :')
hPrice, //Will store the price
hLevel,
hPickup, //The pickup. This is used to remove/move the pickup icon!
hIcon, //The map icon. Also used to remove/move it! We are going to need an ID. Without an ID we can't do NOTHING!
hVecModel, //The housecar's model
Float:hVecX, //X location. En float too.
Float:hVecY,
Float:hVecZ,
Float:hVecA
};
new HouseInfo[MAX_HOUSES][hInfo];
new House[MAX_HOUSES];
new HouseCar[MAX_HOUSES];
stock LoadHouses(houseid)
{
new fstring[128],string[256]; //The string for the file [format]
format(fstring, 128, "Houses/%d.ini", houseid); //Format the filename
if(!fexist(fstring)) return 0; //"If Houses/{houseid} not exists then return False (0)"
print("Stage 1: COMPLETE");
INI_ParseFile(fstring, "LoadHouseData_%s", .bExtra = true, .extra = houseid);
HouseMapIcon[houseid] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX],HouseInfo[houseid][hEnterY],HouseInfo[houseid][hEnterZ],31,-1,-1,-1,-1,100.0);
House[houseid] = CreateDynamicPickup(1272, 1, HouseInfo[houseid][hEnterX],HouseInfo[houseid][hEnterY],HouseInfo[houseid][hEnterZ]-0.5, -1, -1, -1, 50.0); //line 1458
if(HouseInfo[houseid][hOwned] == false){
format(string,sizeof(string),"{00FF00}Buy this house using /buyhouse\nHouse Price = %i\nHouse Level = %i\nHouse ID: %d",HouseInfo[houseid][hPrice],HouseInfo[houseid][hLevel],houseid);
HouseLabel[houseid] = CreateDynamic3DTextLabel(string, 0xFFFFFFFFFF, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ]+0.3,50.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0,-1,-1,-1,100.0);
print("Stage 2: COMPLETE");
}
else{
format(string,sizeof(string),"{00FF00}House Owner = %d\nHouse Level = %i\nHouse ID: %d",HouseInfo[houseid][hOwner],HouseInfo[houseid][hLevel],houseid);
HouseLabel[houseid] = CreateDynamic3DTextLabel(string, 0xFFFFFFFFFF, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ]+0.3,50.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0,-1,-1,-1,100.0);
print("Stage 2: COMPLETE");
}
return 1;
}
forward LoadHouseData_Main(houseid, name[], value[]);
public LoadHouseData_Main(houseid, name[], value[])
{
INI_Float("EnterX", HouseInfo[houseid][hEnterX]);
INI_Float("EnterY", HouseInfo[houseid][hEnterY]);
INI_Float("EnterZ", HouseInfo[houseid][hEnterY]);
INI_Int("InsideInt", HouseInfo[houseid][hInsideInt]);
INI_Int("InsideVir", HouseInfo[houseid][hInsideVir]);
INI_Int("OutsideInt", HouseInfo[houseid][hOutsideInt]);
INI_Int("OutsideVir", HouseInfo[houseid][hOutsideVir]);
INI_Int("Price", HouseInfo[houseid][hPrice]);
INI_Int("HV_Model", HouseInfo[houseid][hVecModel]);
INI_Float("HV_PosX", HouseInfo[houseid][hVecX]);
INI_Float("HV_PosY", HouseInfo[houseid][hVecY]);
INI_Float("HV_PosZ", HouseInfo[houseid][hVecZ]);
INI_Float("HV_PosA", HouseInfo[houseid][hVecA]);
INI_Bool("Owned", HouseInfo[houseid][hOwned]);
INI_String("Owner",HouseInfo[houseid][hOwner],40);
print("Stage 3: COMPLETE");
return 1;
}
public OnGameModeInit()
{
for(new i = 0; i < MAX_HOUSES; i++)
{
LoadHouses(i);
}
return 1;
}
stock GetNextHouseID()
{
for(new i = 0; i < MAX_HOUSES; i++)
{
if(fexist(HousePath(i))) continue;
return i;
}
return -1;
}
CMD:createhouse(playerid,params[])
{
if(PlayerInfo[playerid][pLevel] < 3) return error
new price,level;
if(sscanf(params,"ii",price,level)) return SendClientMessage(playerid, COLOR_RED,"USAGE: /createhouse <price> <level>");
if(level < 1 || level > 10) return SendClientMessage(playerid, COLOR_RED,"Minimum house level: 1\nMaximum house level: 10");
if(price < 100000) return SendClientMessage(playerid, COLOR_RED,"Too cheap! Please choose a higher value!");
new Float:x,Float:y,Float:z,string[128],nextid = GetNextHouseID();
GetPlayerPos(playerid,x,y,z); //line 1447
new file[64];
format(file, sizeof(file), HousePath(nextid));
new INI:File2 = INI_Open(file);
INI_SetTag(File2, "Main");
INI_WriteFloat(File2, "EnterX", x); //line 1981
INI_WriteFloat(File2, "EnterY", y);
INI_WriteFloat(File2, "EnterZ", z);
INI_WriteInt(File2, "InsideInt", HouseInfo[nextid][hInsideInt]);
INI_WriteInt(File2, "InsideVir", HouseInfo[nextid][hInsideVir]);
INI_WriteInt(File2, "OutsideInt", HouseInfo[nextid][hOutsideInt]);
INI_WriteInt(File2, "OutsideVir", HouseInfo[nextid][hOutsideVir]);
INI_WriteInt(File2, "Price", price);
INI_WriteInt(File2, "Level", level);
INI_WriteInt(File2, "HV_Model", HouseInfo[nextid][hVecModel]);
INI_WriteFloat(File2, "HV_PosX", HouseInfo[nextid][hVecX]);
INI_WriteFloat(File2, "HV_PosY", HouseInfo[nextid][hVecY]);
INI_WriteFloat(File2, "HV_PosZ", HouseInfo[nextid][hVecZ]);
INI_WriteFloat(File2, "HV_PosA", HouseInfo[nextid][hVecA]);
INI_WriteBool(File2, "Owned", false);
INI_WriteString(File2, "Owner",HouseInfo[nextid][hOwner]);
INI_Close(File2);
HouseInfo[nextid][hEnterX] = x;
HouseInfo[nextid][hEnterY] = y;
HouseInfo[nextid][hEnterZ] = z;
HouseInfo[nextid][hPrice] = price;
HouseInfo[nextid][hLevel] = level;
HouseMapIcon[nextid] = CreateDynamicMapIcon(HouseInfo[nextid][hEnterX],HouseInfo[nextid][hEnterY],HouseInfo[nextid][hEnterZ],31,-1,-1,-1,-1,100.0);
House[nextid] = CreateDynamicPickup(1272, 1, x, y, z-0.5, -1, -1, -1, 50.0); //line 1458
format(string,sizeof(string),"{00FF00}Buy this house using /buyhouse\nHouse Price = %i\nHouse Level = %i\nHouse ID: %d",HouseInfo[nextid][hPrice],HouseInfo[nextid][hLevel],nextid);
HouseLabel[nextid] = CreateDynamic3DTextLabel(string, 0xFFFFFFFFFF, HouseInfo[nextid][hEnterX], HouseInfo[nextid][hEnterY], HouseInfo[nextid][hEnterZ]+0.3,50.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0,-1,-1,-1,100.0);
SendClientMessage(playerid, COLOR_LIMEGREEN,"House successfully created!");
return 1;
}
stock HousePath(houseid)
{
new string[64];
format(string,sizeof(string),"/Houses/%d.ini", houseid);
return string;
}
Re: Load Houses -
ReVo_ - 01.08.2013
https://sampwiki.blast.hk/wiki/Debugging
Where the code stops to work?
EDIT:
Код:
new fstring[128],file[128],string[256]; //The string for the file [format]
format(fstring, 128, "Houses/%d.ini", houseid); //Format the filename
if(!fexist(fstring)) return 0; //"If Houses/{houseid} not exists then return False (0)"
INI_ParseFile(file, "LoadHouseData_%s", .bExtra = true, .extra = houseid);
Why you use fstring and file, you pass an empty string to INI_ParseFile. Remove "file" and use fstring
Re: Load Houses -
wumpyc - 01.08.2013
I just tried to print out at LoadHouseData_Main and at both stages of LoadHouses and i got all the prints out successfully.. Sounds like it goes trough everythign but sets something wrong?
Re: Load Houses -
Threshold - 01.08.2013
You are using INI_ParseFile(
file, when you should be using INI_ParseFile(
fstring, unless you want to format the string 'file', the 'new file[40]' becomes useless. Basically, you are passing an empty string into your INI_ParseFile function, therefore loading absolutely nothing.
EDIT: Oh shoot, just read the above poster's post, didn't even see him mention that.
Re: Load Houses -
wumpyc - 01.08.2013
Here's how my 0.ini (0 is house id) looks like:
pawn Код:
[Main]
EnterX = 1898.003784
EnterY = 729.104370
EnterZ = 10.819780
InsideInt = 0
InsideVir = 0
OutsideInt = 0
OutsideVir = 0
Price = 100000
Level = 1
HV_Model = 0
HV_PosX = 0.000000
HV_PosY = 0.000000
HV_PosZ = 0.000000
HV_PosA = 0.000000
Owned = false
Owner =
According to my code it passes trough all loading stages, however yet in-game i don't see map icon, 3d label nor house icon..
Re: Load Houses -
wumpyc - 02.08.2013
Maybe a mistake creating objects? hmm :/
Re: Load Houses -
wumpyc - 03.08.2013
bump
Re: Load Houses -
Ayumi - 03.08.2013
I personally don't understand why you have created a house system the hard way... That's also inefficient?
For example, you could have simplified things by using your "stock" for everything rather than creating a new "public" function to load the house data. It would also make things look more tidy in your "OnGameModeInit" etc also when you could just use "LoadHouses();"
Did you follow a tutorial to create this? Or make it from scratch from your humble knowledge?