[FilterScript] House System * C-HOUSE
#1

• Introduction

I created this Filterscript especially here for the SAMP forum.
To use the members and to encourage the use of SQLite rescue, and the Pawn.CMD plugin.
Among other reasons. Remembering that the code is released for use and editing while keeping the creator's credits.

There is not much to talk about FS.
It is like any other system of houses,
but updated optimized and using current releases.



• Commands

Administrator

/createhouse
/deletehouse
/edithouse
/gohouse

Players

/buyhouse
/sellhouse
/lock


• Imagens

Images are in Portuguese language. But the script is in English.
Album



• Script


PHP Code:
/*
    FilterScript House System C-HOUSE.
    Create by Cleyson Stein - StNN
    Do not withdraw credits.
    All rights reserved. 05/02/2018 *
    
*/
#include <a_samp>
#include <pawn.cmd>
#include <sscanf2>
#include <streamer>
enum
{
    
MAX_HOUSE 100// Max house
    
RED 0xFF000FFF,
    
CINZA 0xCECECEFF,
    
ORANGE 0xF97804FF,
};
enum pInfo
{
    
Name[24],
    
HasHouse,
    
EnterHouse,
};
new 
p[MAX_PLAYERS][pInfo];
enum cInfo
{
    
cOwner[24],
    
Float:cX,
    
Float:cY,
    
Float:cZ,
    
cOccupied,
    
cLocked,
    
cIcon,
    
cPickup,
    
cInt,
    
Text3D:cText,
    
cPrice
};
new 
c[MAX_HOUSE][cInfo], TotalHouse;
// interior houses
enum inter
{
    
Float:iX,
    
Float:iY,
    
Float:iZ,
    
Float:iA,
    
iID
}
new 
interior[][inter] =
{
    {
2196.84, -1204.361049.0294.00106},
    {
2259.38, -1135.891050.64275.399210},
    {
2282.99, -1140.281050.89358.466011},
    {
2233.69, -1115.261050.88358.46605},
    {
2218.39, -1076.211050.4895.26351},
    {
2496.00, -1692.081014.74177.81593},
    {
2365.25, -1135.581050.88359.03678},
    {
2317.77, -1026.761050.21359.03679},
    {
2324.41, -1149.541050.71359.036712},
    {
1260.6603, -785.40051091.9063270.98915},
    {
140.281365.921083.859.69015}
};
// sqlite
new DB:Database;
public 
OnFilterScriptInit()
{
    print(
"\n-------------------------------------");
    print(
"   System C-HOUSE successfully loaded.");
    print(
"    Created by Cleyson Stein - StNN.");
    print(
"    All rights reserved - 02/05/2018");
    print(
"-------------------------------------\n");
    
ConnectDB(); 
    
LoadHouse(); 
    
EnableStuntBonusForAll(0); 
    
DisableInteriorEnterExits();
    return 
1;    
}
public 
OnFilterScriptExit()
{
    
db_close(Database);
    for(new 
0MAX_HOUSE; ++i)
    {
        
DestroyDynamicPickup(c[i][cPickup]);
        
DestroyDynamicMapIcon(c[i][cIcon]);
        
DestroyDynamic3DTextLabel(c[i][cText]);
    }    
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
GetPlayerName(playeridp[playerid][Name], 24);
    
LoadPlayer(playerid);
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    if(
p[playerid][HasHouse] > 0SavePlayer(playerid);
    return 
1;
}
// ============= COMMANDS ADMIN
CMD:ahouse(playerid)
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridRED"Command restricted to administrators.");
    new 
String_COMANDOS[220]; //
    
format(String_COMANDOSsizeof String_COMANDOS"");
    
    
strcat(String_COMANDOS"{009900}ADMIN C-HOUSE\n\n"); 
    
strcat(String_COMANDOS"{CECECE}/createhouse {FFFFFF}- Create a house.\n");
    
strcat(String_COMANDOS"{CECECE}/edithouse {FFFFFF}- Edit  house.\n");
    
strcat(String_COMANDOS"{CECECE}/deletehouse {FFFFFF}- Delete house.\n");
    
strcat(String_COMANDOS"{CECECE}/gohouse {FFFFFF}- Go to house.\n");
    
ShowPlayerDialog(playerid9545DIALOG_STYLE_MSGBOX"Commands Admin C-HOUSE"String_COMANDOS"Ok""");
    return 
1;
}
CMD:createhouse(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridRED"Command restricted to administrators.");
    if(
sscanf(params"ii"params[0], params[1])) return SendClientMessage(playeridCINZA"Use /createhouse [price] [int 0a10]");
    
