[FilterScript] iHouse - V2 | MySQL | ZCMD - [FIXED from v1]
#1

iHouse Ownership Sysem

Brand new 2014 ownership system for houses.
Changelog:
Код:
You can now /createhouse & /deletehouse
About this project:
Well I started this a few months ago and well, it was a total disaster. It wasn't doing anything except sitting on my desktop so I started the development again like literally 7 days ago. Anyway, I wanted to create my own project from scratch and give it some unique features and I believe that is what I have done with this script. Anyway, without further a due....... Please enjoy and don't forget to give me REP+ or a comment if you used this <3 As always much appreciated.

old version: https://sampforum.blast.hk/showthread.php?tid=483670

Features:
This script contains a bunch of new features that I have only just recently added and thought of.


Some features:
  • You can own a house
  • You can rent at a house
  • You can give your friend a key to the house (He can open & close)
  • You can set rent price
  • You can rent at a house
  • You can store / take cash from house as long as it's open
  • You can lock your house
Also, if you are an RCON administrator you can have full control of the house - this means you can do the following:
  • Set an owner with a simple command
  • Give someone a dupekey / set dupekey
  • Set rentprice
  • Sell the house
  • Set the houses amount of cash
  • Open / close the house with a command
  • Set the interior of the house with a command
Commands:

Код:
/ahouse
    interior > Set's the current position to the interior of the house.
   
    move > Set's the exterior of the house to your position

    sell > Sells the house you're outside of to the price spcified.

    rentprice > Sets the rentprice of the house you are outside of the specified criteria

    Housecash > Set's the house cash to specified amount. Outside house.

    dupekey > Set's the dupekey to the owner of the house you are outside of. To set to nobody type in "None"

    lock > If the house is locked it will be unlocked. If it's unlocked it will be locked.
Код:
/ihouse
	
	Buy > If you are outside a house and it's for sale, you will buy the house given that you have the amount of cash
	Sell > If you and outside a house and you own it, you can sell the house with the specified amount.
	rentprice > If you are outside the house and you are owner. You can set rentprice to spcirfied.
	Rentroom > If you are outside a house and it's rentable. Youw ill be rtenting at it now.
	lock > If your the owner of the house you are outside, if it's locked it will be unlocked. If it's unlocked it will be locked.
	locker > If you type in /ihouse locker take 5000 it will give you the amount and take away from the house cash.
	dupekey > Type in the ID of the person you with to give the dupekey to. /ihouse dupekey 1. He needs to be close to you.
pawn Код:
/*
/*
/*
 _ _ _ _ _ _ _ _   _ _ _       _ _ _   _ _ _ _ _ _ _ _ _   _ _           _ _
|               | |     |     |     | |                 | |   |         |   |
|_ _ _     _ _ _| |     |     |     | |    _ _ _ _ _    | |   |         |   |
      |   |       |     |     |     | |   |         |   | |   |         |   |
      |   |       |     |     |     | |   |         |   | |   |         |   |
      |   |       |     |_ _ _|     | |   |         |   | |   |         |   |
      |   |       |                 | |   |         |   | |   |         |   |
      |   |       |      _ _ _      | |   |         |   | |   |         |   |
      |   |       |     |     |     | |   |         |   | |   |         |   |
      |   |       |     |     |     | |   |         |   | |   |         |   |
 _ _ _|   |_ _ _  |     |     |     | |   | _ _ _ _ |   | |   |_ _ _ _ _|   |
|               | |     |     |     | |                 | |                 |
|_ _ _ _ _ _ _ _| |_ _ _|     |_ _ _| |_ _ _ _ _ _ _ _ _| |_ _ _ _ _ _ _ _ _|

By your man GiGi! (Brandon More)
*/


#include <a_samp>
#include <a_mysql>
#include <string>
#include <streamer>
#include <a_zones>
#include <zcmd>

#define mysql_host          "localhost" // MySQL host. Default set.
#define mysql_user          "root" // MySQL user. Default set
#define mysql_password      "" // Password. Default is set.
#define mysql_database      "Sicilia-RP" // MySQL Database. (Change)

#define MAX_HOUSES 200

#define ALTCOMMAND:%1->%2;                     \
            COMMAND:%1(playerid, params[])     \
                return cmd_%2(playerid, params);

#define HouseLoop(%1) for(new %1 = 0; %1 < MAX_HOUSES; %1++)

#undef MAX_PLAYERS
#define MAX_PLAYERS 50 // Please change this to the criteria of your server. Set to default.

#define MaxPriceAHouseCanBeSold 5000000 // Change this to what ever.

new RentedHouse[MAX_PLAYERS] = -1;

enum iHouse
{
    hID,
    Float:outX, // Exterior
    Float:outY, // Exterior
    Float:outZ, // Exterior
    Float:intX, // Interior
    Float:intY, // Interior
    Float:intZ, // Interior
    intVW, // Interior
    intINT,  // Interior
    Text3D:outLabel,  // House Exterior label
    owner[ 50 ],  // House owner - displays on Label
    sellprice, // If > than 0 it will be classed as on sale!
    closed,
    rentprice,
    dupekey,
    housecash,
    hActive,
}

new House[MAX_HOUSES][iHouse];

forward mysql_start();
public mysql_start()
{
    mysql_debug(1);
    if(mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password))
    {
        print("[MYSQL] Connection successful!");
    }
    else
    {
        print("[MYSQL] There was an error connecting to the MYSQL server");
    }
    return 1;
}

public OnFilterScriptInit()
{
    mysql_start();
    LoadHouse();
    return 1;
}

public OnFilterScriptExit()
{
    HouseLoop(h)
    {
        SaveHouses(h);
    }
    mysql_close();
    return 1;
}
/*
From other people....
*/

stock myStrcpy(dest[], src[])
{
    new i = 0;
    while ((dest[i] = src[i])) i++;
}

stock IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
                if (string[i] > '9' || string[i] < '0')
        {
            return 0;
        }
    }
    return 1;
}
/*
Finish
*/

main()
{
    print("\n---------------------------------------");
    print(" Player house System by your boy GiGi!");
    print("---------------------------------------\n");
}

stock CreateNewHouse(house, Float:posX, Float:posY, Float:posZ)
{
    new query[250];
    format(query,sizeof(query),"INSERT INTO `houseinfo` (hID) VALUES (%d);", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intX` = '0.0' WHERE `hID`=%d",house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intY` = '0.0' WHERE `hID`=%d",house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intZ` = '0.0' WHERE `hID`=%d", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `outX` = '%f' WHERE `hID`=%d", posX, house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `outY` = '%f' WHERE `hID`=%d", posY, house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `outZ` = '%f' WHERE `hID`=%d", posZ, house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intINT` = 0 WHERE `hID`=%d", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `owner` = 'None' WHERE `hID`=%d", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `dupekey` = 'None' WHERE `hID`=%d", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `sellprice` = '0' WHERE `hID`=%d", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `rentprice` = '0' WHERE `hID`=%d", house);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `housecash` = '0' WHERE `hID`=%d", house);
    mysql_query(query);
    ReloadHouse(house);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(RentedHouse[playerid] != -1)
    {
        new HouseToSpawn = RentedHouse[playerid];
        SetPlayerVirtualWorld(playerid, House[HouseToSpawn][intVW]);
        SetPlayerInterior(playerid, House[HouseToSpawn][intINT]);
        SetPlayerPos(playerid, House[HouseToSpawn][intX], House[HouseToSpawn][intY], House[HouseToSpawn][intZ]);
    }
    return 1;
}

stock HouseExitOrEnter(playerid)
{
    HouseLoop(h)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, House[h][intX], House[h][intY], House[h][intZ]))
        {
            new playerINT = GetPlayerInterior(playerid), playerVW = GetPlayerVirtualWorld(playerid);
            if(playerINT == House[h][intINT])
            {
                if(playerVW == House[h][intVW])
                {
                    SetPlayerInterior(playerid, 0);
                    SetPlayerVirtualWorld(playerid, 0);
                    SetPlayerPos(playerid, House[h][outX], House[h][outY], House[h][outZ]);
                }
            }
        }
        if(IsPlayerInRangeOfPoint(playerid, 2.0, House[h][outX], House[h][outY], House[h][outZ]))
        {
            new playerINT = GetPlayerInterior(playerid), playerVW = GetPlayerVirtualWorld(playerid);
            if(playerINT == 0)
            {
                if(playerVW == 0)
                {
                    if(House[h][closed] == 1) return GameTextForPlayer(playerid,"~r~Closed",3000,3);
                    SetPlayerInterior(playerid, House[h][intINT]);
                    SetPlayerVirtualWorld(playerid, House[h][intVW]);
                    SetPlayerPos(playerid, House[h][intX], House[h][intY], House[h][intZ]);
                }
            }
        }
    }
    return 1;
}

