SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/10/2013, 09:20 PM   #1
Cerealguy
Huge Clucker
 
Cerealguy's Avatar
 
Join Date: Mar 2013
Posts: 292
Reputation: 8
Default House system , save house create

Hello friends, I have followed all the tutorial and everything is dynamic perfectly and I did, I did that instead of adding the houses was done manually with a command / createhouse, the problem is as I do so that when I create a store house either continue using sqlite or use data other than for y_ini house, help please

Code:
new DB:database, DBResult:queryresult, fquery[300];

#define MAX_HOUSES 300
#define MAX_HOUSES_PER_PLAYER 2 
#define databasename "housedb.db"

#define DEFAULT_HOUSE_NAME          "No-Title" // The default name when a house is created/sold
#define DEFAULT_HOUSE_NAME_OWNER    "No-Owner" // house title default

#define DIALOG_HOUSE_CONFIG         14750
#define DIALOG_CHANGE_HOUSE_TITLE   15750

//************************************************************//

enum hinfo
{
    owner[24],
    Hname[100],
    costprice,
    Float:EnterPos[3],
    Float:TelePos[3],
    interiors,
    Text3D:textid,
    checkpointidx[2]
};

new HouseInformation[MAX_HOUSES][hinfo];
new houseid = -1;
new InHouse[MAX_PLAYERS], InHouseCP[MAX_PLAYERS];

CMD:h(playerid, params[])
{
    if(isnull(params))
    {
		SendClientMessage(playerid,COLOR_YELLOW,"Usage:{FFFFFF} /h [BUY] [SELL]");
		return 1;
	}

	if(!strcmp(params, "buy", true))
	{
	    if(InHouseCP[playerid] == -1) return SendClientMessage(playerid, 0xFF0000, "You are not in any house checkpoints!");
	    if(HouseInformation[InHouseCP[playerid]][owner][0] != 0) return SendClientMessage(playerid, 0xFF0000, "This house has a owner");
	    if(GetPlayerMonez(playerid) < HouseInformation[InHouseCP[playerid]][costprice]) return SendClientMessage(playerid, 0xFF0000, "You don't have enough money!"); //Player has a lack of cash!
	    new PlayerName[24];
	    GetPlayerName(playerid, PlayerName, 24);
	    format(fquery, sizeof(fquery), "SELECT `houseowner` FROM `HOUSEINFO` WHERE `houseowner` = '%s'", PlayerName); //Formats the SELECT query
	    format(fquery, sizeof(fquery), "SELECT `houseowner` FROM `HOUSEINFO` WHERE `housename` = '%s'", DEFAULT_HOUSE_NAME); //Formats the SELECT query
	    queryresult = db_query(database, fquery); //Query result variable has been used to query the string above.
	    if(db_num_rows(queryresult) == MAX_HOUSES_PER_PLAYER) return SendClientMessage(playerid, 0xFF0000, "You already have the max amount of houses"); //If the player has the max houses
	    db_free_result(queryresult);
	    //This is the point where the player can buy the house
	    SetOwner(HouseInformation[InHouseCP[playerid]][Hname], PlayerName, Comma(HouseInformation[InHouseCP[playerid]][costprice]), InHouseCP[playerid]);
	    //SetOwner(HouseName[], ownername[], houseids)
	    SetPlayerPos(playerid, HouseInformation[InHouseCP[playerid]][TelePos][0], HouseInformation[InHouseCP[playerid]][TelePos][1], HouseInformation[InHouseCP[playerid]][TelePos][2]); //Sets players position where InHouseCP[playerid] = houseid.
	    SetPlayerInterior(playerid, HouseInformation[InHouseCP[playerid]][interiors]); //Sets players interior
	    SetPlayerVirtualWorld(playerid, 15500000 + InHouseCP[playerid]); //Sets the virtual world
	    GivePlayerMonez(playerid, - HouseInformation[InHouseCP[playerid]][costprice]);
	    GameTextForPlayer(playerid, "House ~r~Purchased!", 3000, 3); //Tells them they have purchased a house
    }
    
    if(!strcmp(params, "sell", true))
    {
	    if(InHouse[playerid] == -1) return SendClientMessage(playerid, 0xFF0000, "You have to be inside your house to sell it!");
	    new Pname[24];
	    GetPlayerName(playerid, Pname, 24);
	    if(strcmp(HouseInformation[InHouse[playerid]][owner], Pname) != 0) return SendClientMessage(playerid, 0xFF0000, "This is not your house!");
	    //This is the point where the player can sell the house
	    DeleteOwner(HouseInformation[InHouse[playerid]][Hname], InHouse[playerid]);
	    //DeleteOwner(HouseName[], houseids)
	    SetPlayerPos(playerid, HouseInformation[InHouse[playerid]][EnterPos][0], HouseInformation[InHouse[playerid]][EnterPos][1], HouseInformation[InHouse[playerid]][EnterPos][2]);
	    SetPlayerInterior(playerid, 0); //Sets the player back to interior 0 (Outside)
	    SetPlayerVirtualWorld(playerid, 0); //Sets the players Virtual world to 0.
     	GivePlayerMonez(playerid, HouseInformation[InHouseCP[playerid]][costprice]);
	    InHouseCP[playerid] = InHouse[playerid];
	    GameTextForPlayer(playerid, "House ~g~sold!", 3000, 3); //Tells them they have sold a house
    }
    return 1;
}

