SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/01/2019, 04:30 PM   #1
ShadowMortar
Big Clucker
 
Join Date: Jul 2016
Posts: 60
Reputation: 5
Angry House system problem[Probably the mysql too]

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.
Code:
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;
}
Code:
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;
}
Code:
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].
ShadowMortar is online now   Reply With Quote
Old 11/01/2019, 04:32 PM   #2
Kevinas100
Little Clucker
 
Join Date: Oct 2015
Posts: 27
Reputation: 7
Default Re: House system problem[Probably the mysql too]

you made every field in database to null, edit them and unselect null
Kevinas100 is offline   Reply With Quote
Old 11/01/2019, 04:33 PM   #3
ShadowMortar
Big Clucker
 
Join Date: Jul 2016
Posts: 60
Reputation: 5
Default Re: House system problem[Probably the mysql too]

Quote:
Originally Posted by Kevinas100 View Post
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
ShadowMortar is online now   Reply With Quote
Old 11/01/2019, 04:36 PM   #4
Kevinas100
Little Clucker
 
Join Date: Oct 2015
Posts: 27
Reputation: 7
Default Re: House system problem[Probably the mysql too]

Quote:
Originally Posted by ShadowMortar View Post
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?
Kevinas100 is offline   Reply With Quote
Old 11/01/2019, 04:37 PM   #5
ShadowMortar
Big Clucker
 
Join Date: Jul 2016
Posts: 60
Reputation: 5
Default Re: House system problem[Probably the mysql too]

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.
ShadowMortar is online now   Reply With Quote
Old 11/01/2019, 04:39 PM   #6
ShadowMortar
Big Clucker
 
Join Date: Jul 2016
Posts: 60
Reputation: 5
Default Re: House system problem[Probably the mysql too]

https://gyazo.com/08e00be2cb3f3767dde34d382b9bc208
ShadowMortar is online now   Reply With Quote
Old 11/01/2019, 04:40 PM   #7
Kevinas100
Little Clucker
 
Join Date: Oct 2015
Posts: 27
Reputation: 7
Default Re: House system problem[Probably the mysql too]

select where as defined and make to NONE
Kevinas100 is offline   Reply With Quote
Old 11/01/2019, 04:43 PM   #8
ShadowMortar
Big Clucker
 
Join Date: Jul 2016
Posts: 60
Reputation: 5
Default Re: House system problem[Probably the mysql too]

Quote:
Originally Posted by Kevinas100 View Post
you made every field in database to null, edit them and unselect null
Quote:
Originally Posted by Kevinas100 View Post
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.
ShadowMortar is online now   Reply With Quote
Old 11/01/2019, 05:07 PM   #9
Kevinas100
Little Clucker
 
Join Date: Oct 2015
Posts: 27
Reputation: 7
Default Re: House system problem[Probably the mysql too]

Quote:
Originally Posted by ShadowMortar View Post
I already tried that, and then when I create a house, it says no default value for anything.
Then I have no idea
Kevinas100 is offline   Reply With Quote
Old 12/01/2019, 12:00 AM   #10
ConnorW
Big Clucker
 
ConnorW's Avatar
 
Join Date: Apr 2012
Location: Los Santos
Posts: 126
Reputation: 49
Default Re: House system problem[Probably the mysql too]

Quote:
Originally Posted by ShadowMortar View Post
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.
__________________
ConnorW is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql house system jeffery30162 Scripting Help 9 26/10/2014 05:07 AM
Gagi's House System's House cords problem Wahaj Scripting Help 2 03/07/2014 04:15 PM
Mysql House System BruLaX Scripting Help 0 08/08/2013 10:31 PM
House system - using Mysql Kindred Scripting Help 5 02/07/2012 11:47 PM
Mysql House System ihatetn931 Help Archive 0 13/08/2010 03:14 PM


All times are GMT. The time now is 08:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.