stock SaveHouses(h) // Saved every variable sepratly. - More simple.
{
    new query[750];
    format(query, sizeof(query), "UPDATE `houseinfo` SET `outX`='%f' WHERE `hID`=%d", House[h][outX], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `outY`='%f' WHERE `hID`=%d", House[h][outY], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `outZ`='%f' WHERE `hID`=%d", House[h][outZ], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intX`='%f' WHERE `hID`=%d", House[h][intX], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intY`='%f' WHERE `hID`=%d", House[h][intY], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intZ`='%f' WHERE `hID`=%d", House[h][intZ], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `intINT`='%d' WHERE `hID`=%d", House[h][intINT], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `owner`='%s' WHERE `hID`=%d", House[h][owner], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `sellprice`='%d' WHERE `hID`=%d", House[h][sellprice], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `dupekey`='%s' WHERE `hID`=%d", House[h][dupekey], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `housecash`='%d' WHERE `hID`=%d", House[h][housecash], h);
    mysql_query(query);
    format(query, sizeof(query), "UPDATE `houseinfo` SET `rentprice`='%d' WHERE `hID`=%d", House[h][rentprice], h);
    mysql_query(query);
    return 1;
}

stock UnusedHouse()
{
    new Found = -1;
    HouseLoop(h)
    {
        if(House[h][hActive] > 0)
        return h;
    }
    return Found;
}

stock LoadHouse()
{
    HouseLoop(h)
    {
        new query[250];
        format(query, sizeof(query),"SELECT * FROM `houseinfo` WHERE `hID`=%d", h);
        mysql_query(query);
        mysql_store_result();
        new rows = mysql_num_rows();
        if(rows >= 1)
        {
            ReloadHouse(h);
            House[h][hActive] = 1;
        }
        else
        {
            House[h][hActive] = 0;
        }
        mysql_free_result();
    }
}

stock ReloadHouse(i) //FAILED!
{
    DestroyDynamic3DTextLabel(House[i][outLabel]);

    new query[300], savingstring[50];
    format(query, sizeof(query), "SELECT * FROM `houseinfo` WHERE `hID`=%d", i);
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "hID");
        House[i][hID] = strval(savingstring);
// Coordinated shit
    //Exterior
        mysql_fetch_field_row(savingstring, "outX");
        House[i][outX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "outY");
        House[i][outY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "outZ");
        House[i][outZ] = floatstr(savingstring);
    //Interior
        mysql_fetch_field_row(savingstring, "intX");
        House[i][intX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "intY");
        House[i][intY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "intZ");
        House[i][intZ] = floatstr(savingstring);
// Coordinated shit
        mysql_fetch_field_row(savingstring, "intINT");
        House[i][intINT] = strval(savingstring);

        mysql_fetch_field_row(savingstring, "owner");
        myStrcpy(House[i][owner], savingstring);
        mysql_fetch_field_row(savingstring, "dupekey");
        myStrcpy(House[i][dupekey], savingstring);

        mysql_fetch_field_row(savingstring, "sellprice");
        House[i][sellprice] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "rentprice");
        House[i][rentprice] = strval(savingstring);

        mysql_fetch_field_row(savingstring, "housecash");
        House[i][housecash] = strval(savingstring);

        House[i][closed] = 1;
    }
    mysql_free_result();
    new avayable, string[250], tmps[100];
    if(House[i][sellprice] >= 1) { avayable = House[i][sellprice]; }
    else { avayable = 0; }
    new zone[60];
    GetZone(House[i][outX],House[i][outY],House[i][outZ], zone);
    format(tmps, 256, "{FF0000}[ {FFDAB9}%d, %s{FF0000}]\n{FFDAB9}Owner: {FF0000}%s", i, zone, House[i][owner]);
    format(string, sizeof(string), "\n{FFDAB9}For Sale: {FF0000}$%d", House[i][sellprice]);
    if(avayable) { strcat(tmps, string); }
    House[i][outLabel] = CreateDynamic3DTextLabel(tmps, -1, House[i][outX], House[i][outY], House[i][outZ]+0.3, 20.0);
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & 16 && !IsPlayerInAnyVehicle(playerid))
    {
        HouseExitOrEnter(playerid);
    }
    return 1;
}

// When a player performs a command
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(!success) return SendClientMessage(playerid, -1, "The command has not been found! Use /commands.");
    return 1;
}

COMMAND:ahouse(playerid, params[]) // For server admnistators
{
    new tmp[ 15 ], tmp2[ 15 ], tmp3[ 128 ], houseId = -1, query[250];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You cannot perform this command.");
    if(sscanf(params, "szz", tmp, tmp2, tmp3)) return SendClientMessage(playerid, -1, " /ahouse [ Move / Sell / Owner / Interior / Dupekey / Rentprice / housecash / lock ]");
//==============================================================================
    new playerINT = GetPlayerInterior(playerid);
    HouseLoop(h)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, House[h][outX], House[h][outY], House[h][outZ]))
        {
            houseId = h;
        }
    }
//==============================================================================
    if(!strcmp(tmp, "move", true, 4))
    {
        if(!strlen(tmp2) || !IsNumeric(tmp2) || strlen(tmp2) > 2) return SendClientMessage(playerid, -1, "move [HouseID]");
        new houseID = strval(tmp2);
        new Float:iX, Float:iY, Float:iZ;
        GetPlayerPos(playerid, iX, iY, iZ);
        format(query, sizeof(query), "UPDATE `houseinfo` SET `outX` = '%f', `outY` = '%f', `outZ` = '%f' WHERE `hID` = %d", iX, iY, iZ, houseID);
        mysql_query(query);
        House[houseID][outX] = iX;
        House[houseID][outY] = iY;
        House[houseID][outZ] = iZ;
        ReloadHouse(houseID);
    }
    else if(!strcmp(tmp, "sell", true, 4))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(!strlen(tmp2) || !IsNumeric(tmp2) || strlen(tmp2) > 9) return SendClientMessage(playerid, -1, "sell [amount]");
        format(query, sizeof(query), "UPDATE `houseinfo` SET `sellprice` = %d WHERE `hID` = %d", strval(tmp2), houseId);
        mysql_query(query);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "owner", true, 5))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(!strlen(tmp2) || IsNumeric(tmp2)) return SendClientMessage(playerid, -1, "owner [Who? (Fullnme, no ID's)]");
        format(query, sizeof(query), "UPDATE `houseinfo` SET `owner` = '%s' WHERE `hID` = %d", tmp2, houseId);
        mysql_query(query);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "dupekey", true, 7))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(!strlen(tmp2) || IsNumeric(tmp2)) return SendClientMessage(playerid, -1, "dupekey [Who? (Fullnme, no ID's)]");
        format(query, sizeof(query), "UPDATE `houseinfo` SET `dupekey` = '%s' WHERE `hID` = %d", tmp2, houseId);
        mysql_query(query);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "interior", true, 8))
    {
        if(!strlen(tmp2) || !IsNumeric(tmp2)) return SendClientMessage(playerid, -1, "interior [HouseID]");
        new ID = strval(tmp2);
        new Float:iX, Float:iY, Float:iZ;
        GetPlayerPos(playerid, iX, iY, iZ);
        format(query, sizeof(query), "UPDATE `houseinfo` SET `intX` = '%f', `intY` = '%f', `intZ` = '%f', `intINT` = %d WHERE `hID` = %d", iX, iY, iZ, playerINT, ID);
        mysql_query(query);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "rentprice", true, 9))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(!strlen(tmp2) || !IsNumeric(tmp2) || strlen(tmp2) > 9) return SendClientMessage(playerid, -1, "rentprice [amount]");
        format(query, sizeof(query), "UPDATE `houseinfo` SET `rentprice` = %d WHERE `hID` = %d", strval(tmp2), houseId);
        mysql_query(query);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "housecash", true, 9))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(!strlen(tmp2) || !IsNumeric(tmp2) || strlen(tmp2) > 9) return SendClientMessage(playerid, -1, "housecash [amount]");
        format(query, sizeof(query), "UPDATE `houseinfo` SET `housecash` = %d WHERE `hID` = %d", strval(tmp2), houseId);
        mysql_query(query);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "lock", true, 4))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(House[houseId][closed] == 1)
        {
            House[houseId][closed] = 0;
            GameTextForPlayer(playerid,"~g~Opened",3000,3);
            return 1;
        }
        else
        {
            House[houseId][closed] = 1;
            GameTextForPlayer(playerid,"~r~Closed",3000,3);
            return 1;
        }
    }
    else return SendClientMessage(playerid, -1, " /ahouse [ Move / Sell / Owner / Interior / Dupekey / Rentprice / housecash / lock ]");
    return 1;
}
COMMAND:ihouse(playerid, params[]) // For owners of house
{
    new tmp[ 15 ], tmp2[ 15 ], tmp3[ 128 ];
    if(sscanf(params, "szz", tmp, tmp2, tmp3)) return SendClientMessage(playerid, -1, " /ihouse [ Buy / Sell / Lock / Rentprice / Locker / Dupekey ]");
    new houseId = -1, query[250];
    HouseLoop(h)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, House[h][outX], House[h][outY], House[h][outZ]))
        {
            houseId = h;
        }
    }
    if(!strcmp(tmp, "buy", true, 3))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(House[houseId][sellprice] < 1) return GameTextForPlayer(playerid,"~r~Not for sale",3000,3);
        else
        {
            new PlayerCash = GetPlayerMoney(playerid);
            if(PlayerCash >= House[houseId][sellprice])
            {
                GivePlayerMoney(playerid, -House[houseId][sellprice]);
                GameTextForPlayer(playerid,"~g~Purchased",3000,3);
                new pname[50];
                GetPlayerName(playerid, pname, sizeof(pname));
                format(query, sizeof(query), "UPDATE `houseinfo` SET `owner` = '%s', `sellprice` = 0 WHERE `hID` = %d", pname, houseId);
                mysql_query(query);
                ReloadHouse(houseId);
            }
            else return GameTextForPlayer(playerid,"~r~You do not have enough money",3000,3);
        }
    }
    else if(!strcmp(tmp, "sell", true, 4))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return GameTextForPlayer(playerid,"~r~You don't own this house",3000,3);

        new MaxPrice = strval(tmp2);
        new warning[50];
        format(warning, sizeof(warning), "A house can only be sold for $%d, please change amount.", MaxPriceAHouseCanBeSold);
        if(MaxPrice < 0 || MaxPrice > MaxPriceAHouseCanBeSold) return SendClientMessage(playerid, -1, warning);
        format(query, sizeof(query),"UPDATE `houseinfo` SET `SellPrice` = %d WHERE `hID` = %d", MaxPrice, houseId);
        mysql_query(query);
        new iStr[50];
        format(iStr, sizeof(iStr), "~g~$%d", MaxPrice);
        GameTextForPlayer(playerid,iStr,3000,3);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "rentprice", true, 9))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return GameTextForPlayer(playerid,"~r~You don't own this house",3000,3);

        new Rent = strval(tmp2);
        format(query, sizeof(query),"UPDATE `houseinfo` SET `RentPrice` = %d WHERE `hID` = %d", Rent, houseId);
        mysql_query(query);

        new iStr[50];
        format(iStr, sizeof(iStr), "~g~$%d", Rent);
        GameTextForPlayer(playerid,iStr,3000,3);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "rentroom", true, 8))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        new Rent = House[houseId][rentprice], PlayerCash = GetPlayerMoney(playerid);
        if(Rent == 0) return GameTextForPlayer(playerid,"~r~UnRentable",3000,3);
        if(PlayerCash < Rent) return GameTextForPlayer(playerid,"~r~Not enough cash",3000,3);
        else
        {
            RentedHouse[playerid] = houseId;
            new iStr[50];
            format(iStr, sizeof(iStr), "~g~Renting at %d for $%d", houseId, Rent);
            GameTextForPlayer(playerid,iStr,3000,3);
            GivePlayerMoney(playerid, -Rent);
        }
    }
    else if(!strcmp(tmp, "locker", true, 6))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        if(House[houseId][closed] == 1)
        {
            GameTextForPlayer(playerid,"~g~Locker is closed",3000,3);
            return 1;
        }
        else
        {
            if(!strlen(tmp2) || IsNumeric(tmp2)) return SendClientMessage(playerid, -1, "locker [take / store]");
            else if(!strcmp(tmp2, "take", true, 4))
            {
                if(!strlen(tmp3) || !IsNumeric(tmp3) || strlen(tmp3) > 9) return SendClientMessage(playerid, -1, "take [amount]");
                new Amount = strval(tmp3);
                if(Amount > House[houseId][housecash]) return GameTextForPlayer(playerid,"~r~Not enough in house",3000,3);
                House[houseId][housecash] -= Amount;
                GivePlayerMoney(playerid, Amount);
                GameTextForPlayer(playerid,"~g~Taken cash",3000,3);
            }
            else if(!strcmp(tmp2, "store", true, 5))
            {

            }
            else return SendClientMessage(playerid, -1, "locker [take / store]");
        }
    }
    else if(!strcmp(tmp, "lock", true, 4))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return GameTextForPlayer(playerid,"~r~You don't own this house",3000,3);

        if(House[houseId][closed] == 1)
        {
            House[houseId][closed] = 0;
            GameTextForPlayer(playerid,"~g~Opened",3000,3);
            return 1;
        }
        else
        {
            House[houseId][closed] = 1;
            GameTextForPlayer(playerid,"~r~Closed",3000,3);
            return 1;
        }
    }
    else if(!strcmp(tmp, "dupekey", true, 7))
    {
        if(houseId < 0) return SendClientMessage(playerid, -1, "You arn't outside a house");
        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return GameTextForPlayer(playerid,"~r~You don't own this house",3000,3);
        else
        {
            if(!strlen(tmp2) || IsNumeric(tmp2)) return SendClientMessage(playerid, -1, "dupekey [take / set]");
            else if(!strcmp(tmp2, "take", true, 4))
            {
                GameTextForPlayer(playerid,"~g~Taken dupekey",3000,3);
                format(query, sizeof(query), "UPDATE `houseinfo` SET `dupekey` = 'None' WHERE `hID` = %d", houseId);
                mysql_query(query);
                ReloadHouse(houseId);
            }
            else if(!strcmp(tmp2, "set", true, 3))
            {
                if(!strlen(tmp3) || !IsNumeric(tmp3) || strlen(tmp3) > MAX_PLAYERS) return SendClientMessage(playerid, -1, "set [playerid]");
                new playerID = strval(tmp3);
                if(!IsPlayerConnected(playerID)) return GameTextForPlayer(playerid,"~r~Player isn't connected",3000,3);
                GetPlayerName(playerID, pname, sizeof(pname));
                format(query, sizeof(query), "UPDATE `houseinfo` SET `dupekey` = '%s' WHERE `hID` = %d", pname, houseId);
                mysql_query(query);
                ReloadHouse(houseId);
            }
            else return SendClientMessage(playerid, -1, "dupekey [take / set]");
        }
    }
    else return SendClientMessage(playerid, -1, " /ihouse [ Buy / Sell / Lock / Rentprice / Locker / Dupekey ]");
    return 1;
}
COMMAND:unrent(playerid, params[])
{
    if(RentedHouse[playerid] != -1)
    {
        GameTextForPlayer(playerid,"~r~Unrented",3000,3);
        RentedHouse[playerid] = -1;
    }
    else
    {
        GameTextForPlayer(playerid,"~r~You arn't renting",3000,3);
    }
    return 1;
}
COMMAND:createhouse(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You cannot use this");
    new Float:iX, Float:iY, Float:iZ;
    GetPlayerPos(playerid, iX, iY, iZ);
    new houseId = UnusedHouse();
    CreateNewHouse(houseId, iX, iY, iZ);
    return 1;
}
COMMAND:deletehouse(playerid)
{
    new query[50];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You cannot use this");
    HouseLoop(h)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, House[h][outX], House[h][outY], House[h][outZ]))
        {
            format(query,sizeof(query), "DELETE FROM `HouseInfo` WHERE `hID` = %d", h);
            mysql_query(query);
            House[h][hActive] = 0;
            ReloadHouse(h);
        }
    }
    return 1;
}
Please reply below if you find any bugs or anything I need to be aware of.

