Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* __ __
- /\ \/\ \
- ____\ \ \_\ \ ___ __ __ ____ __
- /',__\\ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
- /\__, `\\ \ \ \ \/\ \ \ \ \ \_\ \/\__, `\/\ __/
- \/\____/ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
- \/___/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
- */
- /*
- ============[ChangeLog]==========//
- 8/01/2011 [1.0.0] - Initial Release
- 9/01/2011 [1.0.1] - Fixed 3D Text Labels
- - Fixed bugged when you destroy a house
- - Added 3 more interiors
- - Fixed a bug with Virtual worlds
- */
- //==========[Includes]==========//
- #include <a_samp>//by SA-MP Team
- #include <zcmd>//by Zeex
- #include <sscanf2>//by Y_Less
- #include <mysql>//by StrickenKid
- #include <seif_text>//by Seif
- #include <streamer>//by Incognito
- //==========[Database]==========//
- #define SQL_HOST "localhost"// Your MySQL Host
- #define SQL_USER "root"// Your MySQL username(usually root)
- #define SQL_PASS ""// Your MySQL Password
- #define SQL_DB "samp"// Your MySQL database (default samp)
- //==========[Shit]==========//
- #define function%0(%1) forward%0(%1); public%0(%1)
- #define MAX_HOUSES 50
- #define SCRIPT_VERSION "1.0.1"
- #define SCRIPT_AUTHOR "Souvlaki"
- //-------------------------------------------------------------------------------------//
- #define GREEN 0x007C00AA
- #define ORANGE 0xF68B00AA
- //-------------------------------------------------------------------------------------//
- new Text3D:HouseText[MAX_HOUSES];
- new sArray[5];
- //-------------------------------------------------------------------------------------//
- enum hInfo
- {
- hID,
- hOwned,
- hOwner[24],
- Float:hEntranceX,
- Float:hEntranceY,
- Float:hEntranceZ,
- Float:hExitX,
- Float:hExitY,
- Float:hExitZ,
- hInterior,
- hOpen,
- hPickup,
- hPrice
- };
- new HouseInfo[MAX_HOUSES][hInfo];
- //-------------------------------------------------------------------------------------//
- public OnFilterScriptInit()
- {
- print("--------------------------------------\n");
- print("sHouse version 1.0.1 Loaded");
- print("\n--------------------------------------");
- mysql_init(LOG_ALL, 1);
- mysql_connect(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
- LoadSHouses();
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- public OnFilterScriptExit()
- {
- print("--------------------------------------\n");
- print("sHouse version 1.0.1 Unloaded");
- print("\n--------------------------------------");
- for(new id; id < MAX_HOUSES; id++)
- {
- SaveSHouse(id);
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- public OnPlayerConnect(playerid)
- {
- DisplayTextForPlayer(playerid, "sHouse", 5, 3, 3);
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- function OnPlayerPickUpDynamicPickup(playerid, pickupid)
- {
- new string[128];
- for(new id = 0; id < sizeof(HouseInfo); id++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]))
- {
- if(HouseInfo[id][hOwned] == 0)
- {
- format(string,sizeof(string),"~r~Property~n~~w~For Sale~n~~y~~h~Price:~w~ %d",HouseInfo[id][hPrice]);
- DisplayTextForPlayer(playerid, string, 5, 3, 3);
- }
- else if(HouseInfo[id][hOwned] == 1)
- {
- format(string,sizeof(string),"~r~Property~n~~y~~h~Owner:~w~ %s",HouseInfo[id][hOwner], HouseInfo[id][hPrice]);
- DisplayTextForPlayer(playerid, string, 5, 3, 3);
- }
- }
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:enter(playerid, params[])
- {
- #pragma unused params
- for(new id = 0; id < sizeof(HouseInfo); id++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]))
- {
- if(HouseInfo[id][hOpen] == 0)
- {
- DisplayTextForPlayer(playerid,"~r~Locked",2, 1, 1);
- }
- else
- {
- SetPlayerPos(playerid, HouseInfo[id][hExitX], HouseInfo[id][hExitY], HouseInfo[id][hExitZ]);
- SetPlayerInterior(playerid, HouseInfo[id][hInterior]);
- SetPlayerVirtualWorld(playerid, id);
- }
- }
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:exit(playerid, params[])
- {
- #pragma unused params
- for(new id = 0; id < sizeof(HouseInfo); id++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 5.0, HouseInfo[id][hExitX], HouseInfo[id][hExitY], HouseInfo[id][hExitZ]))
- {
- SetPlayerPos(playerid, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
- SetPlayerInterior(playerid, 0);
- SetPlayerVirtualWorld(playerid, 0);
- }
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:createhouse(playerid, params[])
- {
- if(sscanf(params, "ii", sArray[0], sArray[1]))
- {
- SendClientMessage(playerid, GREEN, "[SYNTAX]: /createhouse [Price] [Interior (1-3)]");
- SendClientMessage(playerid, ORANGE, "[Interiors]: Large/2 story/3 bedrooms (1) | Medium/1 story/1 bedroom (2) | Small/1 story/1 bedroom (3)");
- SendClientMessage(playerid, ORANGE, "[Interiors]: VERY Large/2 story/4 bedrooms (4) | Small/1 story/2 bedrooms (5) | Small/1 story/2 bedrooms (6)");
- return 1;
- }
- if(IsPlayerAdmin(playerid))
- {
- if(sArray[1] > 3 && sArray[1] < 1) return SendClientMessage(playerid, ORANGE, "[Interiors]: House Large 1 (1) | House Medium (2) | House Small (3)");
- new Float:PlayerPos[3];
- GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
- CreateSHouse(PlayerPos[0], PlayerPos[1], PlayerPos[2], sArray[0], sArray[1]);
- }
- else
- {
- SendClientMessage(playerid, ORANGE, "[ERROR]: You ain't no RCON admin, you piece of shit motherfucker.");
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:movehouse(playerid, params[])
- {
- if(sscanf(params, "i", sArray[0])) return SendClientMessage(playerid, GREEN, "[SYNTAX]: /movehouse [HouseID]");
- if(IsPlayerAdmin(playerid))
- {
- new Float:PlayerPos[3];
- GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
- Delete3DTextLabel(HouseText[sArray[0]]);
- DestroyDynamicPickup(HouseInfo[sArray[0]][hPickup]);
- HouseInfo[sArray[0]][hEntranceX] = PlayerPos[0];
- HouseInfo[sArray[0]][hEntranceY] = PlayerPos[1];
- HouseInfo[sArray[0]][hEntranceZ] = PlayerPos[2];
- SaveSHouse(sArray[0]);
- if(HouseInfo[sArray[0]][hOwned] == 0)
- {
- HouseInfo[sArray[0]][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[sArray[0]][hEntranceX], HouseInfo[sArray[0]][hEntranceY], HouseInfo[sArray[0]][hEntranceZ]);
- }
- else if(HouseInfo[sArray[0]][hOwned] == 1)
- {
- HouseInfo[sArray[0]][hPickup] = CreateDynamicPickup(1239, 1, HouseInfo[sArray[0]][hEntranceX], HouseInfo[sArray[0]][hEntranceY], HouseInfo[sArray[0]][hEntranceZ]);
- }
- }
- else
- {
- SendClientMessage(playerid, ORANGE, "[ERROR]: You ain't no RCON admin, you piece of shit motherfucker.");
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:destroyhouse(playerid, params[])
- {
- new string[256];
- if(sscanf(params, "i", sArray[0])) return SendClientMessage(playerid, GREEN, "[SYNTAX]: /destroyhouse [id]");
- if(IsPlayerAdmin(playerid))
- {
- format(string, sizeof(string), "DELETE FROM Houses WHERE id = %i", sArray[0]);
- mysql_query(string);
- DestroyDynamic3DTextLabel(HouseText[sArray[0]]);
- DestroyDynamicPickup(HouseInfo[sArray[0]][hPickup]);
- mysql_query("SELECT MAX(id) FROM Houses");
- mysql_store_result();
- new SQL[20];
- mysql_fetch_row(SQL, "|");
- new SQLID = strval(SQL);
- mysql_free_result();
- format(string, sizeof(string), "ALTER TABLE `Houses` AUTO_INCREMENT =%i", SQLID);
- mysql_query(string);
- //SaveSHouse([sArray[0]]);
- }
- else
- {
- SendClientMessage(playerid, ORANGE, "[ERROR]: You ain't no RCON admin, you piece of shit motherfucker.");
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:shouse(playerid, params[])
- {
- if(IsPlayerAdmin(playerid))
- {
- SendClientMessage(playerid, GREEN, "[HELP]: /createhouse [Price] [Interior (1-3)][Will create a house at your position].");
- SendClientMessage(playerid, GREEN, "[HELP]: /movehouse [HouseID] [Will move a house to your position].");
- SendClientMessage(playerid, GREEN, "[HELP]: /destroyhouse [HouseID] [Will move a house with the selected ID].");
- SendClientMessage(playerid, GREEN, "[HELP]: /househelp [Player Commands for houses].");
- }
- else
- {
- SendClientMessage(playerid, ORANGE, "[ERROR]: You ain't no RCON admin, you piece of shit motherfucker.");
- }
- return 1;
- }//
- //-------------------------------------------------------------------------------------//
- COMMAND:househelp(playerid, params[])
- {
- SendClientMessage(playerid, GREEN, "[HELP]: /buyhouse [You can buy a house].");
- SendClientMessage(playerid, GREEN, "[HELP]: /sellhouse [You will sell your house].");
- SendClientMessage(playerid, GREEN, "[HELP]: /lock [You will lock/unlock your house].");
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:buyhouse(playerid, params[])
- {
- new id = IsPlayerNearByHouse(playerid);
- if(HouseInfo[id][hOwned] == 1) return SendClientMessage(playerid, ORANGE, "[ERROR]This house is already owned!");
- if(GetPlayerMoney(playerid) >= HouseInfo[id][hPrice])
- {
- GivePlayerMoney(playerid, -HouseInfo[id][hPrice]);
- HouseInfo[id][hOwned] = 1;
- strmid(HouseInfo[id][hOwner], GetPlayerNameRP(playerid), 0, strlen(GetPlayerNameRP(playerid)), 255);
- DestroyDynamicPickup(HouseInfo[id][hPickup]);
- HouseInfo[id][hPickup] = CreateDynamicPickup(1239, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
- Update3DTextLabels();
- SaveSHouse(id);
- }
- else return SendClientMessage(playerid, ORANGE, "[ERROR]You don't have enought money to buy this house!");
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:sellhouse(playerid, params[])
- {
- new id = IsPlayerNearByHouse(playerid);
- if(HouseInfo[id][hOwned] == 0) return SendClientMessage(playerid, ORANGE, "[ERROR]This house is already for sale!");
- if(!strcmp(GetPlayerNameRP(playerid), HouseInfo[id][hOwner], true))
- {
- GivePlayerMoney(playerid, HouseInfo[id][hPrice]);
- HouseInfo[id][hOwned] = 0;
- strmid(HouseInfo[id][hOwner], "None", 0, strlen("None"), 255);
- DestroyDynamicPickup(HouseInfo[id][hPickup]);
- HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
- Update3DTextLabels();
- SaveSHouse(id);
- }
- else return SendClientMessage(playerid, ORANGE, "[ERROR]You don't own this house!");
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- COMMAND:lock(playerid, params[])
- {
- new id = IsPlayerNearByHouse(playerid);
- if(id != -1)
- {
- if(!strcmp(GetPlayerNameRP(playerid), HouseInfo[id][hOwner], true))
- {
- if(HouseInfo[id][hOpen] == 0)
- {
- SendClientMessage(playerid, ORANGE, "[INFO]Door Unlocked!");
- HouseInfo[id][hOpen] = 1;
- SaveSHouse(id);
- }
- else
- {
- HouseInfo[id][hOpen] = 0;
- SendClientMessage(playerid, ORANGE, "[INFO]Door locked!");
- SaveSHouse(id);
- }
- }
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- function LoadSHouses()
- {
- for(new id; id < MAX_HOUSES; id++)
- {
- new DataString[128], Query[128];
- format( Query, sizeof( Query ), "SELECT * FROM Houses WHERE id= '%d'", id);
- mysql_query(Query);
- mysql_store_result();
- if(mysql_num_rows())
- if(mysql_fetch_row(Query,"|"))
- {
- mysql_fetch_field("id", DataString);
- HouseInfo[id][hID] = strval(DataString);
- mysql_fetch_field("Owned", DataString);
- HouseInfo[id][hOwned] = strval(DataString);
- mysql_fetch_field("Owner", DataString);
- HouseInfo[id][hOwner] = strval(DataString);
- mysql_fetch_field("EntranceX", DataString);
- HouseInfo[id][hEntranceX] = floatstr(DataString);
- mysql_fetch_field("EntranceY", DataString);
- HouseInfo[id][hEntranceY] = floatstr(DataString);
- mysql_fetch_field("EntranceZ", DataString);
- HouseInfo[id][hEntranceZ] = floatstr(DataString);
- mysql_fetch_field("ExitX", DataString);
- HouseInfo[id][hExitX] = floatstr(DataString);
- mysql_fetch_field("ExitY", DataString);
- HouseInfo[id][hExitY] = floatstr(DataString);
- mysql_fetch_field("ExitZ", DataString);
- HouseInfo[id][hExitZ] = floatstr(DataString);
- mysql_fetch_field("Interior", DataString);
- HouseInfo[id][hInterior] = strval(DataString);
- mysql_fetch_field("Open", DataString);
- HouseInfo[id][hOpen] = strval(DataString);
- mysql_fetch_field("Pickup", DataString);
- HouseInfo[id][hPickup] = strval(DataString);
- mysql_fetch_field("Price", DataString);
- HouseInfo[id][hPrice] = strval(DataString);
- mysql_free_result();
- if(HouseInfo[id][hOwned] == 0)
- {
- HouseText[id] = CreateDynamic3DTextLabel("[HOUSE FOR SALE]", GREEN, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]+0.75, 75.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 75.0);
- HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
- }
- else if(HouseInfo[id][hOwned] == 1)
- {
- HouseText[id] = CreateDynamic3DTextLabel("[HOUSE]", GREEN, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]+0.75, 75.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 75.0);
- HouseInfo[id][hPickup] = CreateDynamicPickup(1239, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
- }
- }
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- function Update3DTextLabels()
- {
- new string[64];
- for(new id = 0; id < sizeof(HouseInfo); id++)
- {
- if(HouseInfo[id][hOwned] == 0)
- {
- format(string,sizeof(string), "[HOUSE FOR SALE]");
- }
- else if(HouseInfo[id][hOwned] == 1)
- {
- format(string,sizeof(string), "[HOUSE]");
- }
- UpdateDynamic3DTextLabelText(HouseText[id], GREEN,string);
- }
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- function CreateSHouse(Float:X, Float:Y, Float:Z, price, interior)
- {
- new string[256];
- format(string, sizeof(string), "INSERT INTO Houses (EntranceX, EntranceY, EntranceZ, Price, Owner) VALUES('%f', '%f', '%f', %i , 'None')",
- X, Y, Z, price);
- mysql_query(string);
- mysql_query("SELECT MAX(id) FROM Houses");
- mysql_store_result();
- new SQL[20];
- mysql_fetch_row(SQL, "|");
- new id = strval(SQL);
- HouseInfo[id][hPrice] = price;
- HouseInfo[id][hEntranceX] = X;
- HouseInfo[id][hEntranceY] = Y;
- HouseInfo[id][hEntranceZ] = Z;
- strmid(HouseInfo[id][hOwner], "None", 0, strlen("None"), 255);
- switch(interior)
- {
- case 1:
- { //Large/2 story/3 bedrooms/
- SetHouseDetails(id, 3 ,235.508994, 1189.169897 ,1080.339966);
- }
- case 2:
- { //Medium/1 story/1 bedroom
- SetHouseDetails(id,2, 225.756989, 1240.000000, 1082.149902);
- }
- case 3:
- { //Small/1 story/1 bedroom
- SetHouseDetails(id, 1, 223.043991 , 1289.259888, 1082.199951);
- }
- case 4:
- { //VERY Large/2 story/4 bedrooms
- SetHouseDetails(id, 7, 225.630997, 1022.479980, 1084.069946 );
- }
- case 5:
- { //Small/1 story/2 bedrooms
- SetHouseDetails(id, 15, 295.138977, 1474.469971, 1080.519897);
- }
- case 6:
- { //Small/1 story/2 bedrooms
- SetHouseDetails(id, 15, 328.493988, 1480.589966, 1084.449951 );
- }
- }
- SaveSHouse(id);
- HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
- HouseText[id] = CreateDynamic3DTextLabel("[HOUSE FOR SALE]", GREEN, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]+0.75, 75.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 75.0);
- return 1;
- }
- //-------------------------------------------------------------------------------------//
- function SetHouseDetails(id, interiorid, Float:X, Float:Y, Float:Z)
- {
- HouseInfo[id][hInterior] = interiorid;
- HouseInfo[id][hExitX] = X;
- HouseInfo[id][hExitY] = Y;
- HouseInfo[id][hExitZ] = Z;
- SaveSHouse(id);
- }
- //-------------------------------------------------------------------------------------//
- function SaveSHouse(id)
- {
- new string[256];
- format(string, sizeof(string), "UPDATE Houses SET EntranceX='%f',EntranceY='%f',EntranceZ='%f', \
- Interior= %i,ExitX='%f',ExitY='%f',ExitZ='%f', Price= %i,Owner='%s',Owned= %i ,Open= %i WHERE id = %i ",
- HouseInfo[id][hEntranceX],HouseInfo[id][hEntranceY],HouseInfo[id][hEntranceZ],
- HouseInfo[id][hInterior],HouseInfo[id][hExitX],HouseInfo[id][hExitY],
- HouseInfo[id][hExitZ],HouseInfo[id][hPrice],HouseInfo[id][hOwner],
- HouseInfo[id][hOwned], HouseInfo[id][hOpen], id);
- mysql_query(string);
- }
- //-------------------------------------------------------------------------------------//
- function IsPlayerNearByHouse(playerid)
- {
- for(new id = 0; id < sizeof(HouseInfo); id++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 5.0, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]))
- {
- return id;
- }
- }
- return -1;
- }
- //-------------------------------------------------------------------------------------//
- stock GetPlayerNameRP(playerid)
- {
- new player[MAX_PLAYER_NAME];
- GetPlayerName(playerid, player, sizeof(player));
- for(new i = 0; i < MAX_PLAYER_NAME; i++)
- {
- if (player[i] == '_') player[i] = ' ';
- }
- return player;
- }
Add Comment
Please, Sign In to add comment