Код:
#include <a_samp>
#include <a_mysql>
#include <streamer>
#include <zcmd>
#include <sscanf2>
#define MySQL_Host "127.0.0.1"
#define MySQL_User "root"
#define MySQL_Pass ""
#define MySQL_DB "samp"
#define Houses_Table "houses"
enum PlayerInfo
{
CurrentHID
};
new pInfo[MAX_PLAYERS][PlayerInfo];
#define HMenu 1234
#define CInt 1235
#define MAX_HOUSES 2000
enum HInfo
{
ID,
Owner[25],
Owned,
Locked,
InteriorID,
World,
Price,
Float:OX,
Float:OY,
Float:OZ,
Float:IX,
Float:IY,
Float:IZ,
Text3D:Label,
Icon,
EnterPickup,
ExitPickup
};
new HouseInfo[MAX_HOUSES][HInfo];
new CreatedHouses = 0;
new query[256];
new SQL = -1;
public OnFilterScriptInit()
{
SQL = mysql_connect(MySQL_Host, MySQL_User, MySQL_DB, MySQL_Pass);
LoadHouses();
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
pInfo[playerid][CurrentHID] = -1;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
pInfo[playerid][CurrentHID] = -1;
return 1;
}
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
for(new i=1; i<=CreatedHouses; i++)
{
if(pickupid == HouseInfo[i][ExitPickup])
{
KickFromHouse(playerid, i);
}
else if(pickupid == HouseInfo[i][EnterPickup])
{
if(HouseInfo[i][Owned] == 0)
{
SendClientMessage(playerid, -1, "You can buy this house using /buyhouse!");
return 1;
}
else if(HouseInfo[i][Owned] == 1)
{
if(HouseInfo[i][Locked] == 1)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name, HouseInfo[i][Owner]) != 0)
{
SendClientMessage(playerid, -1, "This house is currently locked! You cannot enter it!");
return 1;
}
}
PutPlayerInHouse(playerid, i);
break;
}
else continue;
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == HMenu)
{
new hID = pInfo[playerid][CurrentHID], lString[256];
if(response)
{
if(listitem == 0)
{
if(HouseInfo[hID][Locked] == 0)
{
HouseInfo[hID][Locked] = 1;
SendClientMessage(playerid, -1, "House has been locked!");
format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", HouseInfo[hID][Owner], HouseInfo[hID][Price], (HouseInfo[hID][Locked] == 1) ? ("Yes") : ("No"));
UpdateDynamic3DTextLabelText(Text3D:HouseInfo[hID][Label], -1, lString);
mysql_format(SQL, query, sizeof(query), "UPDATE `"Houses_Table"` SET `Locked` = '%i' WHERE `ID` = '%i'", HouseInfo[hID][Locked], hID);
mysql_tquery(SQL, query, "", "");
}
else if(HouseInfo[hID][Locked] == 1)
{
HouseInfo[hID][Locked] = 0;
SendClientMessage(playerid, -1, "House successfully unlocked!");
format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", HouseInfo[hID][Owner], HouseInfo[hID][Price], (HouseInfo[hID][Locked] == 1) ? ("Yes") : ("No"));
UpdateDynamic3DTextLabelText(Text3D:HouseInfo[hID][Label], -1, lString);
mysql_format(SQL, query, sizeof(query), "UPDATE `"Houses_Table"` SET `Locked` = '%i' WHERE `ID` = '%i'", HouseInfo[hID][Locked], hID);
mysql_tquery(SQL, query, "", "");
}
}
if(listitem == 1)
{
ShowPlayerDialog(playerid, CInt, DIALOG_STYLE_LIST, "Interior List", "Ryder's house($3000000)\nUnused house($1000000)\n", "Change", "Back");
}
if(listitem == 2)
{
new name[25];
format(name,25,"None");
HouseInfo[hID][Owner] = name;
HouseInfo[hID][Locked] = 0;
HouseInfo[hID][Owned] = 0;
format(lString, sizeof(lString), "House Owned: No\nHouse Owner: None\nHouse Price: $%i", HouseInfo[hID][Price]);
UpdateDynamic3DTextLabelText(Text3D:HouseInfo[hID][Label], -1, lString);
mysql_format(SQL, query, sizeof(query), "UPDATE `"Houses_Table"` SET `Owner` = '%s', `Owned` = '%i', `Locked` = '%i'", HouseInfo[hID][Owner], HouseInfo[hID][Owned], HouseInfo[hID][Locked]);
mysql_tquery(SQL, query, "", "");
DestroyDynamicMapIcon(HouseInfo[hID][Icon]);
HouseInfo[hID][Icon] = CreateDynamicMapIcon(HouseInfo[hID][OX], HouseInfo[hID][OY], HouseInfo[hID][OZ], 31, -1);
GivePlayerMoney(playerid, HouseInfo[hID][Price]/2);
new string[128];
format(string, sizeof(string),"You've successfully sold the house and recieved $%i!", HouseInfo[hID][Price]/2);
SendClientMessage(playerid, -1, string);
KickFromHouse(playerid, hID);
}
}
}
if(dialogid == CInt)
{
new hID = pInfo[playerid][CurrentHID];
if(!response)
{
ShowPlayerDialog(playerid, HMenu, DIALOG_STYLE_LIST, "House Menu", "(UN)Lock House\nChange Interior\nSell House\n", "Select", "Cancel");
}
if(response)
{
if(listitem == 0)
{
if(GetPlayerMoney(playerid) < 3000000) return SendClientMessage(playerid,-1, "You don't have enough money to buy this interior!");
if(HouseInfo[hID][InteriorID] == 1) return SendClientMessage(playerid, -1, "The current house interior is already the same!");
HouseInfo[hID][InteriorID] = 1;
SendClientMessage(playerid, -1, "Interior changed. Please re-enter your house!");
DestroyDynamicPickup(HouseInfo[hID][ExitPickup]);
SetHouseExit(playerid, hID);
KickFromHouse(playerid, hID);
}
if(listitem == 1)
{
if(GetPlayerMoney(playerid) < 1000000) return SendClientMessage(playerid,-1, "You don't have enough money to buy this interior!");
if(HouseInfo[hID][InteriorID] == 2) return SendClientMessage(playerid,-1, "The current house interior is already the same!");
HouseInfo[hID][InteriorID] = 2;
SendClientMessage(playerid, -1, "Interior changed. Please re-enter your house!");
DestroyDynamicPickup(HouseInfo[hID][ExitPickup]);
SetHouseExit(playerid, hID);
KickFromHouse(playerid, hID);
}
}
}
return 1;
}
//==================================[Commands]==================================
CMD:chid(playerid,params[])
{
new string[127];
format(string,127,"house id %i",pInfo[playerid][CurrentHID]);
SendClientMessage(playerid,-1,string);
return 1;
}
CMD:createhouse(playerid,params[])
{
new HID = CreatedHouses+1, price, interior, Float:x, Float:y, Float:z;
if(!IsPlayerAdmin(playerid)) return 0; //Do nothing if the player is not admin..
if(sscanf(params, "ii", price, interior)) return SendClientMessage(playerid,-1,"Usage: /createhouse (price) (interior)"); //If they didn't enter the house price and interior or if they entered it wrongly, then send this message.
if(interior >= 3 || interior <= 0) return SendClientMessage(playerid,-1,"Valid house interiors are 1 and 2 only!");
if(CreatedHouses == MAX_HOUSES-1) return SendClientMessage(playerid, -1,"House creation limit has been exceeded! [500]"); //If the created houses is equal to max houses -1, then send this message
GetPlayerPos(playerid, x, y, z);
//=============================[Lets set it up]=============================
HouseInfo[HID][ID] = HID;
new name[25];
format(name,25,"None");
HouseInfo[HID][Owner] = name;
HouseInfo[HID][Locked] = 0;
HouseInfo[HID][World] = HID;
HouseInfo[HID][InteriorID] = interior;
HouseInfo[HID][Price] = price;
HouseInfo[HID][OX] = x;
HouseInfo[HID][OY] = y;
HouseInfo[HID][OZ] = z;
new string[256];
format(string, sizeof(string), "House Owned: No\nHouse Owner: None\nHouse Price: $%i", HouseInfo[HID][Price]);
HouseInfo[HID][Label] = CreateDynamic3DTextLabel(string, -1, HouseInfo[HID][OX], HouseInfo[HID][OY], HouseInfo[HID][OZ]+0.5, 20.0);
HouseInfo[HID][Icon] = CreateDynamicMapIcon(HouseInfo[HID][OX], HouseInfo[HID][OY], HouseInfo[HID][OZ], 31, -1);
HouseInfo[HID][EnterPickup] = CreateDynamicPickup(1273, 23, HouseInfo[HID][OX], HouseInfo[HID][OY], HouseInfo[HID][OZ], -1, -1, -1, 20.0);
mysql_format(SQL, query, sizeof(query), "INSERT INTO `"Houses_Table"` (ID, Owner, Owned, Locked, InteriorID, World, Price, OX, OY, OZ) VALUES ('%i', '%s', '%i', '%i', '%i', '%i', '%i', '%f', '%f', '%f')",
HouseInfo[HID][ID], HouseInfo[HID][Owner], HouseInfo[HID][Owned], HouseInfo[HID][Locked], HouseInfo[HID][InteriorID], HouseInfo[HID][World], HouseInfo[HID][Price], HouseInfo[HID][OX], HouseInfo[HID][OY], HouseInfo[HID][OZ]);
if(mysql_tquery(SQL, query, "", ""))
SendClientMessage(playerid, -1, "House was successfully created!");
else
SendClientMessage(playerid, -1, "House was not created!");
SetHouseExit(playerid, HID);
CreatedHouses++;
return 1;
}
CMD:housemenu(playerid,params[])
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(pInfo[playerid][CurrentHID] == -1) return SendClientMessage(playerid,-1,"You are not inside an house!"); //If the player is not inside an house, then send this message..
if(strcmp(name, HouseInfo[pInfo[playerid][CurrentHID]][Owner]) != 0) return SendClientMessage(playerid, -1, "You don't own this house!");
ShowPlayerDialog(playerid, HMenu, DIALOG_STYLE_LIST, "House Menu", "(UN)Lock House\nChange Interior\nSell House\n", "Select", "Cancel");
return 1;
}
CMD:gotohouse(playerid,params[])
{
new hID;
if(sscanf(params, "i", hID)) return SendClientMessage(playerid,-1, "Usage: /gotohouse (house id)");
if(hID == 0 || hID < CreatedHouses) return SendClientMessage(playerid, -1, "Invalid house ID!");
SetPlayerPos(playerid, HouseInfo[hID][OX], HouseInfo[hID][OY], HouseInfo[hID][OZ]);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerInterior(playerid, 0);
return 1;
}
CMD:buyhouse(playerid,params[])
{
new id = 0, name[25], count = 0;
for(new i=1; i<=CreatedHouses; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 4.0, HouseInfo[i][OX], HouseInfo[i][OY], HouseInfo[i][OZ]))
{
id = i;
break;
}
}
for(new i=1; i<=CreatedHouses; i++)
{
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name, HouseInfo[i][Owner]) == 0)
{
count++;
}
}
if(id == 0) return SendClientMessage(playerid, -1, "You aren't near an house!");
if(count >= 2) return SendClientMessage(playerid, -1, "You can't own more than 2 houses!");
if(HouseInfo[id][Owned] == 1) return SendClientMessage(playerid, -1, "This house is already owned!");
if(GetPlayerMoney(playerid) < HouseInfo[id][Price]) return SendClientMessage(playerid, -1, "You don't have enough money to buy this house!");
GetPlayerName(playerid, name, 25);
HouseInfo[id][Owned] = 1;
HouseInfo[id][Owner] = name;
GivePlayerMoney(playerid,-HouseInfo[id][Price]);
new lString[256];
DestroyDynamicMapIcon(HouseInfo[id][Icon]);
HouseInfo[id][Icon] = CreateDynamicMapIcon(HouseInfo[id][OX], HouseInfo[id][OY], HouseInfo[id][OZ], 32, -1);
format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", HouseInfo[id][Owner], HouseInfo[id][Price], (HouseInfo[id][Locked] == 1) ? ("Yes") : ("No"));
UpdateDynamic3DTextLabelText(Text3D:HouseInfo[id][Label], -1, lString);
mysql_format(SQL, query, sizeof(query),"UPDATE `"Houses_Table"` SET `Owned` = '%i', `Owner` = '%s' WHERE `ID` = '%i'",HouseInfo[id][Owned], HouseInfo[id][Owner], id);
if(mysql_tquery(SQL, query, "", ""))
SendClientMessage(playerid, -1, "Congratulations on buying an new house! Access your house menu using /housemenu!");
else
SendClientMessage(playerid, -1, "Some error occured! Please contact an admin!");
PutPlayerInHouse(playerid, id);
return 1;
}
//==============================================================================
forward LoadHouses();
public LoadHouses()
{
for(new i=0; i<=MAX_HOUSES; i++)
{
mysql_format(SQL, query, sizeof(query),"SELECT * FROM `"Houses_Table"` WHERE `ID` = '%i'", i);
mysql_query(SQL, query);
mysql_store_result();
if(mysql_num_rows() == 0) break;
else if(mysql_num_rows() != 0)
{
mysql_fetch_row_format(query);
sscanf(query, "e<p<|>is[25]iiiiiffffff>", HouseInfo[i]);
new lString[256];
switch(HouseInfo[i][Owned])
{
case 0:
{
format(lString, sizeof(lString), "House Owned: No\nHouse Owner: None\nHouse Price: $%i", HouseInfo[i][Price]);
HouseInfo[i][Label] = CreateDynamic3DTextLabel(lString, -1, HouseInfo[i][OX], HouseInfo[i][OY], HouseInfo[i][OZ]+0.5, 20.0);
HouseInfo[i][Icon] = CreateDynamicMapIcon(HouseInfo[i][OX], HouseInfo[i][OY], HouseInfo[i][OZ], 31, -1);
HouseInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, HouseInfo[i][OX], HouseInfo[i][OY], HouseInfo[i][OZ], -1, -1, -1, 20.0);
HouseInfo[i][ExitPickup] = CreateDynamicPickup(1273, 23, HouseInfo[i][IX], HouseInfo[i][IY], HouseInfo[i][IZ], -1, -1, -1, 20.0);
}
case 1:
{
format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", HouseInfo[i][Owner], HouseInfo[i][Price], (HouseInfo[i][Locked] == 1) ? ("Yes") : ("No"));
HouseInfo[i][Label] = CreateDynamic3DTextLabel(lString, -1, HouseInfo[i][OX], HouseInfo[i][OY], HouseInfo[i][OZ]+0.5, 20.0);
HouseInfo[i][Icon] = CreateDynamicMapIcon(HouseInfo[i][OX], HouseInfo[i][OY], HouseInfo[i][OZ], 32, -1);
HouseInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, HouseInfo[i][OX],HouseInfo[i][OY], HouseInfo[i][OZ], -1, -1, -1, 20.0);
HouseInfo[i][ExitPickup] = CreateDynamicPickup(1273, 23, HouseInfo[i][IX], HouseInfo[i][IY], HouseInfo[i][IZ], -1, -1, -1, 20.0);
}
}
CreatedHouses++;
}
}
mysql_free_result();
printf("[House System] %i houses were retrieved..", CreatedHouses);
return 1;
}
//==============================================================================
forward SetHouseExit(playerid, houseid);
public SetHouseExit(playerid, houseid)
{
switch(HouseInfo[houseid][InteriorID])
{
case 1:
{
HouseInfo[houseid][IX] = 2466.5610;
HouseInfo[houseid][IY] = -1698.3323;
HouseInfo[houseid][IZ] = 1013.5078;
HouseInfo[houseid][ExitPickup] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][IX], HouseInfo[houseid][IY], HouseInfo[houseid][IZ], -1, -1, -1, 20.0);
mysql_format(SQL, query, sizeof(query),"UPDATE `"Houses_Table"` SET `IX` = '%f', `IY` = '%f', `IZ` = '%f' WHERE `ID` = '%i'", HouseInfo[houseid][IX], HouseInfo[houseid][IY], HouseInfo[houseid][IZ], houseid);
mysql_tquery(SQL, query, "", "");
}
case 2:
{
HouseInfo[houseid][IX] = 327.9615;
HouseInfo[houseid][IY] = 1478.2103;
HouseInfo[houseid][IZ] = 1084.4375;
HouseInfo[houseid][ExitPickup] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][IX], HouseInfo[houseid][IY], HouseInfo[houseid][IZ], -1, -1, -1, 20.0);
mysql_format(SQL, query, sizeof(query),"UPDATE `"Houses_Table"` SET `IX` = '%f', `IY` = '%f', `IZ` = '%f' WHERE `ID` = '%i'", HouseInfo[houseid][IX], HouseInfo[houseid][IY], HouseInfo[houseid][IZ], houseid);
mysql_tquery(SQL, query, "", "");
}
}
return 1;
}
forward PutPlayerInHouse(playerid, houseid);
public PutPlayerInHouse(playerid, houseid)
{
switch(HouseInfo[houseid][InteriorID])
{
case 1:
{
SetPlayerInterior(playerid, 2);
SetPlayerPos(playerid, 2465.2151, -1698.3086, 1013.5078);
SetPlayerVirtualWorld(playerid, HouseInfo[houseid][World]);
pInfo[playerid][CurrentHID] = houseid;
}
case 2:
{
SetPlayerInterior(playerid, 15);
SetPlayerPos(playerid, 328.6252, 1480.5461, 1084.4375);
SetPlayerVirtualWorld(playerid, HouseInfo[houseid][World]);
pInfo[playerid][CurrentHID] = houseid;
}
}
return 1;
}
forward KickFromHouse(playerid, houseid);
public KickFromHouse(playerid, houseid)
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, HouseInfo[houseid][OX]+0.5, HouseInfo[houseid][OY]+0.5, HouseInfo[houseid][OZ]);
SetPlayerVirtualWorld(playerid, 0);
pInfo[playerid][CurrentHID] = -1;
return 1;
}
My problem is only while when the filterscript start and the house doesnt load