02.05.2018, 21:37
• 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
• Credits
Includes creators.
Cleyson by total code creation
◘ Sorry my bad english. :*
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.36, 1049.02, 94.0010, 6},
{2259.38, -1135.89, 1050.64, 275.3992, 10},
{2282.99, -1140.28, 1050.89, 358.4660, 11},
{2233.69, -1115.26, 1050.88, 358.4660, 5},
{2218.39, -1076.21, 1050.48, 95.2635, 1},
{2496.00, -1692.08, 1014.74, 177.8159, 3},
{2365.25, -1135.58, 1050.88, 359.0367, 8},
{2317.77, -1026.76, 1050.21, 359.0367, 9},
{2324.41, -1149.54, 1050.71, 359.0367, 12},
{1260.6603, -785.4005, 1091.9063, 270.9891, 5},
{140.28, 1365.92, 1083.85, 9.6901, 5}
};
// 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 i = 0; i < MAX_HOUSE; ++i)
{
DestroyDynamicPickup(c[i][cPickup]);
DestroyDynamicMapIcon(c[i][cIcon]);
DestroyDynamic3DTextLabel(c[i][cText]);
}
return 1;
}
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, p[playerid][Name], 24);
LoadPlayer(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(p[playerid][HasHouse] > 0) SavePlayer(playerid);
return 1;
}
// ============= COMMANDS ADMIN
CMD:ahouse(playerid)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
new String_COMANDOS[220]; //
format(String_COMANDOS, sizeof 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(playerid, 9545, DIALOG_STYLE_MSGBOX, "Commands Admin C-HOUSE", String_COMANDOS, "Ok", "");
return 1;
}
CMD:createhouse(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
if(sscanf(params, "ii", params[0], params[1])) return SendClientMessage(playerid, CINZA, "Use /createhouse [price] [int 0a10]");
Create_House(playerid, TotalHouse+1, params[0], params[1]);
return 1;
}
CMD:gohouse(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
if(sscanf(params, "i", params[0])) return SendClientMessage(playerid, CINZA, "Use /gohouse [id]");
Go_House(playerid, params[0]);
return 1;
}
CMD:edithouse(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
if(sscanf(params, "iii", params[0], params[1], params[2])) return SendClientMessage(playerid, CINZA, "Use /edithouse [id] [price] [int 0a10]");
Edit_House(playerid, params[0], params[1], params[2]);
return 1;
}
CMD:deletehouse(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
if(sscanf(params, "i", params[0])) return SendClientMessage(playerid, CINZA, "Use /deletehouse [id]");
Delete_House(playerid, params[0]);
return 1;
}
// ================= COMMANDS PLAYERS
/*CMD:money(playerid)
{
GivePlayerMoney(playerid, 500000);
return 1;
}
*/
CMD:buyhouse(playerid)
{
for(new i = 0; i < MAX_HOUSE; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1, c[i][cX], c[i][cY], c[i][cZ]))
{
if(p[playerid][HasHouse] > 0) return SendClientMessage(playerid, RED, "You already own a house..");
if(c[i][cOccupied] == 1) return SendClientMessage(playerid, RED, "This house already owns.");
if(GetPlayerMoney(playerid) < c[i][cPrice]) return SendClientMessage(playerid, RED, "Insufficient moneye.");
format(c[i][cOwner], 24, p[playerid][Name]);
c[i][cOccupied] = 1;
p[playerid][HasHouse] = i;
SendClientMessage(playerid, ORANGE, "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(19522, 21, c[i][cX], c[i][cY], c[i][cZ]);//1272
format(texto, sizeof(texto), "{B22222}HOUSE ID: {FFFFFF}%d\n{CD5C5C}Owner: {FFFFFF}%s\n{CD5C5C}Price: {FFFFFF}$ %d{CD5C5C}\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
new Query[80];
format(Query, sizeof(Query), "UPDATE HOUSES SET OWNER ='%s', OCCUPIED = 1 WHERE ID =%d", c[i][cOwner], i);
db_query(Database, Query);
break;
}
}
return 1;
}
CMD:sellhouse(playerid)
{
for(new i = 0; i < MAX_HOUSE; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1, c[i][cX], c[i][cY], c[i][cZ]))
{
if(p[playerid][HasHouse] == 0) return SendClientMessage(playerid, RED, "You do not own a house.");
if(c[i][cOccupied] == 0) return SendClientMessage(playerid, RED, "This house does not have an owner.");
if(p[playerid][HasHouse] == i)
{
SendClientMessage(playerid, ORANGE, "House sold successfully.");
GivePlayerMoney(playerid, c[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(1273, 21, c[i][cX], c[i][cY], c[i][cZ]);
format(texto, sizeof(texto), "{2E8B57}HOUSE ID: {FFFFFF}%d\n{3CB371}Owner: {FFFFFF}%s\n{3CB371}Price: {FFFFFF}$ %d\n{3CB371}Press 'F' to enter\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
new Query[80];
format(Query, sizeof(Query), "UPDATE HOUSES SET OWNER ='%s', OCCUPIED = 0 WHERE ID =%d", c[i][cOwner], i);
db_query(Database, Query);
break;
} else {
SendClientMessage(playerid, RED, "This house is not yours.");
return 1;
}
}
}
return 1;
}
CMD:lock(playerid)
{
for(new i = 0; i < MAX_HOUSE; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1, c[i][cX], c[i][cY], c[i][cZ]))
{
if(p[playerid][HasHouse] == 0) return SendClientMessage(playerid, RED, "You do not own a house.");
if(c[i][cOccupied] == 0) return SendClientMessage(playerid, RED, "This house does not have an owner.");
if(p[playerid][HasHouse] == i)
{
new Query[80];
if(c[i][cLocked] == 0)
{
SendClientMessage(playerid, ORANGE, "Locked house.");
c[i][cLocked] = 1;
format(Query, sizeof(Query), "UPDATE HOUSES SET LOCKED = 1 WHERE ID =%d", i);
db_query(Database, Query);
break;
} else {
SendClientMessage(playerid, ORANGE, "Unlocked house.");
c[i][cLocked] = 0;
format(Query, sizeof(Query), "UPDATE HOUSES SET LOCKED = 0 WHERE ID =%d", i);
db_query(Database, Query);
break;
}
} else {
SendClientMessage(playerid, RED, "This house is not yours.");
return 1;
}
}
}
return 1;
}
CMD:helphouse(playerid)
{
ShowPlayerDialog(playerid, 9595, DIALOG_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(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_SECONDARY_ATTACK) // KEY F
{
for(new x = 0; x < MAX_HOUSE; x++)
{
if(IsPlayerInRangeOfPoint(playerid, 1, c[x][cX], c[x][cY], c[x][cZ]))
{
if(c[x][cOccupied] == 0)
{
SetPlayerPos(playerid, interior[c[x][cInt]][iX], interior[c[x][cInt]][iY], interior[c[x][cInt]][iZ]);
SetPlayerFacingAngle(playerid, interior[c[x][cInt]][iA]);
SetPlayerInterior(playerid, interior[c[x][cInt]][iID]);
p[playerid][EnterHouse] = x;
SendClientMessage(playerid, ORANGE, "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] == 1 && p[playerid][HasHouse] != x) return SendClientMessage(playerid, RED, "Locked house.");
if(p[playerid][HasHouse] == x)
{
SetPlayerPos(playerid, interior[c[x][cInt]][iX], interior[c[x][cInt]][iY], interior[c[x][cInt]][iZ]);
SetPlayerFacingAngle(playerid, interior[c[x][cInt]][iA]);
SetPlayerInterior(playerid, interior[c[x][cInt]][iID]);
p[playerid][EnterHouse] = x;
SendClientMessage(playerid, ORANGE, "Welcome to your home. Use 'N' to exit.");
break;
} else {
SendClientMessage(playerid, RED, "This house is not yours.");
return 1;
}
}
}
}
}
if(newkeys == 131072) // KEY N
{
if(p[playerid][EnterHouse] > 0)
{
SetPlayerPos(playerid, c[p[playerid][EnterHouse]][cX], c[p[playerid][EnterHouse]][cY], c[p[playerid][EnterHouse]][cZ]);
SetPlayerInterior(playerid, 0);
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(Query, sizeof(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(Database, Query);
format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS OWNERS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NOME TEXT DEFAULT '', CASAID INTEGER DEFAULT 0)");
db_query(Database, Query);
return 1;
}
LoadPlayer(playerid)
{
new DBResult:Result, Query[65];
format(Query, sizeof(Query), "SELECT * FROM OWNERS WHERE NOME = '%s'", p[playerid][Name]);
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
p[playerid][HasHouse] = db_get_field_assoc_int(Result, "CASAID");
} else {
new Query2[75];
format(Query2, sizeof(Query2), "INSERT INTO OWNERS (NOME, CASAID) VALUES ('%s', 0)", p[playerid][Name]);
db_query(Database, Query2);
p[playerid][HasHouse] = 0;
}
db_free_result(Result);
return 1;
}
SavePlayer(playerid)
{
new Query[75];
format(Query, sizeof(Query), "UPDATE OWNERS SET CASAID =%d WHERE NOME ='%s'", p[playerid][HasHouse], p[playerid][Name]);
db_query(Database, Query);
return 1;
}
// ============== INIT
LoadHouse()
{
new DBResult:Result, Query[50];
for(new i = 0; i < MAX_HOUSE; i++)
{
format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", i);
Result = db_query(Database, Query);
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(1273, 21, c[i][cX], c[i][cY], c[i][cZ]);
format(texto, sizeof(texto), "{2E8B57}HOUSE ID: {FFFFFF}%d\n{3CB371}Owner: {FFFFFF}%s\n{3CB371}Price: {FFFFFF}$ %d\n{3CB371}Press 'F' to enter\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
}
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(19522, 21, c[i][cX], c[i][cY], c[i][cZ]);//1272
format(texto, sizeof(texto), "{B22222}HOUSE ID: {FFFFFF}%d\n{CD5C5C}Owner: {FFFFFF}%s\n{CD5C5C}Price: {FFFFFF}$ %d{CD5C5C}\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
}
return 1;
}
// ============== ADMIN
Create_House(playerid, id, preco, inte)
{
new DBResult:Result, Query[160];
format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
SendClientMessage(playerid, RED, "Error.");
} else {
new Float:Pos[3];
GetPlayerPos(playerid, Pos[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(playerid, ORANGE, "House created successfully.");
CreateHouse(id);
format(Query, sizeof(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(Database, Query);
TotalHouse ++;
}
db_free_result(Result);
return 1;
}
Edit_House(playerid, id, preco, interi)
{
new DBResult:Result, Query[50];
format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
new string[60];
format(string, sizeof(string), "You have successfully edited the house id %d", id);
SendClientMessage(playerid, ORANGE, string);
c[id][cPrice] = preco;
c[id][cInt] = interi;
DestroyDynamicPickup(c[id][cPickup]);
DestroyDynamicMapIcon(c[id][cIcon]);
DestroyDynamic3DTextLabel(c[id][cText]);
CreateHouse(id);
} else {
SendClientMessage(playerid, RED, "Error.");
}
db_free_result(Result);
return 1;
}
Go_House(playerid, id)
{
new DBResult:Result, Query[50];
format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
new string[60];
format(string, sizeof(string), "You went home id %d.", id);
SendClientMessage(playerid, ORANGE, string);
SetPlayerPos(playerid, c[id][cX], c[id][cY], c[id][cZ]);
SetPlayerInterior(playerid, 0);
} else {
SendClientMessage(playerid, RED, "Error.");
}
db_free_result(Result);
return 1;
}
Delete_House(playerid, id)
{
new DBResult:Result, Query[50];
format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
format(Query, sizeof(Query), "DELETE FROM HOUSES WHERE ID = %d", id);
db_query(Database, Query);
new string[60];
format(string, sizeof(string), "You have successfully deleted the house id %d", id);
SendClientMessage(playerid, ORANGE, string);
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(playerid, RED, "Error.");
}
db_free_result(Result);
return 1;
}
• Credits
Includes creators.
Cleyson by total code creation
◘ Sorry my bad english. :*