27.12.2015, 23:38
The house system has some bugs. Can someone help me fix the following: the dini doesn't create more than 1 created house, and "Owner = pName" is not being created, and "Owner" is not being created in the dini either, yet it doesn't give any errors.
Help would be really appreciated!
Help would be really appreciated!
PHP код:
#define MAX_HOUSES 1000
#define CreateHouseDialog 1500
#define HousePriceDialog 1501
#define HouseInteriorDialog 1502
#define SaveHouseDialog 1503
#define RemoveIDHouseDialog 1504
enum hInfo
{
hPrice,
hInterior,
hNumber,
hLocked,
hOwned,
hPick,
hIcon,
hWorld,
hOwner[MAX_PLAYER_NAME],
Text3D:hLabel,
Float:hX,
Float:hY,
Float:hZ,
}
new HouseInfo[MAX_HOUSES][hInfo];
new houseid, InHouse[MAX_PLAYERS][MAX_HOUSES];
new Float:hA[MAX_HOUSES][3];
CMD:chouse(playerid, params[])
{
ShowPlayerDialog(playerid, CreateHouseDialog, DIALOG_STYLE_MSGBOX, "House options", "Select your option.", "Create", "Remove");
return 1;
}
CMD:buyhouse(playerid, params[])
{
new string[128], pName[MAX_PLAYER_NAME], Float:X, Float:Y, Float:Z, World, Houses[75];
World = GetPlayerVirtualWorld(playerid);
GetPlayerPos(playerid, hA[houseid][0], hA[houseid][1], hA[houseid][2]);
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ])) return SendClientMessage(playerid, COLOR_RED, "Error: You have to be near a house!");
if(HouseInfo[i][hOwner] == 1) return SendClientMessage(playerid, COLOR_RED, "Error: You own this house already!");
if(HouseInfo[i][hOwned] == 1) return SendClientMessage(playerid, COLOR_RED, "Error: The house is already purchased!");
if(GetPlayerMoney(playerid) < HouseInfo[i][hPrice]) return SendClientMessage(playerid, COLOR_RED, "Error: You don't have enough money to purchase this house!");
DestroyPickup(HouseInfo[i][hPick]);
HouseInfo[i][hPick] = CreatePickup(1272, 1, hA[houseid][0], hA[houseid][1], hA[houseid][2], World);
HouseInfo[i][hIcon] = SetPlayerMapIcon(playerid, 33, X, Y, Z, 32, 0, 0);
format(string, sizeof string, "{15FF00}Owner: {FFFFFF}%s\n{FFEA00}Price: {FFFFFF}%i", pName, HouseInfo[i][hPrice]);
Update3DTextLabelText(HouseInfo[i][hLabel], COLOR_WHITE, string);
HouseInfo[i][hOwner] = pName;
HouseInfo[i][hOwned] = 1;
format(string, sizeof string, "Congratulations! You have purchased the house for $%i dollars. Enjoy your stay!", HouseInfo[i][hPrice]);
SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
GivePlayerMoney(playerid, -HouseInfo[i][hPrice]);
format(Houses, sizeof Houses, "Houses/%i.ini", i);
if(fexist(Houses))
{
dini_IntSet(Houses, "Owned", 1);
dini_Set(Houses, "Owner", pName);
}
}
return 1;
}
CMD:sellhouse(playerid, params[])
{
new string[128], pName[MAX_PLAYER_NAME], Float:X, Float:Y, Float:Z, World, Houses[75];
World = GetPlayerVirtualWorld(playerid);
//GetPlayerPos(playerid, X, Y, Z);
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
for(new i = 0; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]))
{
if(HouseInfo[i][hOwned] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: This house has to be purchased first!");
if(HouseInfo[i][hOwner] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: This house is not owned by you!");
DestroyPickup(HouseInfo[i][hPick]);
HouseInfo[i][hPick] = CreatePickup(1273, 1, hA[houseid][0], hA[houseid][1], hA[houseid][2], World);
HouseInfo[i][hIcon] = SetPlayerMapIcon(playerid, 35, X, Y, Z, 31, 0, 0);
format(string, sizeof string, "{FFEA00}Price: $%i\nType /Buyhouse to purchase this house!", HouseInfo[i][hPrice]);
Update3DTextLabelText(HouseInfo[i][hLabel], COLOR_WHITE, string);
HouseInfo[i][hOwned] = 0;
HouseInfo[i][hOwner] = 0;
format(string, sizeof string, "You have earned $%i dollars for selling your house!", HouseInfo[i][hPrice]);
SendClientMessage(playerid, COLOR_YELLOW, string);
GivePlayerMoney(playerid, HouseInfo[i][hPrice]);
{
dini_IntSet(Houses, "Owned", 0);
dini_IntSet(Houses, "Owner", 0);
}
}
else
{
if(HouseInfo[i][hOwner] == 1)
{
SendClientMessage(playerid, COLOR_RED, "Error: You must be near your house");
}
}
}
return 1;
}
CMD:enter(playerid, params[])
{
for(new i = 0; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]))
{
if(HouseInfo[i][hOwned] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: This house has to be purchased first!");
if(HouseInfo[i][hLocked] == 1) return SendClientMessage(playerid, COLOR_RED, "Error: This house is locked.");
if(HouseInfo[i][hNumber] == 1000)
{
SetPlayerPos(playerid, 243.9951,304.9418,999.1484);
SetPlayerFacingAngle(playerid, 267.0980);
SetCameraBehindPlayer(playerid);
SetPlayerInterior(playerid, 1);
}
if(HouseInfo[i][hNumber] == 2000)
{
SetPlayerPos(playerid, 2259.6702,-1135.8542,1050.6328);
SetPlayerFacingAngle(playerid, 267.3974);
SetCameraBehindPlayer(playerid);
SetPlayerInterior(playerid, 10);
}
if(HouseInfo[i][hNumber] == 3000)
{
SetPlayerPos(playerid, 2308.8254,-1212.8070,1049.0234);
SetPlayerFacingAngle(playerid, 359.8550);
SetCameraBehindPlayer(playerid);
SetPlayerInterior(playerid, 6);
}
if(HouseInfo[i][hNumber] == 4000)
{
SetPlayerPos(playerid, 260.7436,1237.5563,1084.2578);
SetPlayerFacingAngle(playerid, 1.6415);
SetCameraBehindPlayer(playerid);
SetPlayerInterior(playerid, 9);
}
if(HouseInfo[i][hNumber] == 5000)
{
SetPlayerPos(playerid, -42.5742,1405.6521,1084.4297);
SetPlayerFacingAngle(playerid, 359.1347);
SetCameraBehindPlayer(playerid);
SetPlayerInterior(playerid, 8);
}
}
InHouse[playerid][i] = 1;
SendClientMessage(playerid, COLOR_GREEN, "{FFA200}[House]: {FFFFFF}You have entered the house.");
}
return 1;
}
CMD:exit(playerid, params[])
{
for(new i = 0; i < MAX_HOUSES; i++)
{
if(InHouse[playerid][i] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You are not in a house!");
SetPlayerPos(playerid, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]);
InHouse[playerid][i] = 0;
}
SendClientMessage(playerid, COLOR_GREEN, "{FFA200}[House]: {FFFFFF}You have left the house.");
return 1;
}
CMD:lockhouse(playerid, params[])
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
for(new i = 0; i < MAX_HOUSES; i++)
{
if(HouseInfo[i][hOwner] == 1) return SendClientMessage(playerid, COLOR_RED, "Error: This house is not owned by you!");
if(HouseInfo[i][hLocked] == 1) return SendClientMessage(playerid, COLOR_RED, "Error: You have locked your house already!");
HouseInfo[i][hLocked] = 1;
}
SendClientMessage(playerid, COLOR_YELLOW, "{FFA200}[House]: {FFFFFF}You have locked your house.");
return 1;
}
CMD:unlockhouse(playerid, params[])
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(HouseInfo[i][hOwner] != 1) return SendClientMessage(playerid, COLOR_RED, "Error: This house is not owned by you!");
if(HouseInfo[i][hLocked] != 1) return SendClientMessage(playerid, COLOR_RED, "Error: Your house is unlocked already!");
HouseInfo[i][hLocked] = 0;
}
SendClientMessage(playerid, COLOR_YELLOW, "{FFA200}[House]: {FFFFFF}You have unlocked your house.");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
// HOUSE SYSTEM !!
if(dialogid == CreateHouseDialog)
{
if(response)
{
ShowPlayerDialog(playerid, HousePriceDialog, DIALOG_STYLE_INPUT, "House Price", "Enter the price of this house", "Continue", "Back");
}
else
{
ShowPlayerDialog(playerid, RemoveIDHouseDialog, DIALOG_STYLE_INPUT, "Remove House ID", "Enter the house ID to be removed", "Remove", "Back");
}
}
if(dialogid == HousePriceDialog)
{
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, HousePriceDialog, DIALOG_STYLE_INPUT, "House Price", "Enter the price of this house", "Continue", "Back");
SendClientMessage(playerid, COLOR_WHITE, "{FFA200}[House]: The entered price has been set as the house price.");
HouseInfo[houseid][hPrice] = strval(inputtext);
ShowPlayerDialog(playerid, HouseInteriorDialog, DIALOG_STYLE_LIST, "Interiors", "Interior 1\nInterior 2\nInterior 3\nInterior 4\nInterior 5", "Continue", "Back");
}
else
{
ShowPlayerDialog(playerid, CreateHouseDialog, DIALOG_STYLE_MSGBOX, "House options", "Select a option", "Create", "Remove");
}
}
if(dialogid == HouseInteriorDialog)
{
switch(listitem)
{
case 0:
{
new string[128];
format(string, sizeof string, "{288F88}House ID: {FF4D00}%i\n{33FF00}House Price: {FF4D00}%i\n{FF4D00}House Interior: {FF4D00}1", houseid, HouseInfo[houseid][hPrice]);
ShowPlayerDialog(playerid, SaveHouseDialog, DIALOG_STYLE_MSGBOX, "Save", string, "Save", "Back");
SendClientMessage(playerid, COLOR_ORANGE, "{FFA200}[House]: Interior has been set. (Interior 1)");
HouseInfo[houseid][hInterior] = 3;
HouseInfo[houseid][hNumber] = 1000;
}
case 1:
{
new string[128];
format(string, sizeof string, "{288F88}House ID: {FF4D00}%i\n{33FF00}House Price: {FF4D00}%i\n{FF4D00}House Interior: {FF4D00}2", houseid, HouseInfo[houseid][hPrice]);
ShowPlayerDialog(playerid, SaveHouseDialog, DIALOG_STYLE_MSGBOX, "Save", string, "Save", "Back");
SendClientMessage(playerid, COLOR_ORANGE, "{FFA200}[House]: Interior has been set. (Interior 2)");
HouseInfo[houseid][hInterior] = 3;
HouseInfo[houseid][hNumber] = 2000;
}
case 2:
{
new string[128];
format(string, sizeof string, "{288F88}House ID: {FF4D00}%i\n{33FF00}House Price: {FF4D00}%i\n{FF4D00}House Interior: {FF4D00}3", houseid, HouseInfo[houseid][hPrice]);
ShowPlayerDialog(playerid, SaveHouseDialog, DIALOG_STYLE_MSGBOX, "Save", string, "Save", "Back");
SendClientMessage(playerid, COLOR_ORANGE, "{FFA200}[House]: Interior has been set. (Interior 3)");
HouseInfo[houseid][hInterior] = 2;
HouseInfo[houseid][hNumber] = 3000;
}
case 3:
{
new string[128];
format(string, sizeof string, "{288F88}House ID: {FF4D00}%i\n{33FF00}House Price: {FF4D00}%i\n{FF4D00}House Interior: {FF4D00}4", houseid, HouseInfo[houseid][hPrice]);
ShowPlayerDialog(playerid, SaveHouseDialog, DIALOG_STYLE_MSGBOX, "Save", string, "Save", "Back");
SendClientMessage(playerid, COLOR_ORANGE, "{FFA200}[House]: Interior has been set. (Interior 4)");
HouseInfo[houseid][hInterior] = 2;
HouseInfo[houseid][hNumber] = 4000;
}
case 4:orm_insert_inline()
{
new string[128];
format(string, sizeof string, "{288F88}House ID: {FF4D00}%i\n{33FF00}House Price: {FF4D00}%i\n{FF4D00}House Interior: {FF4D00}5", houseid, HouseInfo[houseid][hPrice]);
ShowPlayerDialog(playerid, SaveHouseDialog, DIALOG_STYLE_MSGBOX, "Save", string, "Save", "Back");
SendClientMessage(playerid, COLOR_ORANGE, "{FFA200}[House]: Interior has been set. (Interior 5)");
HouseInfo[houseid][hInterior] = 5;
HouseInfo[houseid][hNumber] = 5000;
}
}
//else
//{
// ShowPlayerDialog(playerid, HousePriceDialog, DIALOG_STYLE_INPUT, "House Price", "Enter the price of this house", "Continue", "Back");
//}
}
if(dialogid == SaveHouseDialog)
{
if(response)
{
new string[128], pName[MAX_PLAYER_NAME], Float:X, Float:Y, Float:Z, World, Houses[75];
World = GetPlayerVirtualWorld(playerid);
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof string, "{FFA200}[House]: {288F88}House ID: {FF4D00}%i {FFFFFF} has been created.", houseid);
SendClientMessage(playerid, -1, string);
GetPlayerPos(playerid, X, Y, Z);
HouseInfo[houseid][hX] = X;
HouseInfo[houseid][hY] = Y;
HouseInfo[houseid][hZ] = Z;
HouseInfo[houseid][hPick] = CreatePickup(1273, 1, X, Y, Z, World);
HouseInfo[houseid][hIcon] = SetPlayerMapIcon(playerid, 34, X, Y, Z, 31, 0, 0);
format(string, sizeof string, "{FFA200}House ID: {FFFFFF}%i\n{FFA200}Price: {FFFFFF}%i\nType /Buyhouse to purchase this house!", houseid, HouseInfo[houseid][hPrice]);
HouseInfo[houseid][hLabel] = Create3DTextLabel(string, -1, X, Y, Z, 25, 0, 0);
format(Houses, sizeof Houses, "Houses/%i.ini");
if(!fexist(Houses))
{
dini_Create(Houses);
dini_IntSet(Houses, "Price", HouseInfo[houseid][hPrice]);
dini_IntSet(Houses, "Interior", HouseInfo[houseid][hInterior]);
dini_Int(Houses, "Owned");
dini_Int(Houses, "Owner");
dini_FloatSet(Houses, "Position X", X);
dini_FloatSet(Houses, "Position Y", Y);
dini_FloatSet(Houses, "Position Z", Z);
}
houseid++;
}
else
{
SendClientMessage(playerid, COLOR_RED, "Error: The house has been resetted.");
}
}
if(dialogid == RemoveIDHouseDialog)
{
if(response)
{
new hID, Houses[75], string[128];
hID = strval(inputtext);
format(Houses, sizeof Houses, "Houses/%i.ini", hID);
if(!fexist(Houses))
{
SendClientMessage(playerid, COLOR_RED, "Error: The specified house id is not recognized.");
}
else
{
HouseInfo[houseid][hPrice] = 0;
HouseInfo[hID][hLocked] = 0;
HouseInfo[hID][hOwned] = 0;
HouseInfo[hID][hOwner] = 0;
HouseInfo[hID][hX] = 0;
HouseInfo[hID][hY] = 0;
HouseInfo[hID][hZ] = 0;
DestroyPickup(HouseInfo[houseid][hPick]);
Update3DTextLabelText(HouseInfo[houseid][hLabel], COLOR_WHITE, "");
format(string, sizeof string, "{FFA200}[House]: {288F88}House ID: %i has been removed.", hID);
SendClientMessage(playerid, -1, string);
dini_Remove(Houses);
}
}
else
{
ShowPlayerDialog(playerid, CreateHouseDialog, DIALOG_STYLE_MSGBOX, "House options", "{FFFFFF}Please, select your option.", "Create", "Remove");
}
}