Create_House(playeridTotalHouse+1params[0], params[1]);
    return 
1;
}
CMD:gohouse(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridRED"Command restricted to administrators.");
    if(
sscanf(params"i"params[0])) return SendClientMessage(playeridCINZA"Use /gohouse [id]");
    
Go_House(playeridparams[0]);
    return 
1;
}
CMD:edithouse(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridRED"Command restricted to administrators.");
    if(
sscanf(params"iii"params[0], params[1], params[2])) return SendClientMessage(playeridCINZA"Use /edithouse [id] [price] [int 0a10]");
    
Edit_House(playeridparams[0], params[1], params[2]);
    return 
1;
}
CMD:deletehouse(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridRED"Command restricted to administrators.");
    if(
sscanf(params"i"params[0])) return SendClientMessage(playeridCINZA"Use /deletehouse [id]");
    
Delete_House(playeridparams[0]);
    return 
1;
}
// ================= COMMANDS PLAYERS
/*CMD:money(playerid)
{
    GivePlayerMoney(playerid, 500000);
    return 1;
}
*/
CMD:buyhouse(playerid)
{
    for(new 
0MAX_HOUSEi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid1c[i][cX], c[i][cY], c[i][cZ]))
        {
            if(
p[playerid][HasHouse] > 0) return SendClientMessage(playeridRED"You already own a house..");
            if(
c[i][cOccupied] == 1) return SendClientMessage(playeridRED"This house already owns.");
            if(
GetPlayerMoney(playerid) < c[i][cPrice]) return SendClientMessage(playeridRED"Insufficient moneye.");
            
format(c[i][cOwner], 24p[playerid][Name]);
            
c[i][cOccupied] = 1;
            
p[playerid][HasHouse] = i;
            
SendClientMessage(playeridORANGE"House successfully acquired.");
            
GivePlayerMoney(playerid, -c[i][cPrice]);
            
DestroyDynamicPickup(c[i][cPickup]);
            
DestroyDynamicMapIcon(c[i][cIcon]);
            
DestroyDynamic3DTextLabel(c[i][cText]);
            new 
texto[200];
            
c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 32, -1);
            
c[i][cPickup] = CreateDynamicPickup(1952221c[i][cX], c[i][cY], c[i][cZ]);//1272
            
            
format(textosizeof(texto), "{B22222}HOUSE ID: {FFFFFF}%d\n{CD5C5C}Owner: {FFFFFF}%s\n{CD5C5C}Price: {FFFFFF}$ %d{CD5C5C}\n/helphouse"ic[i][cOwner], c[i][cPrice]);
            
c[i][cText] = CreateDynamic3DTextLabel(texto0xFFFFFFAAc[i][cX], c[i][cY], c[i][cZ]+120);
            new 
Query[80];
            
format(Querysizeof(Query), "UPDATE HOUSES SET OWNER ='%s', OCCUPIED = 1 WHERE ID =%d"c[i][cOwner], i);
            
db_query(DatabaseQuery);
            break;
        }
    }
    return 
1;
}
CMD:sellhouse(playerid)
{
    for(new 
0MAX_HOUSEi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid1c[i][cX], c[i][cY], c[i][cZ]))
        {
            if(
p[playerid][HasHouse] == 0) return SendClientMessage(playeridRED"You do not own a house.");
            if(
c[i][cOccupied] == 0) return SendClientMessage(playeridRED"This house does not have an owner.");
            if(
p[playerid][HasHouse] == i)
            {
                
SendClientMessage(playeridORANGE"House sold successfully.");
                
GivePlayerMoney(playeridc[i][cPrice]/2);
                
format(c[i][cOwner], 24"None");
                
c[i][cOccupied] = 0;
                
p[playerid][HasHouse] = 0;
                
DestroyDynamicPickup(c[i][cPickup]);
                
DestroyDynamicMapIcon(c[i][cIcon]);
                
DestroyDynamic3DTextLabel(c[i][cText]);
                new 
texto[200];
                
c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 31, -1);
                
c[i][cPickup] = CreateDynamicPickup(127321c[i][cX], c[i][cY], c[i][cZ]);
                
format(textosizeof(texto), "{2E8B57}HOUSE ID: {FFFFFF}%d\n{3CB371}Owner: {FFFFFF}%s\n{3CB371}Price: {FFFFFF}$ %d\n{3CB371}Press 'F' to enter\n/helphouse"ic[i][cOwner], c[i][cPrice]);
                
c[i][cText] = CreateDynamic3DTextLabel(texto0xFFFFFFAAc[i][cX], c[i][cY], c[i][cZ]+120);
                new 
Query[80];
                
format(Querysizeof(Query), "UPDATE HOUSES SET OWNER ='%s', OCCUPIED = 0 WHERE ID =%d"c[i][cOwner], i);
                
db_query(DatabaseQuery);
                break;
                } else {
                
SendClientMessage(playeridRED"This house is not yours.");
                return 
1;
               }
        }
    }
    return 
