Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <streamer>
- #include <sscanf2>
- #include <dini>
- #include <zcmd>
- #define MAX_HOUSES 30
- #define MAX_HOUSE_NAME 40
- #define HOUSE_DIAG 5050
- #define BUILDINGHOUSE(%0) GetPVarInt(%0, "BuildingHouse")
- #define BUILDID(%0) GetPVarInt(%0, "BuildID")
- #define EDITSTR "House Name\nPrice\nFor Sale\nInterior\nVirtual World\nEnter Position\nExit Position\nSpawn Position\nPickup Position\nLabel Position\nEnter Checkpoint\nExit Checkpoint"
- //=========[Internal Settings]========== [Don't not edit these unless you know what you are doing]
- // [Model IDs]
- #define NOTFORSALE_PICKUP 1272
- #define FORSALE_PICKUP 1273
- #define NOTFORSALE_ICON 32
- #define FORSALE_ICON 31
- // [Draw Distance]
- #define ICON_DRAW 100.0
- #define PICKUP_DRAW 30.0
- #define LABEL_DRAW 30.0
- #define ENTERCP_DRAW 15.0
- #define EXITCP_DRAW 15.0
- // [Size]
- #define ENTERCP_SIZE 1.0
- #define EXITCP_SIZE 1.0
- // [Properties]
- #define LABEL_LOS 1 //Labels show through objects? [1-Yes/0-No]
- //===========================
- #define LABEL_COLOR 0xFFFFFFF
- #define MSG_COLOR 0x37C83AFF
- #define HOUSE_FILE "/Houses/%d.ini"
- new hfile[80];
- new hstr[750];
- enum h_enum
- {
- Name[MAX_HOUSE_NAME],
- Owner[MAX_PLAYER_NAME],
- Price,
- ForSale,
- Interior,
- World,
- Float:EnterPos[4], //Pos after entering EnterCP [X-Y-Z-A]
- Float:ExitPos[4], //Pos after entering ExitCP
- Float:SpawnPos[4], //Pos set on spawn
- Float:PickupPos[3],
- Float:LabelPos[3],
- Float:EnterCPPos[3],
- Float:ExitCPPos[3],
- MapIcon, //Red if not for sale, green if yes
- Pickup, //House main properties [Buy, Sell, Information]
- Text3D:InfoLabel,
- EnterCP,
- ExitCP
- }
- new hInfo[MAX_HOUSES][h_enum];
- //Added - House loading, main build menu
- //Needed - Builder menu
- public OnFilterScriptInit()
- {
- print(" House System v0.1 by PotH3Ad initialized...");
- for(new x=0; x<MAX_HOUSES; x++)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, x);
- if(!fexist(hfile)) continue;
- format(hInfo[x][Name], MAX_HOUSE_NAME, "%s", dini_Get(hfile, "Name"));
- format(hInfo[x][Owner], MAX_PLAYER_NAME, "%s", dini_Get(hfile, "Owner"));
- hInfo[x][Price] = dini_Int(hfile, "Price");
- hInfo[x][ForSale] = dini_Int(hfile, "ForSale");
- hInfo[x][Interior] = dini_Int(hfile, "Interior");
- hInfo[x][World] = dini_Int(hfile, "World");
- for(new i=0; i<3; i++)
- {
- sscanf(dini_Get(hfile, "EnterPos"), "p<,>ffff", hInfo[x][EnterPos][i]);
- sscanf(dini_Get(hfile, "ExitPos"), "p<,>ffff", hInfo[x][ExitPos][i]);
- sscanf(dini_Get(hfile, "SpawnPos"), "p<,>ffff", hInfo[x][SpawnPos][i]);
- sscanf(dini_Get(hfile, "LabelPos"), "p<,>fff", hInfo[x][LabelPos][i]);
- sscanf(dini_Get(hfile, "EnterCPPos"), "p<,>fff", hInfo[x][EnterCPPos][i]);
- sscanf(dini_Get(hfile, "ExitCPPos"), "p<,>fff", hInfo[x][ExitCPPos][i]);
- }
- if(dini_Int(hfile, "ForSale"))
- {
- hInfo[x][Pickup] = CreateDynamicPickup(FORSALE_PICKUP, 1, hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], 0, 0, -1, PICKUP_DRAW);
- hInfo[x][MapIcon] = CreateDynamicMapIcon(hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], FORSALE_ICON, 0, 0, 0, -1, ICON_DRAW);
- }
- else
- {
- hInfo[x][Pickup] = CreateDynamicPickup(NOTFORSALE_PICKUP, 1, hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], 0, 0, -1, PICKUP_DRAW);
- hInfo[x][MapIcon] = CreateDynamicMapIcon(hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], NOTFORSALE_ICON, 0, 0, 0, -1, ICON_DRAW);
- }
- hInfo[x][EnterCP] = CreateDynamicCP(hInfo[x][EnterCPPos][0], hInfo[x][EnterCPPos][1], hInfo[x][EnterCPPos][2], ENTERCP_SIZE, hInfo[x][World], hInfo[x][Interior], -1, ENTERCP_DRAW);
- hInfo[x][ExitCP] = CreateDynamicCP(hInfo[x][ExitCPPos][0], hInfo[x][ExitCPPos][1], hInfo[x][ExitCPPos][2], EXITCP_SIZE, -1, 0, -1, ENTERCP_DRAW);
- new str[100];
- format(str, sizeof(str), "%s\nOwner: %s\nPrice: $%d", hInfo[x][Name], hInfo[x][Owner], hInfo[x][Price]);
- hInfo[x][InfoLabel] = CreateDynamic3DTextLabel(str, LABEL_COLOR, hInfo[x][LabelPos][0], hInfo[x][LabelPos][1], hInfo[x][LabelPos][2], LABEL_DRAW, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, LABEL_LOS, 0, 0, -1, LABEL_DRAW);
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- print(" House System v0.1 by PotH3Ad");
- for(new x=0; x<MAX_HOUSES; x++)
- {
- DestroyDynamicCP(hInfo[x][EnterCP]);
- DestroyDynamicCP(hInfo[x][ExitCP]);
- DestroyDynamicPickup(hInfo[x][Pickup]);
- DestroyDynamicMapIcon(hInfo[x][MapIcon]);
- DestroyDynamic3DTextLabel(hInfo[x][InfoLabel]);
- }
- return 1;
- }
- CMD:hexit(playerid, params[])
- {
- SetPVarInt(playerid, "BuildingHouse", 0);
- return 1;
- }
- CMD:hmenu(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return 1;
- if(BUILDINGHOUSE(playerid)) return 1;
- ShowBuilderDialog(playerid);
- return 1;
- }
- CMD:hedit(playerid, params[])
- {
- if(!BUILDINGHOUSE(playerid)) return 1;
- ShowEditDialog(playerid);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == HOUSE_DIAG)
- {
- if(response)
- {
- switch(listitem)
- {
- case 0:
- {
- new hid = GetLowestOpenSlot();
- SetPVarInt(playerid, "BuildingHouse", 1);
- format(hfile, sizeof(hfile), HOUSE_FILE, hid);
- dini_Create(hfile);
- dini_Set(hfile, "Builder", pName(playerid));
- SetPVarInt(playerid, "BuildID", hid);
- SendClientMessage(playerid, MSG_COLOR, "You are now building a house! {0000FF}(Tip: Use '/hedit' to access the edit menu.)");
- }
- case 1:
- {
- format(hstr, sizeof(hstr), "ID\tHouse Name\n");
- for(new x=0; x<MAX_HOUSES; x++)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, x);
- if(strlen(dini_Get(hfile, "Name")) > 0) format(hstr, sizeof(hstr), "%s%d\t%s\n", hstr, x, dini_Get(hfile, "Name"));
- else format(hstr, sizeof(hstr), "%s%d\tEmpty Slot\n", hstr, x);
- }
- ShowPlayerDialog(playerid, HOUSE_DIAG+1, DIALOG_STYLE_LIST, "Choose a house to edit", hstr, "Select", "Exit");
- }
- case 2:
- {
- format(hstr, sizeof(hstr), "ID\tHouse Name\n");
- for(new x=0; x<MAX_HOUSES; x++)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, x);
- if(strlen(dini_Get(hfile, "Name")) > 0) format(hstr, sizeof(hstr), "%s%d\t%s\n", hstr, x, dini_Get(hfile, "Name"));
- else format(hstr, sizeof(hstr), "%s%d\tEmpty Slot\n", hstr, x);
- }
- ShowPlayerDialog(playerid, HOUSE_DIAG+2, DIALOG_STYLE_LIST, "Delete a house", hstr, "Select", "Exit");
- }
- case 3:
- {
- format(hstr, sizeof(hstr), "ID\tHouse Name\n");
- for(new x=0; x<MAX_HOUSES; x++)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, x);
- if(strlen(dini_Get(hfile, "Name")) > 0) format(hstr, sizeof(hstr), "%s%d\t%s\n", hstr, x, dini_Get(hfile, "Name"));
- else format(hstr, sizeof(hstr), "%s%d\tEmpty Slot\n", hstr, x);
- }
- ShowPlayerDialog(playerid, HOUSE_DIAG+3, DIALOG_STYLE_LIST, "Select a house to view info", hstr, "Select", "Back");
- }
- }
- }
- }
- else if(dialogid == HOUSE_DIAG+1)
- {
- if(response)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, listitem-1);
- if(!dini_Exists(hfile)) return OnDialogResponse(playerid, HOUSE_DIAG, 1, 1, "blank");
- SetPVarInt(playerid, "BuildingHouse", 1);
- SetPVarInt(playerid, "BuildID", listitem-1);
- }
- else ShowBuilderDialog(playerid);
- }
- else if(dialogid == HOUSE_DIAG+2)
- {
- if(response)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, listitem-1);
- if(!dini_Exists(hfile)) return OnDialogResponse(playerid, HOUSE_DIAG, 1, 2, "blank");
- dini_Remove(hfile);
- }
- else ShowBuilderDialog(playerid);
- }
- else if(dialogid == HOUSE_DIAG+3)
- {
- if(response)
- {
- #define hid listitem-1
- format(hfile, sizeof(hfile), HOUSE_FILE, hid);
- if(!dini_Exists(hfile)) return OnDialogResponse(playerid, HOUSE_DIAG, 1, 3, "blank");
- format(hstr, sizeof(hstr), "House Name\t\t%s (ID %d)\nOwner\t\t%s\nBuilder\t\t%s\nPrice\t\t$%d\nFor Sale\t\t%d\nInterior\t\t%d\nWorld\t\t%d", hInfo[hid][Name],
- hid, hInfo[hid][Owner], dini_Get(hfile, "Builder"), hInfo[hid][Price], hInfo[hid][ForSale], hInfo[hid][Interior], hInfo[hid][World]);
- ShowPlayerDialog(playerid, HOUSE_DIAG-1, DIALOG_STYLE_MSGBOX, "House Information", hstr, "Ok", "Exit");
- }
- else ShowBuilderDialog(playerid);
- }
- //Edit menu
- else if(dialogid == HOUSE_DIAG+4)
- {
- if(response)
- {
- //"House Name\nPrice\nFor Sale\nInterior\nVirtual World\nEnter Position\nExit Position\nSpawn Position\nPickup Position\nLabel Position\nEnter Checkpoint\nExit Checkpoint"
- switch(listitem)
- {
- case 0:
- {
- ShowPlayerDialog(playerid, HOUSE_DIAG-1, DIALOG_STYLE_INPUT, "House Edit - House Name", hstr, "Update", "Cancel");
- }
- }
- }
- }
- return 0;
- }
- stock ShowBuilderDialog(playerid)
- {
- ShowPlayerDialog(playerid, HOUSE_DIAG, DIALOG_STYLE_LIST, "House Builder", "Build House\nEdit House\nDestroy House\nView House Info", "Select", "Exit");
- }
- stock ShowEditDialog(playerid)
- {
- ShowPlayerDialog(playerid, HOUSE_DIAG+4, DIALOG_STYLE_LIST, "House Builder - Edit", EDITSTR, "Select", "Exit");
- }
- stock SetPlayerPosEx(playerid, Float:x, Float:y, Float:z, Float:angle, interior, world)
- {
- SetPlayerPos(playerid, x, y, z);
- SetPlayerFacingAngle(playerid, angle);
- SetPlayerInterior(playerid, interior);
- SetPlayerVirtualWorld(playerid, world);
- }
- stock GetLowestOpenSlot()
- {
- new num;
- for(new x=0; x<MAX_HOUSES; x++)
- {
- format(hfile, sizeof(hfile), HOUSE_FILE, x);
- if(!dini_Exists(hfile))
- {
- num = x;
- break;
- }
- }
- return num;
- }
- stock pName(playerid)
- {
- new aname[MAX_PLAYER_NAME];
- GetPlayerName(playerid, aname, sizeof(aname));
- return aname;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement