10.12.2015, 16:58
(
Последний раз редактировалось vassilis; 10.12.2015 в 19:35.
)
I tried everything but can't find a solution here is whole information of my house system.
How my system works.
1. /createhouse
2.A dialog with info is shown(Buttons : Ok,Cancel)
3: (If you press Ok)It tells you to Press n at the desired Exterior X,Y,Z
4.Then it tells you that it saves and press again n at Desired Interior X,Y,Z(i have some interiors already)
5.A dialog input style asks you to set virtualworld,then interiorid,then price
6.FINISHED(calls from script createhouse function)
7.Spawning pickup and textdraw
8./buyhouse
9.Asks you to put housename
10.Finished(calls buyhouse function)
BUT
1.You buyhouse doesn't update pickup
2.You createhouse 2 and when you try to buyhouse it says it is already bought
[b]Also before changing 1,2 things i noticed that i could buy correctly 2 houses but couldnt enter previous house but only the last one i buyed(for example if i buy 3 houses i can enter 3rd house but not other 2.)
PROBLEM NOTICED
It updates mysql house id 0 even if it doesnt exist because when i create a house it starts from HOUSE ID 1
CODE:
1.createhouse command(works correctly)
2.(On dialogresponse)(works correctly)[calls createhouse function inside]
3.createhouse function
4.buyhouse command
5.dialog asking housename(calls buyhouse function)
OTHER
1.Loadhouses ( i don't really think that's the problem since the loadhouses function is called after server restarting. The problem happens before i even restart the server
2.Gethouseid stock
3.REGISTERING HOUSEID
edit: UPLOADED HOUSE.TABLE IN PICTURE TO CHECK IF everything is wrong
How my system works.
1. /createhouse
2.A dialog with info is shown(Buttons : Ok,Cancel)
3: (If you press Ok)It tells you to Press n at the desired Exterior X,Y,Z
4.Then it tells you that it saves and press again n at Desired Interior X,Y,Z(i have some interiors already)
5.A dialog input style asks you to set virtualworld,then interiorid,then price
6.FINISHED(calls from script createhouse function)
7.Spawning pickup and textdraw
8./buyhouse
9.Asks you to put housename
10.Finished(calls buyhouse function)
BUT
1.You buyhouse doesn't update pickup
2.You createhouse 2 and when you try to buyhouse it says it is already bought
[b]Also before changing 1,2 things i noticed that i could buy correctly 2 houses but couldnt enter previous house but only the last one i buyed(for example if i buy 3 houses i can enter 3rd house but not other 2.)
PROBLEM NOTICED
It updates mysql house id 0 even if it doesnt exist because when i create a house it starts from HOUSE ID 1
CODE:
1.createhouse command(works correctly)
PHP код:
CMD:createhouse(playerid,params[])
{
if( pinfo[playerid][ Admin] < 5) return 0;
ShowPlayerDialog(playerid,DIALOG_CHOUSE1,DIALOG_STYLE_MSGBOX, "House Creator","Welcome to House Creator. From here you can create the houses you want by following 3 steps!\n"COL_RED"1."COL_WHITE"Choose Enter X,Y,Z\n"COL_RED"2."COL_WHITE"Choose Exit X.Y.Z\n"COL_RED"3."COL_WHITE"Set Virtual World, Interior and Price!","Continue","Cancel");
return 1;
}
PHP код:
case DIALOG_CHOUSE1:
{
if(!response)
{
SendClientMessage(playerid, COLOR_RED,"SERVER: You Choose not to create a house!");
}
else
{
SendClientMessage(playerid, -1," "COL_GREEN"HOUSE CREATOR"COL_WHITE": Choose enter X,Y,Z coordinates and press "COL_YELLOW"N"COL_WHITE" when you decide!");
hcreating[playerid] = 1;
}
}
case DIALOG_CHOUSE2:
{
if(response)
{
new string[240];
new hid;
if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid,DIALOG_CHOUSE2,DIALOG_STYLE_INPUT,"House Creator","ERROR : You must type an ID(Number)!","Select","");
format(string,sizeof(string),"You have choose EnterX: %f, EnterY: %f, EnterZ: %f\nExitX: %f, ExitY: %f, ExitZ: %f\nInteriorID: %d Please now Set house Virtual World",HouseInfo[hid][XEnt],HouseInfo[hid][YEnt],HouseInfo[hid][ZEnt],HouseInfo[hid][XExit],HouseInfo[hid][YExit],HouseInfo[hid][ZExit],inputtext);
ShowPlayerDialog(playerid, DIALOG_CHOUSE3,DIALOG_STYLE_INPUT,"House Creator", string,"Select","");
HouseInfo[hid][HInterior] = strval(inputtext);
}
}
case DIALOG_CHOUSE3:
{
if(response)
{
new string[240];
new hid;
if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid,DIALOG_CHOUSE2,DIALOG_STYLE_INPUT,"House Creator","ERROR : You must type an ID(Number)!","Select","");
format(string,sizeof(string),"You have choose EnterX: %f, EnterY: %f, EnterZ: %f\n ExitX: %f, ExitY: %f, ExitZ: %f\nInteriorID: %d Virtual World: %d\n Please now set a price for the house!",HouseInfo[hid][XEnt],HouseInfo[hid][YEnt],HouseInfo[hid][ZEnt],HouseInfo[hid][XExit],HouseInfo[hid][YExit],HouseInfo[hid][ZExit],HouseInfo[hid][HInterior],inputtext);
HouseInfo[hid][HVirtualWorld] = strval(inputtext);
ShowPlayerDialog(playerid, DIALOG_CHOUSE4,DIALOG_STYLE_INPUT,"House Creator", string,"Select","");
}
}
case DIALOG_CHOUSE4:
{
if(response)
{
new string[240];
new hid;
if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid,DIALOG_CHOUSE2,DIALOG_STYLE_INPUT,"House Creator","ERROR : You must type an ID(Number)!","Select","");
format(string,sizeof(string),"You have choose EnterX: %f, EnterY: %f, EnterZ: %f, ExitX: %f, ExitY: %f, ExitZ: %f, InteriorID: %d Virtual World: %d\n Price: %d. You have created the house!",HouseInfo[hid][XEnt],HouseInfo[hid][YEnt],HouseInfo[hid][ZEnt],HouseInfo[hid][XExit],HouseInfo[hid][YExit],HouseInfo[hid][ZExit],HouseInfo[hid][HInterior],HouseInfo[hid][HPrice],inputtext);
HouseInfo[hid][HPrice] = strval(inputtext);
ShowPlayerDialog(playerid, DIALOG_CHOUSE5,DIALOG_STYLE_MSGBOX,"House Creator", string,"End","");
}
}
case DIALOG_CHOUSE5:
{
if(response)
{
new hid;
CreateHouse(HouseInfo[hid][XEnt],HouseInfo[hid][YEnt],HouseInfo[hid][ZEnt],HouseInfo[hid][XExit],HouseInfo[hid][YExit],HouseInfo[hid][ZExit],HouseInfo[hid][HVirtualWorld],HouseInfo[hid][HInterior],HouseInfo[hid][HPrice]);
printf("ENTER X: %f Y: %f Z: %f EXIT X: %f Y: %f Z: %f vw: %d INTID: %d PRICE : %d",HouseInfo[hid][XEnt],HouseInfo[hid][YEnt],HouseInfo[hid][ZEnt],HouseInfo[hid][XExit],HouseInfo[hid][YExit],HouseInfo[hid][ZExit],HouseInfo[hid][HVirtualWorld],HouseInfo[hid][HInterior],HouseInfo[hid][HPrice]);
}
}
PHP код:
function CreateHouse(Float:Xen,Float:Yen,Float:Zen,Float:Xex,Float:Yex,Float:Zex,virtualworld,interiorid,price)
{
static hCount;
new hid = hCount; hCount += 1;
new string[100];
new query[350];
hid += 1;
HouseInfo[hid][XEnt] = Xen;
HouseInfo[hid][YEnt] = Yen;
HouseInfo[hid][ZEnt] = Zen;
HouseInfo[hid][XExit] = Xex;
HouseInfo[hid][YExit] = Yex;
HouseInfo[hid][ZExit] = Zex;
HouseInfo[hid][HVirtualWorld] = virtualworld;
HouseInfo[hid][HInterior] = interiorid;
HouseInfo[hid][HPrice] = price;
HouseInfo[hid][HOwned] = 0;
HouseInfo[hid][HLocked] = 0;
HouseInfo[hid][HOwnerID] = -1;
HouseInfo[hid][HPickup] = CreateDynamicPickup(HUNOWNED_PICKUP, 1, Xen, Yen, Zen,0,0,-1, 30.0);
format(string,sizeof(string),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",price);
HouseInfo[hid][H3D] = CreateDynamic3DTextLabel(string, COLOR_YELLOW, Xen, Yen, Zen, 40.0);
mysql_format(mysql,query,sizeof(query), "INSERT INTO `houses` (`Xent`, `Yent`, `Zent`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld`, `HInterior`, `HPrice`,\
`HOwned`, `HLocked`) VALUES (%f, %f, %f, %f, %f, %f, %d, %d, %d, 0, 0)", Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
mysql_tquery(mysql, query, "RegisterHouse","i",hid);
return 1;
}
PHP код:
CMD:buyhouse(playerid,params[])
{
new hid = GetHouseID(playerid);
new price = HouseInfo[hid][HPrice];
if(hid == INVALID_HOUSE_ID) return SendClientMessage(playerid, -1,""COL_RED"SERVER"COL_WHITE"Invalid House id!") ;
if(GetPlayerMoney(playerid) < price) return SendClientMessage(playerid, -1, ""COL_RED"SERVER"COL_WHITE": You don't have so much money to buy the house");
if(HouseInfo[hid][HOwned] == 1) return SendClientMessage(playerid,-1,""COL_RED"SERVER"COL_WHITE"You can't buy this house because it is already bought!");
if(HouseInfo[hid][HOwnerID] == pinfo[playerid][ID]) return SendClientMessage(playerid, -1, ""COL_RED"You can't buy your own house!");
//if(!IsPlayerNearHouse(playerid)) return SendClientMessage(playerid, -1, ""COL_RED"SERVER"COL_WHITE"You can't buy a house if you are not near it!");
ShowPlayerDialog(playerid,DIALOG_BUYHOUSE,DIALOG_STYLE_INPUT,"BUY A HOUSE",""COL_RED"You want to buy a house! Since you can afford it please insert HouseName you want!","OK","Cancel");
return 1;
}
PHP код:
case DIALOG_BUYHOUSE:
{
new hid = GetHouseID(playerid);
new query[200];
if(!response) return SendClientMessage(playerid, -1, ""COL_RED"SERVER"COL_WHITE": You decided not to buy a house. The house sale got cancelled!");
if(strlen(inputtext) > 30) return SendClientMessage(playerid, -1, ""COL_RED"SERVER"COL_WHITE"You must set a name less than 30 characters!");
mysql_format(mysql,query,sizeof(query),"UPDATE `houses` SET `HName` = '%e' WHERE `hID` = '%d'",inputtext,hid);
mysql_tquery(mysql,query,"i",hid);
format(HouseInfo[hid][HName],30,"%s",inputtext);
}
1.Loadhouses ( i don't really think that's the problem since the loadhouses function is called after server restarting. The problem happens before i even restart the server
PHP код:
LoadHouses()
{
new Cache:result,rows;
new label[250];
result = mysql_query(mysql, "SELECT * FROM `houses`");
if((rows = cache_num_rows()))
{
for(new i=0; i < rows; i++)
{
HouseInfo[i][hID] = cache_get_field_content_int(i, "hID");
HouseInfo[i][XEnt] = cache_get_field_content_float(i, "XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
HouseInfo[i][YEnt] = cache_get_field_content_float(i, "YEnt"); //Above
HouseInfo[i][ZEnt] = cache_get_field_content_float(i, "ZEnt");//Above
HouseInfo[i][XExit] = cache_get_field_content_float(i, "XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
HouseInfo[i][YExit] = cache_get_field_content_float(i, "YExit");//Above
HouseInfo[i][ZExit] = cache_get_field_content_float(i, "ZExit");//Above
HouseInfo[i][HVirtualWorld] = cache_get_field_content_int(i, "HVirtualWorld");
HouseInfo[i][HInterior] = cache_get_field_content_int(i, "HInterior");
HouseInfo[i][HPrice] = cache_get_field_content_int(i, "HPrice");
HouseInfo[i][HOwnerID] = cache_get_field_content_int(i, "HOwnerID");
HouseInfo[i][HOwned] = cache_get_field_content_int(i, "HOwned");
HouseInfo[i][HLocked] = cache_get_field_content_int(i, "HLocked");
cache_get_field_content(i, "HName", HouseInfo[i][HName], 1, MAX_HOUSE_NAME);
if(HouseInfo[i][HOwned] == 1)
{
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[i][HName]);
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
printf("HOUSE ID : %d Housename : %s FloatX:%f Float Y: %f FloatZ: %f",HouseInfo[i][hID],HouseInfo[i][HName],HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt]);
CreateDynamicPickup(HOWNED_PICKUP, 1, HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt]);
}
else if(HouseInfo[i][HOwned] == 0)
{
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",HouseInfo[i][HPrice]);
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
CreateDynamicPickup(HUNOWNED_PICKUP, 1, HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt]);
}
}
printf("Successfully Loaded All Houses! ( %d )",rows);
}
else
{
print("There are no houses to load!");
}
cache_delete(result);
}
PHP код:
function BuyHouse(playerid)
{
new houseid = GetHouseID(playerid); // houseid is a slot not real ID
if(houseid == INVALID_HOUSE_ID) print("ERROR: BuyHouse failed, trying to buy house ID 0!");
else{
new str[128];
HouseInfo[houseid][HOwned] = 1;
HouseInfo[houseid][HOwnerID] = pinfo[playerid][ID]; //when i call loadhouses function i have to use the same somehow so server will understand that ownerid = account id again got it?
GivePlayerMoney(GetPlayerMoney(playerid), -HouseInfo[houseid][HPrice]);
mysql_format(mysql,str,sizeof(str),"UPDATE `houses` SET `HOwnerID`= %d, `HOwned` = 1 WHERE `hID` = %d",pinfo[playerid][ID],HouseInfo[houseid][hID]); // HouseInfo[houseid][hID] its real houseid
mysql_query(mysql,str);
format(str,sizeof(str),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[houseid][HName]);
UpdateDynamic3DTextLabelText(HouseInfo[houseid][H3D],COLOR_YELLOW,str);
UpdateHousePickup(playerid);
}
return 1;
}
PHP код:
function RegisterHouse(houseid)
{
HouseInfo[houseid][hID] = cache_insert_id();
printf("House Registered ID : %d",HouseInfo[houseid][hID]);
return 1;
}