House System -
Wesley221 - 08.01.2012
Hey guys,
Im making a house system, but somehow i cant come any further then the CreateHouse function. Ive tried to test it in game to create a house, but it simply doesnt go any further.
pawn Код:
stock CreateHouse( playerid, price, owned, Float:x, Float:y, Float:z, virtualworld, ownername[])
{
new id = HouseCount, INI:pFile = INI_Open(hPath(id)), Label[128];
print( "Price" );
HouseInfo[id][Price] = price;
printf( "Prijs: %i", HouseInfo[id][Price] );
print( "Owned" );
HouseInfo[id][Owned] = owned;
print( "X" );
HouseInfo[id][XPos] = x;
print( "Y" );
HouseInfo[id][YPos] = y;
print( "Z" );
HouseInfo[id][ZPos] = z;
print( "VW" );
HouseInfo[id][VirtualWorld] = virtualworld;
print( "Owner" );
strset( HouseInfo[id][Owner], ownername );
HouseEnter[id] = CreateDynamicCP( x, y, z, 1.5, GetPlayerVirtualWorld( playerid ) );
HouseExit[id] = CreateDynamicCP( 443.9237, 509.4609, 1001.4195, 1.5, id );
INI_WriteInt( pFile, "Prijs", price );
INI_WriteInt( pFile, "Owned", 0 );
INI_WriteInt( pFile, "Virtualworld", GetPlayerVirtualWorld( playerid ) );
INI_WriteFloat( pFile, "Pickup_X", x );
INI_WriteFloat( pFile, "Pickup_Y", y );
INI_WriteFloat( pFile, "Pickup_Z", z );Iv
INI_WriteString( pFile, "Eigenaar", "HeeftGeenEigenaar" );
INI_Close( pFile );
switch( owned )
{
case 0: format( Label, sizeof Label, "Dit huis is nog te koop! \nEigenaar: N/A \nPrijs: $%i", price );
case 1: format( Label, sizeof Label, "Dit huis is niet meer te koop! \nEigenaar: %s \nPrijs: $%i", ownername, price );
}
HouseInfo[id][HouseLabel] = Create3DTextLabel( Label, COLOR_GREEN, x, y, z, 25.0, GetPlayerVirtualWorld( playerid ) );
HouseCount ++;
return 1;
}
As you can see, ive already debugged. The last print was 'Price'.
Im using the function in this command:
pawn Код:
YCMD:createhouse(playerid, params[], help)
{
if( help ) SendClientMessage( playerid, COLOR_BLUE, "Maak een mooi huisje aan " );
if( IsPlayerAdmin(playerid) )
{
new HousePrice;
if( !sscanf( params, "i", HousePrice ) )
{
new Float:x,
Float:y,
Float:z,
Gegevens[128];
GetPlayerPos( playerid, x, y, z );
CreateHouse( playerid, HousePrice, 0, x, y, z, GetPlayerVirtualWorld( playerid ), "GeenEigenaarAanwezig" );
format( Gegevens, sizeof Gegevens, "X: %0.4f | Y: %0.4f | Z: %0.4f | Virtualworld: %i", x, y, z, GetPlayerVirtualWorld( playerid ) );
SendClientMessage( playerid, COLOR_GREEN, "Huis is aangemaakt op jouw positie. " );
SendClientMessage( playerid, COLOR_GREEN, Gegevens );
} else return SendClientMessage( playerid, COLOR_YELLOW, "Werking: /createhouse <prijs>" );
} else return SendAdminError(playerid);
return 1;
}
Anyone knows what the problem can be?
~Wesley
Re: House System -
Norck - 08.01.2012
So, the last print was 'Price'.
Try to print the value of id, like:
pawn Код:
printf("Current id = '%d' ",id);
print( "Price" );
Let's see, maybe id is out of bounds.
Re: House System -
Wesley221 - 08.01.2012
The ID is 0.
Re: House System -
DeathTone - 08.01.2012
You could use format(HInfo[id][OwnerName], 24, "%s", ownername); instead of strset
By the way, what exactly happens when you type /createhouse? does it create the checkpoints?
Re: House System -
Wesley221 - 09.01.2012
Using 'strset' is better as the format one. And like ive said before, it just stops at 'price' and not going any further
Re: House System -
Wesley221 - 09.01.2012
Sorry for the double post, but ive got an update.
The checkpoints creates just fine now, i just had to make a new file in the scriptfiles named '0.ini'.
Now i just got a problem with loading the checkpoints. Whenever i use the function LoadHouses(), it doesnt load the data in the enum.
pawn Код:
stock LoadHouses()
{
for( new i = 0; i <= MAX_HOUSES; i ++ )
{
printf( "I: %i", i );
if( !fexist( hPath(i) ) ) break;
print( "Parse" );
INI_ParseFile(hPath(i), "LoadHouses_%i", .bExtra = true, .extra = i);
print( "CP Enter" );
printf( "HouseInfo[i][XPos] %0.4f || HouseInfo[i][YPos] %0.4f || HouseInfo[i][ZPos] %0.4f", HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos] );
HouseEnter[i] = CreateDynamicCP( HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos], 1.5, HouseInfo[i][VirtualWorld] );
HouseExit[i] = CreateDynamicCP( 443.9237, 509.4609, 1001.4195, 1.5, HouseInfo[i][VirtualWorld] );
print( "CP Exit" );
new LabelString[128];
switch( HouseInfo[i][Owned] )
{
case 0: format( LabelString, sizeof LabelString, "Dit huis is nog te koop! \nEigenaar: N/A \nPrijs: $%i", HouseInfo[i][Price] ), print( "0" );
case 1: format( LabelString, sizeof LabelString, "Dit huis is niet meer te koop! \nEigenaar: %s \nPrijs: %i", HouseInfo[i][Owner], HouseInfo[i][Price] ), print( "1" );
}
HouseInfo[i][HouseLabel] = Create3DTextLabel( LabelString, COLOR_GREEN, HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos], 25.0, HouseInfo[i][VirtualWorld] );
printf( "HouseCount: %i", HouseCount );
HouseCount ++;
}
return 1;
}
It parses all the print's though, it doenst load it all:
Код:
[09:24:42] I: 0
[09:24:42] Parse
[09:24:42] CP Enter
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] CP Exit
[09:24:42] 0
[09:24:42] HouseCount: 0
[09:24:42] I: 1
[09:24:42] Parse
[09:24:42] CP Enter
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] CP Exit
[09:24:42] 0
[09:24:42] HouseCount: 1
[09:24:42] I: 2
[09:24:42] Parse
[09:24:42] CP Enter
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] CP Exit
[09:24:42] 0
[09:24:42] HouseCount: 2
[09:24:42] I: 3
[09:24:42] Parse
[09:24:42] CP Enter
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] CP Exit
[09:24:42] 0
[09:24:42] HouseCount: 3
[09:24:42] I: 4
pawn Код:
forward LoadHouses_data(id, name[], value[]);
public LoadHouses_data(id, name[], value[])
{
INI_Int( "Price", HouseInfo[id][Price] );
printf( "Price: %i", HouseInfo[id][Price] );
INI_Int( "Owned", HouseInfo[id][Owned] );
printf( "Owned: %i", HouseInfo[id][Owned] );
INI_Float( "Pickup_X", HouseInfo[id][XPos] );
printf( "X: %f", HouseInfo[id][XPos] );
INI_Float( "Pickup_Y", HouseInfo[id][YPos] );
printf( "Y: %f", HouseInfo[id][YPos] );
INI_Float( "Pickup_Z", HouseInfo[id][ZPos] );
printf( "Z: %f", HouseInfo[id][ZPos] );
INI_Int( "Virtualworld", HouseInfo[id][VirtualWorld] );
printf( "VW: %i", HouseInfo[id][VirtualWorld] );
INI_String( "Owner", HouseInfo[id][Owner], 24 );
printf( "Owner: %s", HouseInfo[id][Owner] );
return 1;
}
NOTE: With the INI_ParseFile ive tried %s, and %i/%d.