Below I have add a zipped file with all things inside (Includes, plugins, Compiled, Source Code & Database.)
Reply
#2

Nice
Reply
#3

Nice.
Reply
#4

Looking good and adding more features like burglar system, inventory, different interiors you can buy.
Reply
#5

Nice, good job. How do I create a house though?

Thanks!
Reply
#6

Updated the script. You can now /createhouse & /deletehouse.
Reply
#7

The hell! You are sending too many queries. Why not just a SINGLE query for everything instead of so many queries? Also, I don't know why people are stucked with older versions of MySQL, and very slow ass unthreaded queries.
Reply
#8

Quote:
Originally Posted by Brandon_More
Посмотреть сообщение
Updated the script. You can now /createhouse & /deletehouse.
Thanks!
Reply
#9

Nice.
Reply
#10

Quote:
Originally Posted by iZN
Посмотреть сообщение
The hell! You are sending too many queries. Why not just a SINGLE query for everything instead of so many queries? Also, I don't know why people are stucked with older versions of MySQL, and very slow ass unthreaded queries.
You got snubbed man , but your suggestion would be better for this script tho.
Reply
#11

Hmm... Cant create a house... It says "Command has not been found. Use /commands". Also it say that when I try to use /commands
Reply
#12

looks good.
Reply
#13

Quote:
Originally Posted by Brandon_More
Посмотреть сообщение
Updated the script. You can now /createhouse & /deletehouse.
this dont work i see nothing when i use the command
Reply
#14

Hi.
Nice work.

I would have done
PHP Code:
// But maybe I'm wrong
stock CreateNewHouse(Float:posXFloat:posYFloat:posZ)
{
    new 
query[250];
    
format (querysizeof(query), "INSERT INTO `houseinfo` (outX, outY, outZ) VALUES (%f, %f, %f);"posXposYposZ);
    
mysql_query(query);
    
ReloadHouse(mysql_insert_id());
    return 
1;  // And maybe return a new house id (taken from mysql_insert_id())

And set default values for other fields in MySQL (also set hID as AUTO_INCREMENT)


And
PHP Code:
stock SaveHouses(h// Saved every variable sepratly. - More simple.
{
    ...

is really simple, but if you have 200 houses, saving will take time for (200 * 12 = ) 2400 requests.

Try to format your string into one query. And I also used this:
PHP Code:
// to enum iHouse
{
  
// ...
  
bool:Touched,
  
// ...
}
// each time, when something changed in house data
iHouse[houseId][Touched] = true;
// and in SaveHouses():
{
  if (
House[h][Touched]) 
  {
    
mysql_query(...);
    
House[h][Touched] = false;
  }

Reply
#15

everything ok but ...
pawn Code:
..(326) : error 017: undefined symbol "GetZone"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase
Reply
#16

Very nice, but i can shortd this,
PHP Code:
 format(querysizeof(query), "UPDATE `houseinfo` SET `outX`='%f' WHERE `hID`=%d"House[h][outX], h);
    
mysql_query(query);
    
format(querysizeof(query), "UPDATE `houseinfo` SET `outY`='%f' WHERE `hID`=%d"House[h][outY], h);
    
mysql_query(query);
    
format(querysizeof(query), "UPDATE `houseinfo` SET `outZ`='%f' WHERE `hID`=%d"House[h][outZ], h);
    
mysql_query(query);
    
format(querysizeof(query), "UPDATE `houseinfo` SET `intX`='%f' WHERE `hID`=%d"House[h][intX], h);
    
mysql_query(query);
    
format(querysizeof(query), "UPDATE `houseinfo` SET `intY`='%f' WHERE `hID`=%d"House[h][intY], h);
    
mysql_query(query);
    
format(querysizeof(query), "UPDATE `houseinfo` SET `intZ`='%f' WHERE `hID`=%d"House[h][intZ], h);
    
mysql_query(query);
    
format(querysizeof(query), "UPDATE `houseinfo` SET `intINT`='%d' WHERE `hID`=%d"House[h][intINT], h);
    
mysql_query(query); 
with (,) Example,
PHP Code:
"UPDATE `houseinfo` SET `outX`='%f',`outY`='%f',outZ`='%f',  WHERE `hID`=%d'"House[h][outX], House[h][outY], House[h][outZ],
Overall, nice
Reply
#17


Please Help Me
Dont work /createhouse
Reply
#18

Simply nice
Reply
#19

Nice script, But i suggest you some updates.
1. Make it Threaded version of MySQL.
2. We can sell houses to players.
Reply
#20

anyone can help me to set up the house

enum iHouse
{
hID,
FloatutX, // Exterior
FloatutY, // Exterior
FloatutZ, // Exterior
Float:intX, // Interior
Float:intY, // Interior
Float:intZ, // Interior
intVW, // Interior
intINT, // Interior
Text3DutLabel, // House Exterior label
owner[ 50 ], // House owner - displays on Label
sellprice, // If > than 0 it will be classed as on sale!
closed,
rentprice,
dupekey,
housecash,
hActive,
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)