Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ---------------- Jason's Dynamic Housing System ----------------- */
- /* I'm not even going to attempt to put credits here, I know people are just
- going to rip code off me anyway. Might as well give you some decent code to
- rip off of. Enjoy! ;) */
- #include <a_samp>
- #include <streamer>
- #include <sscanf2>
- #include <dini>
- #include <ZCMD>
- #define FILTERSCRIPT
- #define MAX_HOUSES 2000
- #define COLOUR_WHITE 0xFFFFFFAA
- #define COLOUR_GREY 0xAFAFAFAA
- #define COLOUR_LIGHTBLUE 0x33CCFFAA
- #define COLOUR_GREEN 0x33AA33AA
- new ActiveHouses;
- enum HouseData
- {
- hOwned,
- hOwner[255],
- hPrice,
- Float: hExteriorX,
- Float: hExteriorY,
- Float: hExteriorZ,
- Float: hExteriorA,
- hExteriorVW,
- hExteriorInt,
- Float: hInteriorX,
- Float: hInteriorY,
- Float: hInteriorZ,
- Float: hInteriorA,
- hInteriorVW,
- hInteriorInt,
- hLock,
- Text3D: hTextLabelID,
- hPickupID
- }
- new House[MAX_HOUSES][HouseData];
- public OnFilterScriptInit()
- {
- print(" [server] Initiated Jason's Dynamic Housing System");
- LoadHouses();
- return 1;
- }
- public OnFilterScriptExit()
- {
- print(" [server] Unloaded Jason's Dynamic Housing System");
- SaveHouses();
- return 1;
- }
- command(hcreate, playerid, params[])
- {
- new Usage[255], string[255];
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "s[255]", Usage))
- {
- SendClientMessage(playerid, COLOUR_WHITE, "USAGE: /hcreate [usage]");
- SendClientMessage(playerid, COLOUR_GREY, "Usages: Exterior, Interior, Complete.");
- }
- else
- {
- new hID = ActiveHouses+1;
- if(strcmp(Usage, "exterior", true) == 0)
- {
- GetPlayerPos(playerid, House[hID][hExteriorX], House[hID][hExteriorY], House[hID][hExteriorZ]);
- GetPlayerFacingAngle(playerid, House[hID][hExteriorA]);
- House[hID][hExteriorVW] = GetPlayerVirtualWorld(playerid);
- House[hID][hExteriorInt] = GetPlayerInterior(playerid);
- format(string, sizeof(string), "You have successfully set the exterior of House %d.", hID);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- format(string, sizeof(string), "X: %f, Y: %f, Z: %f, A: %f, VW: %d, Int: %d", House[hID][hExteriorX], House[hID][hExteriorY], House[hID][hExteriorZ], House[hID][hExteriorA], House[hID][hExteriorVW], House[hID][hExteriorInt]);
- SendClientMessage(playerid, COLOUR_GREY, string);
- return 1;
- }
- if(strcmp(Usage, "interior", true) == 0)
- {
- GetPlayerPos(playerid, House[hID][hInteriorX], House[hID][hInteriorY], House[hID][hInteriorZ]);
- GetPlayerFacingAngle(playerid, House[hID][hInteriorA]);
- House[hID][hInteriorVW] = GetPlayerVirtualWorld(playerid);
- House[hID][hInteriorInt] = GetPlayerInterior(playerid);
- format(string, sizeof(string), "You have successfully set the interior of House %d.", hID);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- format(string, sizeof(string), "X: %f, Y: %f, Z: %f, A: %f, VW: %d, Int: %d", House[hID][hInteriorX], House[hID][hInteriorY], House[hID][hInteriorZ], House[hID][hInteriorA], House[hID][hInteriorVW], House[hID][hInteriorInt]);
- SendClientMessage(playerid, COLOUR_GREY, string);
- return 1;
- }
- if(strcmp(Usage, "complete", true) == 0)
- {
- if(House[hID][hExteriorX] > 0 && House[hID][hInteriorX] > 0)
- {
- if(hID >= MAX_HOUSES)
- {
- SendClientMessage(playerid, COLOUR_GREY, " Error: Too many houses are currently spawend.");
- }
- else
- {
- format(string, sizeof(string), "Houses/%d.ini", hID);
- if(!fexist(string))
- {
- dini_Create(string);
- dini_IntSet(string, "hOwned", 0);
- dini_Set(string, "hOwner", "Nobody");
- dini_IntSet(string, "hPrice", 0);
- dini_IntSet(string, "hLock", 0);
- dini_FloatSet(string, "hExteriorX", House[hID][hExteriorX]);
- dini_FloatSet(string, "hExteriorY", House[hID][hExteriorY]);
- dini_FloatSet(string, "hExteriorZ", House[hID][hExteriorZ]);
- dini_FloatSet(string, "hExteriorA", House[hID][hExteriorA]);
- dini_IntSet(string, "hExteriorVW", House[hID][hExteriorVW]);
- dini_IntSet(string, "hExteriorInt", House[hID][hExteriorInt]);
- dini_FloatSet(string, "hInteriorX", House[hID][hInteriorX]);
- dini_FloatSet(string, "hInteriorY", House[hID][hInteriorY]);
- dini_FloatSet(string, "hInteriorZ", House[hID][hInteriorZ]);
- dini_FloatSet(string, "hInteriorA", House[hID][hInteriorA]);
- dini_IntSet(string, "hInteriorVW", House[hID][hInteriorVW]);
- dini_IntSet(string, "hInteriorInt", House[hID][hInteriorInt]);
- ActiveHouses++;
- format(string, sizeof(string), "You have successfully created House %d.", hID);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- SetPlayerPos(playerid, House[hID][hExteriorX], House[hID][hExteriorY], House[hID][hExteriorZ]);
- SetPlayerVirtualWorld(playerid, House[hID][hExteriorVW]);
- SetPlayerInterior(playerid, House[hID][hExteriorInt]);
- SetPlayerFacingAngle(playerid, House[hID][hExteriorA]);
- SetCameraBehindPlayer(playerid);
- RespawnHousePickup(hID);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " Error: File already exists, script error.");
- }
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You need to set the house's (ex/in)terior before completing!");
- return 1;
- }
- }
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You are not an administrator!");
- }
- return 1;
- }
- command(hedit, playerid, params[])
- {
- new id, Usage[255], Price, string[255];
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "ds[255]D", id, Usage, Price))
- {
- SendClientMessage(playerid, COLOUR_WHITE, "USAGE: /hedit [id] [usage] [* value]");
- SendClientMessage(playerid, COLOUR_GREY, "Usages: Exterior, Interior, Sell, * Price");
- }
- else
- {
- if(strcmp(Usage, "exterior", true) == 0)
- {
- GetPlayerPos(playerid, House[id][hExteriorX], House[id][hExteriorY], House[id][hExteriorZ]);
- GetPlayerFacingAngle(playerid, House[id][hExteriorA]);
- House[id][hExteriorVW] = GetPlayerVirtualWorld(playerid);
- House[id][hExteriorInt] = GetPlayerInterior(playerid);
- format(string, sizeof(string), "You have successfully re-set the exterior of House %d.", id);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- format(string, sizeof(string), "X: %f, Y: %f, Z: %f, A: %f, VW: %d, Int: %d", House[id][hExteriorX], House[id][hExteriorY], House[id][hExteriorZ], House[id][hExteriorA], House[id][hExteriorVW], House[id][hExteriorInt]);
- SendClientMessage(playerid, COLOUR_GREY, string);
- SaveHouse(id);
- return 1;
- }
- if(strcmp(Usage, "interior", true) == 0)
- {
- GetPlayerPos(playerid, House[id][hInteriorX], House[id][hInteriorY], House[id][hInteriorZ]);
- GetPlayerFacingAngle(playerid, House[id][hInteriorA]);
- House[id][hInteriorVW] = GetPlayerVirtualWorld(playerid);
- House[id][hInteriorInt] = GetPlayerInterior(playerid);
- format(string, sizeof(string), "You have successfully re-set the interior of House %d.", id);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- format(string, sizeof(string), "X: %f, Y: %f, Z: %f, A: %f, VW: %d, Int: %d", House[id][hInteriorX], House[id][hInteriorY], House[id][hInteriorZ], House[id][hInteriorA], House[id][hInteriorVW], House[id][hInteriorInt]);
- SendClientMessage(playerid, COLOUR_GREY, string);
- SaveHouse(id);
- return 1;
- }
- if(strcmp(Usage, "sell", true) == 0)
- {
- House[id][hOwned] = 0;
- format(string, sizeof(string), "You have successfully sold House %d.", id);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- SaveHouse(id);
- return 1;
- }
- if(strcmp(Usage, "price", true) == 0)
- {
- House[id][hPrice] = Price;
- format(string, sizeof(string), "You have successfully set the price of House %d.", id);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- format(string, sizeof(string), "P: %d", House[id][hPrice]);
- SendClientMessage(playerid, COLOUR_GREY, string);
- SaveHouse(id);
- return 1;
- }
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You are not an administrator!");
- }
- return 1;
- }
- command(gotohouse, playerid, params[])
- {
- new id;
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "d", id))
- {
- SendClientMessage(playerid, COLOUR_WHITE, "USAGE: /gotohouse [id]");
- }
- else
- {
- if(House[id][hExteriorX] > 0 && House[id][hInteriorX] > 0)
- {
- SetPlayerPos(playerid, House[id][hExteriorX], House[id][hExteriorY], House[id][hExteriorZ]);
- SetPlayerVirtualWorld(playerid, House[id][hExteriorVW]);
- SetPlayerInterior(playerid, House[id][hExteriorInt]);
- SetPlayerFacingAngle(playerid, House[id][hExteriorA]);
- SetCameraBehindPlayer(playerid);
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " Error: Invalid house number");
- }
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You are not an administrator!");
- }
- return 1;
- }
- command(goinhouse, playerid, params[])
- {
- new id;
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "d", id))
- {
- SendClientMessage(playerid, COLOUR_WHITE, "USAGE: /goinhouse [id]");
- }
- else
- {
- if(House[id][hExteriorX] > 0 && House[id][hInteriorX] > 0)
- {
- SetPlayerPos(playerid, House[id][hInteriorX], House[id][hInteriorY], House[id][hInteriorZ]);
- SetPlayerVirtualWorld(playerid, House[id][hInteriorVW]);
- SetPlayerInterior(playerid, House[id][hInteriorInt]);
- SetPlayerFacingAngle(playerid, House[id][hInteriorA]);
- SetCameraBehindPlayer(playerid);
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " Error: Invalid house number");
- }
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You are not an administrator!");
- }
- return 1;
- }
- command(gotoco, playerid, params[])
- {
- new Interior, Float: x, Float: y, Float: z;
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "fffd", x, y, z, Interior))
- {
- SendClientMessage(playerid, COLOUR_WHITE, "USAGE: /gotoco [x point] [y point] [z point] [Interior ID]");
- }
- else
- {
- SetPlayerPos(playerid, x, y, z);
- SetPlayerInterior(playerid, Interior);
- SendClientMessage(playerid, COLOUR_GREY, " You have been teleported!");
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You are not an administrator!");
- }
- return 1;
- }
- command(buyhouse, playerid, params[])
- {
- #pragma unused params
- new string[255];
- for(new h = 0; h < sizeof(House); h++)
- {
- print("test");
- if(IsPlayerInRangeOfPoint(playerid, 5, House[h][hExteriorX], House[h][hExteriorY], House[h][hExteriorZ]))
- {
- if(House[h][hOwned] == 0)
- {
- if(GetPlayerMoney(playerid) >= House[h][hPrice])
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- GivePlayerMoney(playerid, -House[h][hPrice]);
- House[h][hOwned] = 1;
- format(House[h][hOwner], 255, "%s", name);
- format(string, sizeof(string), " You have successfully purchase House %d", h);
- SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
- SaveHouse(h);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You do not have enough money!");
- return 1;
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " This house is already owned!");
- return 1;
- }
- }
- }
- return 1;
- }
- command(lockhouse, playerid, params[])
- {
- #pragma unused params
- for(new h = 0; h < sizeof(House); h++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 5, House[h][hExteriorX], House[h][hExteriorY], House[h][hExteriorZ]) || IsPlayerInRangeOfPoint(playerid, 5, House[h][hInteriorX], House[h][hInteriorY], House[h][hInteriorZ]))
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- if(strcmp(House[h][hOwner], name, true) == 0)
- {
- if(House[h][hLock] == 0)
- {
- House[h][hLock] = 1;
- SendClientMessage(playerid, COLOUR_WHITE, "You have locked your house.");
- return 1;
- }
- else
- {
- House[h][hLock] = 0;
- SendClientMessage(playerid, COLOUR_WHITE, "You have un-locked your house.");
- return 1;
- }
- }
- else
- {
- SendClientMessage(playerid, COLOUR_GREY, " You do not own this house!");
- return 1;
- }
- }
- }
- return 1;
- }
- command(enterhouse, playerid, params[])
- {
- #pragma unused params
- for(new h = 0; h < sizeof(House); h++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 5, House[h][hExteriorX], House[h][hExteriorY], House[h][hExteriorZ]))
- {
- if(House[h][hLock] == 0)
- {
- SetPlayerPos(playerid, House[h][hInteriorX], House[h][hInteriorY], House[h][hInteriorZ]);
- SetPlayerVirtualWorld(playerid, House[h][hInteriorVW]);
- SetPlayerInterior(playerid, House[h][hInteriorInt]);
- SetPlayerFacingAngle(playerid, House[h][hInteriorA]);
- SetCameraBehindPlayer(playerid);
- return 1;
- }
- else
- {
- GameTextForPlayer(playerid,"~r~Locked!", 3000, 1);
- return 1;
- }
- }
- }
- return 1;
- }
- command(exithouse, playerid, params[])
- {
- #pragma unused params
- for(new h = 0; h < sizeof(House); h++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 5, House[h][hInteriorX], House[h][hInteriorY], House[h][hInteriorZ]))
- {
- SetPlayerPos(playerid, House[h][hExteriorX], House[h][hExteriorY], House[h][hExteriorZ]);
- SetPlayerVirtualWorld(playerid, House[h][hExteriorVW]);
- SetPlayerInterior(playerid, House[h][hExteriorInt]);
- SetPlayerFacingAngle(playerid, House[h][hExteriorA]);
- SetCameraBehindPlayer(playerid);
- return 1;
- }
- }
- return 1;
- }
- stock RespawnHousePickup(houseid)
- {
- new string[255];
- DestroyDynamicPickup(House[houseid][hPickupID]);
- DestroyDynamic3DTextLabel(House[houseid][hTextLabelID]);
- if(House[houseid][hOwned] >= 1)
- {
- format(string, sizeof(string), "This house is owned by\n%s\nID: %d", House[houseid][hOwner], houseid);
- House[houseid][hTextLabelID] = CreateDynamic3DTextLabel(string, COLOUR_GREEN, House[houseid][hExteriorX], House[houseid][hExteriorY], House[houseid][hExteriorZ]+0.5,10.0, .testlos = 1, .worldid = House[houseid][hExteriorVW], .interiorid = House[houseid][hExteriorVW], .streamdistance = 10.0);
- House[houseid][hPickupID] = CreateDynamicPickup(1272, 23, House[houseid][hExteriorX], House[houseid][hExteriorY], House[houseid][hExteriorZ], .worldid = House[houseid][hExteriorVW], .interiorid = House[houseid][hExteriorVW]);
- }
- else
- {
- format(string, sizeof(string), "For Sale!\nPrice: %d\nID: %d", House[houseid][hPrice], houseid);
- House[houseid][hTextLabelID] = CreateDynamic3DTextLabel(string, COLOUR_GREEN, House[houseid][hExteriorX], House[houseid][hExteriorY], House[houseid][hExteriorZ]+0.5,10.0, .testlos = 1, .worldid = House[houseid][hExteriorVW], .interiorid = House[houseid][hExteriorVW], .streamdistance = 10.0);
- House[houseid][hPickupID] = CreateDynamicPickup(1273, 23, House[houseid][hExteriorX], House[houseid][hExteriorY], House[houseid][hExteriorZ], .worldid = House[houseid][hExteriorVW], .interiorid = House[houseid][hExteriorVW]);
- }
- return 1;
- }
- stock RespawnHouseTextLabel(houseid)
- {
- new string[128];
- if(House[houseid][hOwned] >= 1)
- {
- format(string, sizeof(string), "This house is owned by\n%s\nID: %d", House[houseid][hOwner], houseid);
- }
- else format(string, sizeof(string), "For Sale!\nPrice: %d\nID: %d", House[houseid][hPrice], houseid);
- UpdateDynamic3DTextLabelText(House[houseid][hTextLabelID], COLOR_GREEN, string);
- }
- stock SaveHouses()
- {
- for(new i = 0; i < MAX_HOUSES; i++)
- {
- SaveHouse(i);
- }
- return 1;
- }
- stock SaveHouse(houseid)
- {
- new File[23];
- format(File, sizeof(File), "Houses/%d.ini", houseid);
- if(fexist(File))
- {
- dini_IntSet(File, "hOwned", House[houseid][hOwned]);
- dini_Set(File, "hOwner", House[houseid][hOwner]);
- dini_IntSet(File, "hPrice", House[houseid][hPrice]);
- dini_IntSet(File, "hLock", House[houseid][hLock]);
- dini_FloatSet(File, "hExteriorX", House[houseid][hExteriorX]);
- dini_FloatSet(File, "hExteriorY", House[houseid][hExteriorY]);
- dini_FloatSet(File, "hExteriorZ", House[houseid][hExteriorZ]);
- dini_FloatSet(File, "hExteriorA", House[houseid][hExteriorA]);
- dini_IntSet(File, "hExteriorVW", House[houseid][hExteriorVW]);
- dini_IntSet(File, "hExteriorInt", House[houseid][hExteriorInt]);
- dini_FloatSet(File, "hInteriorX", House[houseid][hInteriorX]);
- dini_FloatSet(File, "hInteriorY", House[houseid][hInteriorY]);
- dini_FloatSet(File, "hInteriorZ", House[houseid][hInteriorZ]);
- dini_FloatSet(File, "hInteriorA", House[houseid][hInteriorA]);
- dini_IntSet(File, "hInteriorVW", House[houseid][hInteriorVW]);
- dini_IntSet(File, "hInteriorInt", House[houseid][hInteriorInt]);
- RespawnHousePickup(houseid);
- }
- return 1;
- }
- stock LoadHouses()
- {
- new File[23];
- for(new i = 0; i < MAX_HOUSES; i++)
- {
- format(File, sizeof(File), "Houses/%d.ini", i);
- if(fexist(File))
- {
- House[i][hOwned] = dini_Int(File, "hOwned");
- House[i][hOwner] = dini_Get(File, "hOwner");
- House[i][hPrice] = dini_Int(File, "hPrice");
- House[i][hLock] = dini_Int(File, "hLock");
- House[i][hExteriorX] = dini_Float(File, "hExteriorX");
- House[i][hExteriorY] = dini_Float(File, "hExteriorY");
- House[i][hExteriorZ] = dini_Float(File, "hExteriorZ");
- House[i][hExteriorA] = dini_Float(File, "hExteriorA");
- House[i][hExteriorVW] = dini_Int(File, "hExteriorVW");
- House[i][hExteriorInt] = dini_Int(File, "hExteriorInt");
- House[i][hInteriorX] = dini_Float(File, "hInteriorX");
- House[i][hInteriorY] = dini_Float(File, "hInteriorY");
- House[i][hInteriorZ] = dini_Float(File, "hInteriorZ");
- House[i][hInteriorA] = dini_Float(File, "hInteriorA");
- House[i][hInteriorVW] = dini_Int(File, "hInteriorVW");
- House[i][hInteriorInt] = dini_Int(File, "hInteriorInt");
- ActiveHouses++;
- RespawnHousePickup(i);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement