20.10.2011, 08:43
Hi all,
I've started my house system with MySQL but I have problems, just one house saves in the database, i've put 2 in OnGameModeInit (One line, one house)
Here is the script:
I've started my house system with MySQL but I have problems, just one house saves in the database, i've put 2 in OnGameModeInit (One line, one house)
Here is the script:
pawn Код:
/*
* S32_House - Create house with just one line (MySQL)!
* Copyright©System32
* This file is provided as is (no warranties)
*/
#if defined _S32_House_included
#endinput
#endif
#define _S32_House_included
#include <a_samp>
#include <a_mysql>
#include <YSI\y_commands>
#include <YSI\y_hooks>
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define MAX_HOUSE 150
enum hInfo
{
hOwner[24],
Float: hEnterX,
Float: hEnterY,
Float: hEnterZ,
Float: hExitX,
Float: hExitY,
Float: hExitZ,
hInterior,
hPrice,
hVirtualWorld,
};
new HouseInfo[MAX_HOUSE][hInfo];
//new PlayerHaveHouse[MAX_PLAYERS];
new House = -1, House_Price[MAX_HOUSE] = 0, Buy_House[MAX_HOUSE];
new Label = -1;
new Text3D: LabelMake[sizeof(Label)];
new hstring[128] = -1;
new HQuery[300];
new HouseID;
stock CreateDynamicHouse(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: InteriorX, Float: InteriorY, Float: InteriorZ, Price, VirtualWorld)
{
House += 1;
House_Price[House] = Price;
Buy_House[House] = CreatePickup(1239, 2, EnterX, EnterY, EnterZ, -1);
hstring[126] += 1;
format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nHouse ID: %d\nType /buyhouse to buy house!", Price, HouseID);
Label += 1;
LabelMake[Label] = Create3DTextLabel(hstring, 0x21DD00FF, EnterX, EnterY, EnterZ, 40.0, 0);
format(HQuery, sizeof(HQuery), "SELECT * FROM `house` WHERE `HouseID` = '%d'", HouseID);
mysql_query(HQuery);
mysql_store_result();
if(mysql_num_rows() == 0)
{
HouseInfo[HouseID][hEnterX] = EnterX;
HouseInfo[HouseID][hEnterY] = EnterY;
HouseInfo[HouseID][hEnterZ] = EnterZ;
HouseInfo[HouseID][hExitX] = InteriorX;
HouseInfo[HouseID][hExitY] = InteriorY;
HouseInfo[HouseID][hExitZ] = InteriorZ;
HouseInfo[HouseID][hInterior] = Interior;
HouseInfo[HouseID][hVirtualWorld] = VirtualWorld;
HouseInfo[HouseID][hPrice] = Price;
format(HQuery, sizeof(HQuery), "INSERT INTO `house` (`User`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `Interior`, `Price`, `VirtualWorld`, `HouseID`) VALUES");
format(HQuery, sizeof(HQuery), "%s ('None', '%f', '%f', '%f', '%f', '%f', '%f', '%d', '%d', '%d', '%d')", HQuery, HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ], HouseInfo[HouseID][hExitX], HouseInfo[HouseID][hExitY], HouseInfo[HouseID][hExitZ], HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseID);
mysql_query(HQuery);
printf("House ID %d created", HouseID);//debug
}
else
{
if(mysql_fetch_row_format(HQuery, "|"))
{
new hsavingstring[1000];
mysql_fetch_field_row(hsavingstring, "User"); HouseInfo[HouseID][hOwner] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "EnterX"); HouseInfo[HouseID][hEnterX] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "EnterY"); HouseInfo[HouseID][hEnterY] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "EnterZ"); HouseInfo[HouseID][hEnterZ] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "ExitX"); HouseInfo[HouseID][hExitX] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "ExitY"); HouseInfo[HouseID][hExitY] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "ExitZ"); HouseInfo[HouseID][hExitZ] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "Interior"); HouseInfo[HouseID][hInterior] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "Price"); HouseInfo[HouseID][hPrice] = strval(hsavingstring);
mysql_fetch_field_row(hsavingstring, "VirtualWorld"); HouseInfo[HouseID][hVirtualWorld] = strval(hsavingstring);
}
}
mysql_free_result();
HouseID ++;
return 1;
}
Hook:H1_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_SECONDARY_ATTACK && !IsPlayerInAnyVehicle(playerid))
{
for(new i = 0; i < MAX_HOUSE; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid) == 0)
{
SetPlayerInterior(playerid, HouseInfo[i][hInterior]);
SetPlayerVirtualWorld(playerid, HouseInfo[i][hVirtualWorld]);
SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
}
else if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hInterior] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hVirtualWorld])
{
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerPos(playerid, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]);
}
}
}
return 1;
}