CMD:createhouse(playerid, params[])
{
	new Float:EnterX, Float:EnterY, Float:EnterZ;
	
	new price;
	
	if(sscanf(params,"d",price))
    {
		SendClientMessage(playerid,COLOR_YELLOW,"Usage:{FFFFFF} /createhouse [price]");
		return 1;
	}

	GetPlayerPos(playerid, EnterX, EnterY, EnterZ);
	
    format(HouseInformation[houseid][Hname], 100, "%s", DEFAULT_HOUSE_NAME);
    HouseInformation[houseid][costprice] = price;
    HouseInformation[houseid][EnterPos][0] = EnterX;
    HouseInformation[houseid][EnterPos][1] = EnterY;
    HouseInformation[houseid][EnterPos][2] = EnterZ;
    HouseInformation[houseid][TelePos][0] = 271.884979;
    HouseInformation[houseid][TelePos][1] = 306.631988;
    HouseInformation[houseid][TelePos][2] = 999.148437;
    HouseInformation[houseid][interiors] = 2;
    format(fquery, sizeof(fquery), "SELECT houseowner FROM HOUSEINFO WHERE housename = '%s'", DEFAULT_HOUSE_NAME); //Formats the SELECT query
    format(fquery, sizeof(fquery), "SELECT houseowner FROM HOUSEINFO WHERE houseprice = '%d'", price); //Formats the SELECT query
    queryresult = db_query(database, fquery); //Query result variable has been used to query the string above.
    if(db_num_rows(queryresult) != 0) db_get_field_assoc(queryresult, "houseowner", HouseInformation[houseid][owner], 24); //Fetches the field information  db_free_result(queryresult);
    HouseInformation[houseid][checkpointidx][0] = CreateDynamicCP(EnterX, EnterY, EnterZ, 1.0);
    //CreateDynamicCP(Float:x, Float:y, Float:z, Float:size);
    HouseInformation[houseid][checkpointidx][1] = CreateDynamicCP(271.884979, 306.631988, 999.148437, 1.0, 15500000+houseid, 2);
    //CreateDynamicCP(Float:x, Float:y, Float:z, Float:size, worldid, interiorid);
    if(!HouseInformation[houseid][owner][0]) format(fquery, sizeof(fquery), "House Name: %s \n House Owner: %s \n House Price: $%s", DEFAULT_HOUSE_NAME, DEFAULT_HOUSE_NAME_OWNER, Comma(HouseInformation[houseid][costprice]));
    HouseInformation[houseid][textid] = CreateDynamic3DTextLabel(fquery, 0xFFFFFF, EnterX, EnterY, EnterZ + 0.5, 15.0);
    //CreateDynamic3DTextLabel(const text[], color, Float:x, Float:y, Float:z, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, worldid = -1, interiorid = -1, playerid = -1, Float:distance = 100.0);
    houseid ++; //We go to the next free slot in our variable.
    return 1;
}

stock SetOwner(HouseName[], ownername[], price[], houseids)
{
    format(fquery, sizeof(fquery), "INSERT INTO `HOUSEINFO` (`housename`, `houseowner`, `houseprice`)  VALUES('%s', '%s', '%s')", HouseName, ownername, price);
    db_query(database, fquery); //Queries the SQLite database.
    format(HouseInformation[houseids][owner], 24, "%s", ownername);
    format(fquery, sizeof(fquery), "House Name: %s \n House Owner: %s \n House Price: $%s", HouseName, HouseInformation[houseids][owner], price);
    UpdateDynamic3DTextLabelText(HouseInformation[houseids][textid], 0xFFFFFF, fquery); //Updates the text label.
    return 1;
}

stock DeleteOwner(HouseName[], houseids)
{
    format(HouseInformation[houseids][owner], 24, "%s", "\0");
    format(fquery, sizeof(fquery), "DELETE FROM `HOUSEINFO` WHERE `housename` = '%s'", HouseName);
    db_query(database, fquery); //Queries the SQLite database.
    format(fquery, sizeof(fquery), "House Name: %s \n House Owner: %s \n House Price: $%s", HouseName, DEFAULT_HOUSE_NAME_OWNER, Comma(HouseInformation[houseids][costprice]));
    UpdateDynamic3DTextLabelText(HouseInformation[houseids][textid], 0xFFFFFF, fquery); //Updates the text label.
    return 1;
}

In OnGameModeInt

database = db_open(databasename);
    
    db_free_result(db_query(database, "CREATE TABLE IF NOT EXISTS `HOUSEINFO` (housename varchar(51), houseowner varchar(25), houseprice varchar(25))"));

sorry no speak much english

Last edited by Cerealguy; 28/10/2013 at 01:11 AM.
Cerealguy is offline   Reply With Quote
Old 27/10/2013, 11:34 PM   #2
park4bmx
High-roller
 
park4bmx's Avatar
 
Join Date: Dec 2009
Location: Samokov,Bulgaria
Posts: 2,532
Reputation: 236
Default Re: House system , save house create

Ask on the post, u need to provide code here
park4bmx 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
[FilterScript] Cali-Houses: Create a house anywhere, dynamic house creating! California Filterscripts 257 31/05/2018 02:23 AM
[FilterScript] [FS] v1.6e || Simple House System || 1 line = 1 house Antironix Filterscripts 1307 28/04/2016 01:22 PM
help me to create house system leingod Help Archive 1 18/03/2011 10:31 AM
What wrong with this load a save house system ihatetn931 Help Archive 18 13/08/2010 07:19 AM


All times are GMT. The time now is 10:40 PM.


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