1;
}
CMD:lock(playerid)
{
    for(new 
0MAX_HOUSEi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid1c[i][cX], c[i][cY], c[i][cZ]))
        {
            if(
p[playerid][HasHouse] == 0) return SendClientMessage(playeridRED"You do not own a house.");
            if(
c[i][cOccupied] == 0) return SendClientMessage(playeridRED"This house does not have an owner.");
            if(
p[playerid][HasHouse] == i)
            {
                new 
Query[80];
                if(
c[i][cLocked] == 0)
                {
                    
SendClientMessage(playeridORANGE"Locked house.");
                    
c[i][cLocked] = 1;
                    
                    
format(Querysizeof(Query), "UPDATE HOUSES SET LOCKED = 1 WHERE ID =%d"i);
                    
db_query(DatabaseQuery);
                    break;
                    
                    } else {
                    
                    
SendClientMessage(playeridORANGE"Unlocked house.");
                    
c[i][cLocked] = 0;
                    
                    
format(Querysizeof(Query), "UPDATE HOUSES SET LOCKED = 0 WHERE ID =%d"i);
                    
db_query(DatabaseQuery);
                    break;
                }
                } else {
                
SendClientMessage(playeridRED"This house is not yours.");
                return 
1;
               }
        }
    }
    return 
1;
}
CMD:helphouse(playerid)
{
    
ShowPlayerDialog(playerid9595DIALOG_STYLE_MSGBOX"Help C-House","{009900}HOUSES\n\n{CECECE}/buyhouse {FFFFFF}- Buy a house.\n{CECECE}/sellhouse {FFFFFF}- Sell ​​your house.\n{CECECE}/lock {FFFFFF}- lock | unlock house.\n""Ok""");
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
newkeys == KEY_SECONDARY_ATTACK// KEY F
    
{
        for(new 
0MAX_HOUSEx++)
        {
            if(
IsPlayerInRangeOfPoint(playerid1c[x][cX], c[x][cY], c[x][cZ]))
            {
                if(
c[x][cOccupied] == 0)
                {
                    
SetPlayerPos(playeridinterior[c[x][cInt]][iX], interior[c[x][cInt]][iY], interior[c[x][cInt]][iZ]);
                    
SetPlayerFacingAngle(playeridinterior[c[x][cInt]][iA]);
                    
SetPlayerInterior(playeridinterior[c[x][cInt]][iID]);
                    
p[playerid][EnterHouse] = x;
                    
                    
SendClientMessage(playeridORANGE"House for sale! To buy use /buyhouse in the pickup from outside. Use 'N' to exit.");
                    break;
                    
                }  
                if(
c[x][cOccupied] == 1)
                {
                    if(
c[x][cLocked] == && p[playerid][HasHouse] != x) return SendClientMessage(playeridRED"Locked house.");
                    
                    if(
p[playerid][HasHouse] == x)
                    {
                        
SetPlayerPos(playeridinterior[c[x][cInt]][iX], interior[c[x][cInt]][iY], interior[c[x][cInt]][iZ]);
                        
SetPlayerFacingAngle(playeridinterior[c[x][cInt]][iA]);
                        
SetPlayerInterior(playeridinterior[c[x][cInt]][iID]);
                        
p[playerid][EnterHouse] = x;
                        
                        
SendClientMessage(playeridORANGE"Welcome to your home. Use 'N' to exit.");
                        break;
                        
                        } else {
                        
SendClientMessage(playeridRED"This house is not yours.");
                        return 
1;
                    }
                }
            }
        }
    }
    if(
newkeys == 131072// KEY N
    
{
        if(
p[playerid][EnterHouse] > 0)
        {
            
SetPlayerPos(playeridc[p[playerid][EnterHouse]][cX], c[p[playerid][EnterHouse]][cY], c[p[playerid][EnterHouse]][cZ]);
            
SetPlayerInterior(playerid0);
            
p[playerid][EnterHouse] = 0;
        }
    }
    return 
1;
}
// ============== DATA
ConnectDB()
{
    if((
Database db_open("C-House.db")) == DB:0)
    {
        
SendRconCommand("exit");
        print(
"Failed to connect to SQlite DataBase"); // DEBUG
        
        
} else {
        
        print(
"Successfully Connected to DataBase SQlite."); // DEBUG
    
}
    
//criar a db esta em db.txt
    
new Query[280];
    
format(Querysizeof(Query), "CREATE TABLE IF NOT EXISTS HOUSES(ID INTEGER PRIMARY KEY AUTOINCREMENT,\
    OWNER TEXT DEFAULT '',\
    X FLOAT DEFAULT 0.0,\
    Y FLOAT DEFAULT 0.0,\
    Z FLOAT DEFAULT 0.0,\
    INTERIOR INTEGER DEFAULT 0,\
    LOCKED INTEGER DEFAULT 0,\
    OCCUPIED INTEGER DEFAULT 0,\
    PRICE INTEGER DEFAULT 0)"
);    
    
db_query(DatabaseQuery);
    
format(Querysizeof(Query), "CREATE TABLE IF NOT EXISTS OWNERS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NOME TEXT DEFAULT '', CASAID INTEGER DEFAULT 0)");    
    
db_query(DatabaseQuery);
    return 
1;
}
LoadPlayer(playerid)
{
    new 
DBResult:ResultQuery[65];
    
format(Querysizeof(Query), "SELECT * FROM OWNERS WHERE NOME = '%s'"p[playerid][Name]);
    
Result db_query(DatabaseQuery);
    if(
db_num_rows(Result))
    {
        
p[playerid][HasHouse] = db_get_field_assoc_int(Result"CASAID");
        } else {
        new 
Query2[75];
        
format(Query2sizeof(Query2), "INSERT INTO OWNERS (NOME, CASAID) VALUES ('%s', 0)"p[playerid][Name]);
        
db_query(DatabaseQuery2);
        
p[playerid][HasHouse] = 0;
    }
    
db_free_result(Result);
    return 
1;
}
SavePlayer(playerid)
{
    new 
Query[75];
    
format(Querysizeof(Query), "UPDATE OWNERS SET CASAID =%d WHERE NOME ='%s'"p[playerid][HasHouse], p[playerid][Name]);
    
db_query(DatabaseQuery); 
    return 
1;
}
// ============== INIT
LoadHouse()
{
    new 
DBResult:ResultQuery[50];
    for(new 
0MAX_HOUSEi++)
    {
        
format(Querysizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d"i);
        
Result db_query(DatabaseQuery);
        if(
db_num_rows(Result))
        {
            
db_get_field_assoc(Result"OWNER"c[i][cOwner], 24);
            
c[i][cX] = db_get_field_assoc_float(Result"X");
            
c[i][cY] = db_get_field_assoc_float(Result"Y");
            
c[i][cZ] = db_get_field_assoc_float(Result"Z");
            
c[i][cOccupied] = db_get_field_assoc_int(Result"OCCUPIED");
            
c[i][cPrice] = db_get_field_assoc_int(Result"PRICE");
            
c[i][cInt] = db_get_field_assoc_int(Result"INTERIOR");
            
c[i][cLocked] = db_get_field_assoc_int(Result"LOCKED");
            
TotalHouse ++;
            
CreateHouse(i);
        }
        
db_free_result(Result);
    }
    
printf("\nHouse loaded: %d"TotalHouse);
    return 
1;
}
CreateHouse(i)
{
    new 
texto[200];
    if(
c[i][cOccupied] == 0)
    {
        
c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 31, -1);
        
c[i][cPickup] = CreateDynamicPickup(127321c[i][cX], c[i][cY], c[i][cZ]);
        
format(textosizeof(texto), "{2E8B57}HOUSE ID: {FFFFFF}%d\n{3CB371}Owner: {FFFFFF}%s\n{3CB371}Price: {FFFFFF}$ %d\n{3CB371}Press 'F' to enter\n/helphouse"ic[i][cOwner], c[i][cPrice]);
        
c[i][cText] = CreateDynamic3DTextLabel(texto0xFFFFFFAAc[i][cX], c[i][cY], c[i][cZ]+120);
    }
    else if(
c[i][cOccupied] == 1)
    {
        
c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 32, -1);
        
c[i][cPickup] = CreateDynamicPickup(1952221c[i][cX], c[i][cY], c[i][cZ]);//1272
        
format(textosizeof(texto), "{B22222}HOUSE ID: {FFFFFF}%d\n{CD5C5C}Owner: {FFFFFF}%s\n{CD5C5C}Price: {FFFFFF}$ %d{CD5C5C}\n/helphouse"ic[i][cOwner], c[i][cPrice]);
        
c[i][cText] = CreateDynamic3DTextLabel(texto0xFFFFFFAAc[i][cX], c[i][cY], c[i][cZ]+120);
    }
    return 
1;
}
// ============== ADMIN
Create_House(playerididprecointe)
{
    new 
DBResult:ResultQuery[160];
    
format(Querysizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d"id);
    
Result db_query(DatabaseQuery);
    if(
db_num_rows(Result))
    {
        
SendClientMessage(playeridRED"Error.");
        } else {
        new 
Float:Pos[3];
        
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
        
format(c[id][cOwner], 24"None");
        
c[id][cX] = Pos[0];
        
c[id][cY] = Pos[1];
        
c[id][cZ] = Pos[2];
        
c[id][cOccupied] = 0;
        
c[id][cPrice] = preco;
        
c[id][cInt] = inte;
        
SendClientMessage(playeridORANGE"House created successfully.");
        
CreateHouse(id);
        
format(Querysizeof(Query), "INSERT INTO HOUSES(OWNER, X, Y, Z, PRICE, INTERIOR) VALUES ('%s', %f, %f, %f, %d, %d)"c[id][cOwner], c[id][cX], c[id][cY], c[id][cZ], c[id][cPrice], c[id][cInt]);
        
db_query(DatabaseQuery);
        
TotalHouse ++;
    }
    
db_free_result(Result);
    return 
1;
}
Edit_House(playerididprecointeri)
{
    new 
DBResult:ResultQuery[50];
    
format(Querysizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d"id);
    
Result db_query(DatabaseQuery);
    if(
db_num_rows(Result))
    {
        new 
string[60];
        
format(stringsizeof(string), "You have successfully edited the house id %d"id);
        
SendClientMessage(playeridORANGEstring);    
        
c[id][cPrice] = preco;
        
c[id][cInt] = interi;
        
DestroyDynamicPickup(c[id][cPickup]);
        
DestroyDynamicMapIcon(c[id][cIcon]);
        
DestroyDynamic3DTextLabel(c[id][cText]);
        
CreateHouse(id);
        } else {
        
SendClientMessage(playeridRED"Error.");
    }
    
db_free_result(Result);
    return 
1;
}
Go_House(playeridid)
{
    new 
DBResult:ResultQuery[50];
    
format(Querysizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d"id);
    
Result db_query(DatabaseQuery);
    if(
db_num_rows(Result))
    {
        new 
string[60];
        
format(stringsizeof(string), "You went home id %d."id);
        
SendClientMessage(playeridORANGEstring);    
        
SetPlayerPos(playeridc[id][cX], c[id][cY], c[id][cZ]);
        
SetPlayerInterior(playerid0);
        } else {
        
SendClientMessage(playeridRED"Error.");
    }
    
db_free_result(Result);
    return 
1;
}
Delete_House(playeridid)
{
    new 
DBResult:ResultQuery[50];
    
format(Querysizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d"id);
    
Result db_query(DatabaseQuery);
    if(
db_num_rows(Result))
    {
        
format(Querysizeof(Query), "DELETE FROM HOUSES WHERE ID = %d"id);
        
db_query(DatabaseQuery);
        new 
string[60];
        
format(stringsizeof(string), "You have successfully deleted the house id %d"id);
        
SendClientMessage(playeridORANGEstring);    
        
format(c[id][cOwner], 24"None");
        
c[id][cX] = -1;
        
c[id][cY] = -1;
        
c[id][cZ] = -1;
        
c[id][cOccupied] = -1;
        
c[id][cPrice] = -1;
        
c[id][cInt] = -1;
        
c[id][cLocked] = -1;
        
DestroyDynamicPickup(c[id][cPickup]);
        
DestroyDynamicMapIcon(c[id][cIcon]);
        
DestroyDynamic3DTextLabel(c[id][cText]);
        
TotalHouse --;
        } else {
        
SendClientMessage(playeridRED"Error.");
    }
    
db_free_result(Result);
    return 
1;


• Credits

Includes creators.
Cleyson by total code creation


◘ Sorry my bad english. :*
Reply
#2

Nice


+Rep
Reply
#3

can u give it in .amx?
Reply
#4

Quote:
Originally Posted by PrivateCZ
View Post
can u give it in .amx?
Not going to work. You have to compile it by yourself with the inc/plugins he stated.
Reply
#5

System very well done ...
Reply
#6

I can see it isn't using virtual worlds... їIt's not a problem?. I guess if Player 1 joins his own house and Player 2 also joins his own house and both houses has the same interior, they will meet at the same interior.

їAm I wrong?.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)