House system problem[Probably the mysql too]
#1

I have a house system problem, well, when I /createhouse in game, it creates but it's whether bugged in my script or mysql. If anybody could help me.
Код:
CMD:createhouse(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 4) return	SendClientMessage(playerid, COLOR_GREY, "Not authorized.");
	new type,level,price, Float:X, Float:Y, Float:Z; 
	GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
	if(sscanf(params, "iiii",type,level,price))
	{
		SendClientMessage(playerid, COLOR_GREY, "Usage: /createhouse [Type] [Level] [Price]");
		SendClientMessage(playerid, COLOR_GREY, "Available types: 0: Small House | 1: Medium House | 2: Big House | 3: Villa");
	    return 1;
	}
    SendClientMessage(playerid, COLOR_GREY, "Creating a house, please wait a second.");
    mysql_tquery(dbhandle, "SELECT u.Id + 1 AS FirstAvailableId FROM houses u LEFT JOIN houses u1 ON u1.Id = u.Id + 1 WHERE u1.Id IS NULL ORDER BY u.Id LIMIT 0, 1", "OnHouseFindNextAvaibleId", "iiii", playerid, type, price, level);
	return 1;
}
Код:
forward OnHouseFindNextAvaibleId(playerid, type, price, level);
public OnHouseFindNextAvaibleId(playerid, type, price, level) {
    new i = cache_get_field_content_int(0, "FirstAvailableId", dbhandle);
    /*if(i < 1) {
        SendClientMessage(playerid, COLOR_GREY, "An error has occured, please try again later.");
        return 1;
    }*/

    if(i >= MAX_HOUSES) {
    	new string[100];
    	format(string, sizeof(string)," Max limit of houses is: %d", MAX_HOUSES);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
    new string[256];
    format(string, sizeof(string), "INSERT INTO `houses` (`id`) VALUES ('%i')", i);
    mysql_tquery(dbhandle, string);

    if(type == 0) // Small house
	{
        HouseInfo[i][ExitX] = 223.0732;
    	HouseInfo[i][ExitY] = 1288.3668;
    	HouseInfo[i][ExitZ] = 1082.1406;
    	HouseInfo[i][Interior] = 1;
    	strmid(HouseInfo[i][Type],"Small House",0,strlen("Small House"),255);
    	HouseInfo[i][InteriorType] = 1;
	}
	else if(type == 1) // Middle house
	{
        HouseInfo[i][ExitX] = 2365.2822;
    	HouseInfo[i][ExitY] = -1134.5186;
    	HouseInfo[i][ExitZ] = 1050.8750;
    	HouseInfo[i][Interior] = 8;
    	strmid(HouseInfo[i][Type],"Medium House",0,strlen("Medium House"),255);
    	HouseInfo[i][InteriorType] = 2;
	}
	else if(type == 2) // Big house
	{
        HouseInfo[i][ExitX] = 2317.8977;
    	HouseInfo[i][ExitY] = -1025.7722;
    	HouseInfo[i][ExitZ] = 1050.2109;
    	HouseInfo[i][Interior] = 9;
    	strmid(HouseInfo[i][Type],"Big House",0,strlen("Big House"),255);
    	HouseInfo[i][InteriorType] = 3;
	}
	else if(type == 3) // Villa
	{
        HouseInfo[i][ExitX] = 140.2605;
    	HouseInfo[i][ExitY] = 1367.4221;
    	HouseInfo[i][ExitZ] = 1083.8615;
    	HouseInfo[i][Interior] = 5;
    	strmid(HouseInfo[i][Type],"Villa",0,strlen("Villa"),255);
    	HouseInfo[i][InteriorType] = 4;
	}
	new Float:PosX, Float:PosY, Float:PosZ;
	GetPlayerPos(playerid, PosX, PosY, PosZ);
	HouseInfo[i][Price] = price;
    HouseInfo[i][Level] = level;
    HouseInfo[i][EnterX] = PosX;
    HouseInfo[i][EnterY] = PosY;
    HouseInfo[i][EnterZ] = PosZ;
	HouseInfo[i][HouseFood] = 0;
    HouseInfo[i][CheckOwner] = 0;
    HouseInfo[i][Fridge] = 0;
    HouseInfo[i][Money] = 0;
    HouseInfo[i][Locked] = 1;
    HouseInfo[i][VirtualWorld] = i;
    HouseInfo[i][RingBell] = 0;
    HouseInfo[i][Weapon] = -1;
    HouseInfo[i][Ammo] = 0;
    HouseInfo[i][Rentable] = 0;
    HouseInfo[i][RentPrice] = 50;
    HouseInfo[i][Materials] = 0;
    HouseInfo[i][Drugs] = 0;
    HouseInfo[i][Clothes] = 0;
    strmid(HouseInfo[i][Owner],"Nobody",0,strlen("Nobody"),255);

    format(string,sizeof(string),"{50ff00}House for sale!\nHouse Type: {f2f2f2}%s\n{50ff00}Price: {f2f2f2}%d$\n{50ff00}Level: {f2f2f2}%d\n{50ff00}To buy a house, write /buyhouse.",HouseInfo[i][Type],HouseInfo[i][Price],HouseInfo[i][Level]);
    HouseLabel[i] = CreateDynamic3DTextLabel(string ,0x33CCFFAA, HouseInfo[i][EnterX], HouseInfo[i][EnterY], HouseInfo[i][EnterZ], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0);
    HousePickup[i] = CreateDynamicPickup(19522, 1, HouseInfo[i][EnterX], HouseInfo[i][EnterY], HouseInfo[i][EnterZ]);
    SaveHouse(i);
	format(string, sizeof(string), "House successfully created %d!", i); //conver
	SendClientMessage(playerid,COLOR_GREY, string);
    return 1;
}
Код:
stock SaveHouse(id)
{

    new HouseQuery[1024];
    format(HouseQuery, sizeof(HouseQuery), "UPDATE `houses` SET `ownername`='%s',`owner`='%i',`type`='%s',`enter_x`='%f',`enter_y`='%f',`enter_z`='%f',`exit_x`='%f',`exit_y`='%f',`exit_z`='%f',`inactivity`='%i',`level`='%i', `price`='%i',`money`='%i' WHERE id = '%i'",
       HouseInfo[id][Owner], HouseInfo[id][CheckOwner], HouseInfo[id][Type], HouseInfo[id][EnterX], HouseInfo[id][EnterY], HouseInfo[id][EnterZ], HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], HouseInfo[id][Inactivity],
       HouseInfo[id][Level], HouseInfo[id][Price], HouseInfo[id][Money], id);

    format(HouseQuery, sizeof(HouseQuery), "UPDATE `houses` SET `int`='%i',`closed`='%i',`world`='%i',`weapon`='%i',`ammo`='%i',`rent`='%i',`rentprice`='%i',`bell`='%i',`heal`='%i',`mats`='%i',`drugs`='%i',`cloth`='%i',`inttype`='%i',`food`='%i' WHERE id = '%i'",
        HouseQuery, HouseInfo[id][Interior], HouseInfo[id][Locked], HouseInfo[id][VirtualWorld], HouseInfo[id][Weapon], HouseInfo[id][Ammo], HouseInfo[id][Rentable], HouseInfo[id][RentPrice], HouseInfo[id][RingBell], HouseInfo[id][Fridge],
        HouseInfo[id][Materials], HouseInfo[id][Drugs], HouseInfo[id][Clothes], HouseInfo[id][InteriorType], HouseInfo[id][HouseFood], id);
 	return 1;
}
https://gyazo.com/31a233047258fccdf48b560cca4838f1
This is how it looks like:
https://gyazo.com/93ea2400634583022fe059d7ddded2ba
EDIT:
After I /createhouse it saves only 1 house like that, which is bugged. And after I /createhouse again, it creates a house with the same ID[Id 6 in this case].
Reply
#2

you made every field in database to null, edit them and unselect null
Reply
#3

Quote:
Originally Posted by Kevinas100
Посмотреть сообщение
you made every field in database to null, edit them and unselect null
When I do that, it's like:
[ERROR] CMySQLQuery::Execute[] - (error #1364) Field 'ownername' doesn't have a default value
Reply
#4

Quote:
Originally Posted by ShadowMortar
Посмотреть сообщение
When I do that, it's like:
[ERROR] CMySQLQuery::Execute[] - (error #1364) Field 'ownername' doesn't have a default value
can you post a screen of one of your fields structure?
Reply
#5

Whatever default value I put, it will be inserted in mysql. If I put default value "9999" for EnterX, it'll be 9999. And check my code, anybody who can help me, please.
Reply
#6

https://gyazo.com/08e00be2cb3f3767dde34d382b9bc208
Reply
#7

select where as defined and make to NONE
Reply
#8

Quote:
Originally Posted by Kevinas100
Посмотреть сообщение
you made every field in database to null, edit them and unselect null
Quote:
Originally Posted by Kevinas100
Посмотреть сообщение
select where as defined and make to NONE
I already tried that, and then when I create a house, it says no default value for anything.
Reply
#9

Quote:
Originally Posted by ShadowMortar
Посмотреть сообщение
I already tried that, and then when I create a house, it says no default value for anything.
Then I have no idea
Reply
#10

Quote:
Originally Posted by ShadowMortar
Посмотреть сообщение
When I do that, it's like:
[ERROR] CMySQLQuery::Execute[] - (error #1364) Field 'ownername' doesn't have a default value
This is SQL_MODE in your mysql.
Also you can use insert instead of selecting then inserting.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)