Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.86 KB | None | 0 0
  1. #include <a_samp>
  2. #include <streamer>
  3. #include <sscanf2>
  4. #include <dini>
  5. #include <zcmd>
  6.  
  7. #define MAX_HOUSES      30
  8. #define MAX_HOUSE_NAME  40
  9.  
  10. #define HOUSE_DIAG 5050
  11.  
  12. #define BUILDINGHOUSE(%0) GetPVarInt(%0, "BuildingHouse")
  13. #define BUILDID(%0) GetPVarInt(%0, "BuildID")
  14.  
  15. #define EDITSTR "House Name\nPrice\nFor Sale\nInterior\nVirtual World\nEnter Position\nExit Position\nSpawn Position\nPickup Position\nLabel Position\nEnter Checkpoint\nExit Checkpoint"
  16.  
  17. //=========[Internal Settings]========== [Don't not edit these unless you know what you are doing]
  18. //      [Model IDs]
  19. #define NOTFORSALE_PICKUP   1272
  20. #define FORSALE_PICKUP      1273
  21. #define NOTFORSALE_ICON     32
  22. #define FORSALE_ICON        31
  23. //      [Draw Distance]
  24. #define ICON_DRAW       100.0
  25. #define PICKUP_DRAW     30.0
  26. #define LABEL_DRAW      30.0
  27. #define ENTERCP_DRAW    15.0
  28. #define EXITCP_DRAW     15.0
  29. //      [Size]
  30. #define ENTERCP_SIZE    1.0
  31. #define EXITCP_SIZE     1.0
  32. //      [Properties]
  33. #define LABEL_LOS       1   //Labels show through objects? [1-Yes/0-No]
  34. //===========================
  35. #define LABEL_COLOR 0xFFFFFFF
  36. #define MSG_COLOR   0x37C83AFF
  37.  
  38. #define HOUSE_FILE "/Houses/%d.ini"
  39.  
  40. new hfile[80];
  41. new hstr[750];
  42.  
  43. enum h_enum
  44. {
  45.     Name[MAX_HOUSE_NAME],
  46.     Owner[MAX_PLAYER_NAME],
  47.     Price,
  48.     ForSale,
  49.     Interior,
  50.     World,
  51.     Float:EnterPos[4],      //Pos after entering EnterCP [X-Y-Z-A]
  52.     Float:ExitPos[4],       //Pos after entering ExitCP
  53.     Float:SpawnPos[4],      //Pos set on spawn
  54.     Float:PickupPos[3],
  55.     Float:LabelPos[3],
  56.     Float:EnterCPPos[3],
  57.     Float:ExitCPPos[3],
  58.     MapIcon,                //Red if not for sale, green if yes
  59.     Pickup,                 //House main properties [Buy, Sell, Information]
  60.     Text3D:InfoLabel,
  61.     EnterCP,
  62.     ExitCP
  63. }
  64. new hInfo[MAX_HOUSES][h_enum];
  65.  
  66. //Added - House loading, main build menu
  67. //Needed - Builder menu
  68.  
  69. public OnFilterScriptInit()
  70. {
  71.     print("  House System v0.1 by PotH3Ad initialized...");
  72.    
  73.     for(new x=0; x<MAX_HOUSES; x++)
  74.     {
  75.         format(hfile, sizeof(hfile), HOUSE_FILE, x);
  76.         if(!fexist(hfile)) continue;
  77.  
  78.         format(hInfo[x][Name], MAX_HOUSE_NAME, "%s", dini_Get(hfile, "Name"));
  79.         format(hInfo[x][Owner], MAX_PLAYER_NAME, "%s", dini_Get(hfile, "Owner"));
  80.         hInfo[x][Price] = dini_Int(hfile, "Price");
  81.         hInfo[x][ForSale] = dini_Int(hfile, "ForSale");
  82.         hInfo[x][Interior] = dini_Int(hfile, "Interior");
  83.         hInfo[x][World] = dini_Int(hfile, "World");
  84.  
  85.         for(new i=0; i<3; i++)
  86.         {
  87.             sscanf(dini_Get(hfile, "EnterPos"), "p<,>ffff", hInfo[x][EnterPos][i]);
  88.             sscanf(dini_Get(hfile, "ExitPos"), "p<,>ffff", hInfo[x][ExitPos][i]);
  89.             sscanf(dini_Get(hfile, "SpawnPos"), "p<,>ffff", hInfo[x][SpawnPos][i]);
  90.             sscanf(dini_Get(hfile, "LabelPos"), "p<,>fff", hInfo[x][LabelPos][i]);
  91.             sscanf(dini_Get(hfile, "EnterCPPos"), "p<,>fff", hInfo[x][EnterCPPos][i]);
  92.             sscanf(dini_Get(hfile, "ExitCPPos"), "p<,>fff", hInfo[x][ExitCPPos][i]);
  93.         }
  94.         if(dini_Int(hfile, "ForSale"))
  95.         {
  96.             hInfo[x][Pickup] = CreateDynamicPickup(FORSALE_PICKUP, 1, hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], 0, 0, -1, PICKUP_DRAW);
  97.             hInfo[x][MapIcon] = CreateDynamicMapIcon(hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], FORSALE_ICON, 0, 0, 0, -1, ICON_DRAW);
  98.         }
  99.         else
  100.         {
  101.             hInfo[x][Pickup] = CreateDynamicPickup(NOTFORSALE_PICKUP, 1, hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], 0, 0, -1, PICKUP_DRAW);
  102.             hInfo[x][MapIcon] = CreateDynamicMapIcon(hInfo[x][PickupPos][0], hInfo[x][PickupPos][1], hInfo[x][PickupPos][2], NOTFORSALE_ICON, 0, 0, 0, -1, ICON_DRAW);
  103.         }
  104.  
  105.         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);
  106.         hInfo[x][ExitCP] = CreateDynamicCP(hInfo[x][ExitCPPos][0], hInfo[x][ExitCPPos][1], hInfo[x][ExitCPPos][2], EXITCP_SIZE, -1, 0, -1, ENTERCP_DRAW);
  107.  
  108.         new str[100];
  109.         format(str, sizeof(str), "%s\nOwner: %s\nPrice: $%d", hInfo[x][Name], hInfo[x][Owner], hInfo[x][Price]);
  110.         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);
  111.     }
  112.     return 1;
  113. }
  114.  
  115. public OnFilterScriptExit()
  116. {
  117.     print("  House System v0.1 by PotH3Ad");
  118.    
  119.     for(new x=0; x<MAX_HOUSES; x++)
  120.     {
  121.         DestroyDynamicCP(hInfo[x][EnterCP]);
  122.         DestroyDynamicCP(hInfo[x][ExitCP]);
  123.         DestroyDynamicPickup(hInfo[x][Pickup]);
  124.         DestroyDynamicMapIcon(hInfo[x][MapIcon]);
  125.         DestroyDynamic3DTextLabel(hInfo[x][InfoLabel]);
  126.     }
  127.     return 1;
  128. }
  129.  
  130. CMD:hexit(playerid, params[])
  131. {
  132.     SetPVarInt(playerid, "BuildingHouse", 0);
  133.     return 1;
  134. }
  135.  
  136. CMD:hmenu(playerid, params[])
  137. {
  138.     if(!IsPlayerAdmin(playerid)) return 1;
  139.     if(BUILDINGHOUSE(playerid)) return 1;
  140.     ShowBuilderDialog(playerid);
  141.     return 1;
  142. }
  143.  
  144. CMD:hedit(playerid, params[])
  145. {
  146.     if(!BUILDINGHOUSE(playerid)) return 1;
  147.     ShowEditDialog(playerid);
  148.     return 1;
  149. }
  150.  
  151. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  152. {
  153.     if(dialogid == HOUSE_DIAG)
  154.     {
  155.         if(response)
  156.         {
  157.             switch(listitem)
  158.             {
  159.                 case 0:
  160.                 {
  161.                     new hid = GetLowestOpenSlot();
  162.                     SetPVarInt(playerid, "BuildingHouse", 1);
  163.                     format(hfile, sizeof(hfile), HOUSE_FILE, hid);
  164.                     dini_Create(hfile);
  165.                     dini_Set(hfile, "Builder", pName(playerid));
  166.                     SetPVarInt(playerid, "BuildID", hid);
  167.                     SendClientMessage(playerid, MSG_COLOR, "You are now building a house! {0000FF}(Tip: Use '/hedit' to access the edit menu.)");
  168.                 }
  169.                 case 1:
  170.                 {
  171.                     format(hstr, sizeof(hstr), "ID\tHouse Name\n");
  172.                     for(new x=0; x<MAX_HOUSES; x++)
  173.                     {
  174.                         format(hfile, sizeof(hfile), HOUSE_FILE, x);
  175.                         if(strlen(dini_Get(hfile, "Name")) > 0) format(hstr, sizeof(hstr), "%s%d\t%s\n", hstr, x, dini_Get(hfile, "Name"));
  176.                         else format(hstr, sizeof(hstr), "%s%d\tEmpty Slot\n", hstr, x);
  177.                     }
  178.                     ShowPlayerDialog(playerid, HOUSE_DIAG+1, DIALOG_STYLE_LIST, "Choose a house to edit", hstr, "Select", "Exit");
  179.                 }
  180.                 case 2:
  181.                 {
  182.                     format(hstr, sizeof(hstr), "ID\tHouse Name\n");
  183.                     for(new x=0; x<MAX_HOUSES; x++)
  184.                     {
  185.                         format(hfile, sizeof(hfile), HOUSE_FILE, x);
  186.                         if(strlen(dini_Get(hfile, "Name")) > 0) format(hstr, sizeof(hstr), "%s%d\t%s\n", hstr, x, dini_Get(hfile, "Name"));
  187.                         else format(hstr, sizeof(hstr), "%s%d\tEmpty Slot\n", hstr, x);
  188.                     }
  189.                     ShowPlayerDialog(playerid, HOUSE_DIAG+2, DIALOG_STYLE_LIST, "Delete a house", hstr, "Select", "Exit");
  190.                 }
  191.                 case 3:
  192.                 {
  193.                     format(hstr, sizeof(hstr), "ID\tHouse Name\n");
  194.                     for(new x=0; x<MAX_HOUSES; x++)
  195.                     {
  196.                         format(hfile, sizeof(hfile), HOUSE_FILE, x);
  197.                         if(strlen(dini_Get(hfile, "Name")) > 0) format(hstr, sizeof(hstr), "%s%d\t%s\n", hstr, x, dini_Get(hfile, "Name"));
  198.                         else format(hstr, sizeof(hstr), "%s%d\tEmpty Slot\n", hstr, x);
  199.                     }
  200.                     ShowPlayerDialog(playerid, HOUSE_DIAG+3, DIALOG_STYLE_LIST, "Select a house to view info", hstr, "Select", "Back");
  201.                 }
  202.             }
  203.         }
  204.     }
  205.     else if(dialogid == HOUSE_DIAG+1)
  206.     {
  207.         if(response)
  208.         {
  209.             format(hfile, sizeof(hfile), HOUSE_FILE, listitem-1);
  210.             if(!dini_Exists(hfile)) return OnDialogResponse(playerid, HOUSE_DIAG, 1, 1, "blank");
  211.             SetPVarInt(playerid, "BuildingHouse", 1);
  212.             SetPVarInt(playerid, "BuildID", listitem-1);
  213.         }
  214.         else ShowBuilderDialog(playerid);
  215.     }
  216.     else if(dialogid == HOUSE_DIAG+2)
  217.     {
  218.         if(response)
  219.         {
  220.             format(hfile, sizeof(hfile), HOUSE_FILE, listitem-1);
  221.             if(!dini_Exists(hfile)) return OnDialogResponse(playerid, HOUSE_DIAG, 1, 2, "blank");
  222.             dini_Remove(hfile);
  223.         }
  224.         else ShowBuilderDialog(playerid);
  225.     }
  226.     else if(dialogid == HOUSE_DIAG+3)
  227.     {
  228.         if(response)
  229.         {
  230.             #define hid listitem-1
  231.             format(hfile, sizeof(hfile), HOUSE_FILE, hid);
  232.             if(!dini_Exists(hfile)) return OnDialogResponse(playerid, HOUSE_DIAG, 1, 3, "blank");
  233.             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],
  234.             hid, hInfo[hid][Owner], dini_Get(hfile, "Builder"), hInfo[hid][Price], hInfo[hid][ForSale], hInfo[hid][Interior], hInfo[hid][World]);
  235.             ShowPlayerDialog(playerid, HOUSE_DIAG-1, DIALOG_STYLE_MSGBOX, "House Information", hstr, "Ok", "Exit");
  236.         }
  237.         else ShowBuilderDialog(playerid);
  238.     }
  239.     //Edit menu
  240.     else if(dialogid == HOUSE_DIAG+4)
  241.     {
  242.         if(response)
  243.         {
  244.             //"House Name\nPrice\nFor Sale\nInterior\nVirtual World\nEnter Position\nExit Position\nSpawn Position\nPickup Position\nLabel Position\nEnter Checkpoint\nExit Checkpoint"
  245.             switch(listitem)
  246.             {
  247.                 case 0:
  248.                 {
  249.                     ShowPlayerDialog(playerid, HOUSE_DIAG-1, DIALOG_STYLE_INPUT, "House Edit - House Name", hstr, "Update", "Cancel");
  250.                 }
  251.             }
  252.         }
  253.     }
  254.     return 0;
  255. }
  256.  
  257. stock ShowBuilderDialog(playerid)
  258. {
  259.     ShowPlayerDialog(playerid, HOUSE_DIAG, DIALOG_STYLE_LIST, "House Builder", "Build House\nEdit House\nDestroy House\nView House Info", "Select", "Exit");
  260. }
  261.  
  262. stock ShowEditDialog(playerid)
  263. {
  264.     ShowPlayerDialog(playerid, HOUSE_DIAG+4, DIALOG_STYLE_LIST, "House Builder - Edit", EDITSTR, "Select", "Exit");
  265. }
  266.  
  267. stock SetPlayerPosEx(playerid, Float:x, Float:y, Float:z, Float:angle, interior, world)
  268. {
  269.     SetPlayerPos(playerid, x, y, z);
  270.     SetPlayerFacingAngle(playerid, angle);
  271.     SetPlayerInterior(playerid, interior);
  272.     SetPlayerVirtualWorld(playerid, world);
  273. }
  274.  
  275. stock GetLowestOpenSlot()
  276. {
  277.     new num;
  278.     for(new x=0; x<MAX_HOUSES; x++)
  279.     {
  280.         format(hfile, sizeof(hfile), HOUSE_FILE, x);
  281.         if(!dini_Exists(hfile))
  282.         {
  283.             num = x;
  284.             break;
  285.         }
  286.     }
  287.     return num;
  288. }
  289.  
  290. stock pName(playerid)
  291. {
  292.     new aname[MAX_PLAYER_NAME];
  293.     GetPlayerName(playerid, aname, sizeof(aname));
  294.     return aname;
  295. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement