Advertisement
Guest User

Dynamic Housing - JonathanW

a guest
Jun 27th, 2014
4,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.95 KB | None | 0 0
  1. /*
  2.             | Walker's Dynamic Housing System - ENG - 0.3Z |
  3.                             | Copyright |
  4. */
  5. #include <a_samp>
  6. #include <sscanf2>
  7. #include <YSI\y_ini>
  8. #include <zcmd>
  9. #include <streamer>
  10. // ===============[COLORS]===================
  11. #define         COLOR_GREEN             0x008000FF
  12. #define         COLOR_YELLOW            0xECD400F6
  13. #define         COLOR_WHITE             0xFFFFFFFF
  14.  
  15. //===============[DEFINES]===================
  16. #define         MAX_HOUSES              300
  17. #define         SCM                SendClientMessage // Just for easy,not too important.
  18. #define         HOUSE_PATH          "/Houses/House %d.ini"
  19. #define         USER_PATH           "/Users/%s.ini"
  20. #define         DIALOG_HOUSE                1
  21. #define         SELLPERCENT             50 // This is the Total Percent of Money that you will get back on selling the House.
  22. #define PRESSED(%0) \
  23.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  24. // ==============[TEXTDRAWS]==================
  25. new Text:Statement;
  26. new Text:Box;
  27. new Text:boxtext;
  28. // Player Info (We're using only 1 Variable right now)
  29. enum pInfo
  30. {
  31.     HouseKey,
  32.     HouseID
  33. }
  34. new PlayerInfo[MAX_PLAYERS][pInfo];
  35. // House Info (There are 19 Variables here)
  36. enum hInfo
  37. {
  38.     Owner[32],
  39.     Owned,
  40.     Price,
  41.     Float: EnterX,
  42.     Float: EnterY,
  43.     Float: EnterZ,
  44.     Float: EnterA,
  45.     Float: ExitX,
  46.     Float: ExitY,
  47.     Float: ExitZ,
  48.     Float: ExitA,
  49.     EnterInt,
  50.     EnterVW,
  51.     ExitInt,
  52.     ExitVW,
  53.     Money,
  54.     Text3D: Label,
  55.     PickupID,
  56.     Locked
  57. }
  58. new HouseInfo[MAX_HOUSES][hInfo];
  59. new HouseTaken[MAX_HOUSES];
  60.  
  61. public OnFilterScriptExit()
  62. {
  63.     return 1;
  64. }
  65.  
  66. public OnFilterScriptInit()
  67. {
  68.     print("\n-----------------------------------------");
  69.     print("-Dynamic Housing System - ENG - JonathanW-");
  70.     print("------------------------------------------\n");
  71.     // Loading Houses
  72.     for(new i = 1; i < MAX_HOUSES; i++)
  73.     {
  74.         new gFile[35];
  75.         format(gFile, 35, HOUSE_PATH ,i);
  76.         if(fexist(gFile))
  77.         {
  78.             INI_ParseFile(gFile, "LoadHouse", .bExtra = true, .extra = i);
  79.             ReadHouse(i);
  80.         }
  81.     }
  82.     CreateTextdraws();
  83.     return 1;
  84. }
  85. //=============================[HOUSE FUNCTIONS]=============================
  86. // This is for Setting a House's Information
  87. stock ReadHouse(houseid)
  88. {
  89.     new string[512];
  90.     if(HouseInfo[houseid][Owned]) format(string, sizeof(string), "[House] {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", houseid,HouseInfo[houseid][Owner],HL(houseid));
  91.     else format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", houseid,HouseInfo[houseid][Price]);
  92.     HouseInfo[houseid][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 15);
  93.     HouseInfo[houseid][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 0, 0, -1, 40.0);
  94. }
  95. stock GetAvailableID()
  96. {
  97.     for(new i = 1; i<MAX_HOUSES; i++)
  98.     {
  99.         if(HouseTaken[i] == 0) return i;
  100.     }
  101.     return -1;
  102. }
  103. stock Showlock(playerid)
  104. {
  105.     new txdstring[128];
  106.     format(txdstring, sizeof(txdstring), "Locked");
  107.     TextDrawSetString(boxtext, txdstring);
  108.     TextDrawShowForPlayer(playerid, Box);
  109.     TextDrawShowForPlayer(playerid, boxtext);
  110.     SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  111.     return 1;
  112. }
  113. stock HL(houseid)
  114. {
  115.     new string[16];
  116.     if(HouseInfo[houseid][Locked] == 1) format(string, sizeof(string), "Locked");
  117.     else if(HouseInfo[houseid][Locked] == 0) format(string, sizeof(string), "Unlocked");
  118.     return string;
  119. }
  120. stock GetName(playerid)
  121. {
  122.     new name[MAX_PLAYER_NAME];
  123.     GetPlayerName(playerid,name,sizeof(name));
  124.     for(new i = 0; i < MAX_PLAYER_NAME; i++)
  125.     {
  126.         if(name[i] == '_') name[i] = ' ';
  127.     }
  128.     return name;
  129. }
  130. stock CreateTextdraws()
  131. {
  132.     Statement = TextDrawCreate(172.000000, 398.125000, "You have successfully ~g~purchased~w~ a house");
  133.     TextDrawLetterSize(Statement, 0.377500, 1.337500);
  134.     TextDrawAlignment(Statement, 1);
  135.     TextDrawColor(Statement, -1);
  136.     TextDrawSetShadow(Statement, 0);
  137.     TextDrawSetOutline(Statement, 1);
  138.     TextDrawBackgroundColor(Statement, 51);
  139.     TextDrawFont(Statement, 1);
  140.     TextDrawSetProportional(Statement, 1);
  141.  
  142.     Box = TextDrawCreate(100.500000, 210.187500, "usebox");
  143.     TextDrawLetterSize(Box, 0.000000, 2.034723);
  144.     TextDrawTextSize(Box, 19.000000, 0.000000);
  145.     TextDrawAlignment(Box, 1);
  146.     TextDrawColor(Box, 0);
  147.     TextDrawUseBox(Box, true);
  148.     TextDrawBoxColor(Box, -226);
  149.     TextDrawSetShadow(Box, 0);
  150.     TextDrawSetOutline(Box, 0);
  151.     TextDrawFont(Box, 0);
  152.  
  153.     boxtext = TextDrawCreate(35.500000, 212.625000, "~g~UNLOCKED");
  154.     TextDrawLetterSize(boxtext, 0.285499, 1.250000);
  155.     TextDrawAlignment(boxtext, 1);
  156.     TextDrawColor(boxtext, -1523963137);
  157.     TextDrawSetShadow(boxtext, 0);
  158.     TextDrawSetOutline(boxtext, 1);
  159.     TextDrawBackgroundColor(boxtext, 51);
  160.     TextDrawFont(boxtext, 1);
  161.     TextDrawSetProportional(boxtext, 1);
  162.     return 1;
  163. }
  164. stock SaveHouses()
  165. {
  166.     for(new i=1;i < MAX_HOUSES;i++)
  167.     {
  168.         if(HouseTaken[i] == 0) continue;
  169.  
  170.         new hFile[35];
  171.         format(hFile, 35, HOUSE_PATH, i);
  172.         new INI:File = INI_Open(hFile);
  173.         INI_SetTag(File, "House Data");
  174.         INI_WriteString(File, "Owner", HouseInfo[i][Owner]);
  175.         INI_WriteInt(File, "Owned", HouseInfo[i][Owned]);
  176.         INI_WriteInt(File, "Price", HouseInfo[i][Price]);
  177.         INI_WriteFloat(File, "EnterX", HouseInfo[i][EnterX]);
  178.         INI_WriteFloat(File, "EnterY", HouseInfo[i][EnterY]);
  179.         INI_WriteFloat(File, "EnterZ", HouseInfo[i][EnterZ]);
  180.         INI_WriteFloat(File, "EnterA", HouseInfo[i][EnterA]);
  181.         INI_WriteFloat(File, "ExitX", HouseInfo[i][ExitX]);
  182.         INI_WriteFloat(File, "ExitY", HouseInfo[i][ExitY]);
  183.         INI_WriteFloat(File, "ExitZ", HouseInfo[i][ExitZ]);
  184.         INI_WriteFloat(File, "ExitA", HouseInfo[i][ExitA]);
  185.         INI_WriteInt(File, "EnterInt", HouseInfo[i][EnterInt]);
  186.         INI_WriteInt(File, "EnterVW", HouseInfo[i][EnterVW]);
  187.         INI_WriteInt(File, "ExitInt", HouseInfo[i][ExitInt]);
  188.         INI_WriteInt(File, "ExitVW", HouseInfo[i][ExitVW]);
  189.         INI_WriteInt(File, "Money", HouseInfo[i][Money]);
  190.         INI_WriteInt(File, "PickupID", HouseInfo[i][PickupID]);
  191.         INI_WriteInt(File, "Locked", HouseInfo[i][Locked]);
  192.         INI_Close(File);
  193.      }
  194. }
  195. forward LoadHouse(id, name[], value[]);
  196. public LoadHouse(id, name[], value[])
  197. {
  198.     INI_String("Owner", HouseInfo[id][Owner],32);
  199.     INI_Int("Owned", HouseInfo[id][Owned]);
  200.     INI_Int("Price", HouseInfo[id][Price]);
  201.     INI_Float("EnterX", HouseInfo[id][EnterX]);
  202.     INI_Float("EnterY", HouseInfo[id][EnterY]);
  203.     INI_Float("EnterZ", HouseInfo[id][EnterZ]);
  204.     INI_Float("EnterA", HouseInfo[id][EnterA]);
  205.     INI_Float("ExitX", HouseInfo[id][ExitX]);
  206.     INI_Float("ExitY", HouseInfo[id][ExitY]);
  207.     INI_Float("ExitZ", HouseInfo[id][ExitZ]);
  208.     INI_Float("ExitA", HouseInfo[id][ExitA]);
  209.     INI_Int("EnterInt", HouseInfo[id][EnterInt]);
  210.     INI_Int("EnterVW", HouseInfo[id][EnterVW]);
  211.     INI_Int("ExitInt", HouseInfo[id][ExitInt]);
  212.     INI_Int("ExitVW", HouseInfo[id][ExitVW]);
  213.     INI_Int("Money", HouseInfo[id][Money]);
  214.     INI_Int("PickupID", HouseInfo[id][PickupID]);
  215.     INI_Int("Locked", HouseInfo[id][Locked]);
  216.     HouseTaken[id] = 1;
  217.     return 1;
  218. }
  219. stock SaveUser(playerid)
  220. {
  221.     new File[35];
  222.     format(File, 35, USER_PATH, GetName(playerid));
  223.     new INI:f = INI_Open(File);
  224.     INI_SetTag(f, "Player Data");
  225.     INI_WriteInt(f, "HouseID", PlayerInfo[playerid][HouseID]);
  226.     INI_WriteInt(f, "HouseKey", PlayerInfo[playerid][HouseKey]);
  227.     INI_Close(f);
  228. }
  229. forward LoadUser(playerid, name[], value[]);
  230. public LoadUser(playerid, name[], value[])
  231. {
  232.     INI_Int("HouseID",PlayerInfo[playerid][HouseID]);
  233.     INI_Int("HouseKey",PlayerInfo[playerid][HouseKey]);
  234.     return 1;
  235. }
  236. // ====================================[COMMANDS]=================================
  237. CMD:hhelp(playerid, params[]) return cmd_househelp(playerid, params);
  238. CMD:help(playerid, params[]) return cmd_househelp(playerid, params);
  239. CMD:househelp(playerid, params[])
  240. {
  241.     SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}==================[HOUSE COMMANDS]===============");
  242.     SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ADMIN]: {FFFFFF}/createhouse /deletehouse /edithloc /edithprice");
  243.     SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[PLAYER] {FFFFFF}/buy /sell /lock /putmoney /takemoney");
  244.     SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[EXTRA]: {FFFFFF}/saveme /loadme");
  245.     return 1;
  246. }
  247. CMD:createhouse(playerid, params[])
  248. {
  249.     new type[128], string[256];
  250.     new id = GetAvailableID();
  251.     if(sscanf(params, "s[128]",type))
  252.     {
  253.         SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/createhouse [Level]");
  254.         SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[OPTIONS]{FFFFFF}|| L1 - L2 - L3 - L4 ||");
  255.         return 1;
  256.     }
  257.     if(!strcmp(type, "l1", true, 2))
  258.     {
  259.         HouseInfo[id][EnterX] = 2308.8;
  260.         HouseInfo[id][EnterY] = -1212.8;
  261.         HouseInfo[id][EnterZ] = 1049.0;
  262.         HouseInfo[id][EnterInt] = 6;
  263.     }
  264.     if(!strcmp(type, "l2", true, 2))
  265.     {
  266.         HouseInfo[id][EnterX] = 260.7;
  267.         HouseInfo[id][EnterY] = 1237.5;
  268.         HouseInfo[id][EnterZ] = 1084.2;
  269.         HouseInfo[id][EnterInt] = 9;
  270.     }
  271.     if(!strcmp(type, "l3", true, 2))
  272.     {
  273.         HouseInfo[id][EnterX] = 2365.2;
  274.         HouseInfo[id][EnterY] = -1135.4;
  275.         HouseInfo[id][EnterZ] = 1050.8;
  276.         HouseInfo[id][EnterInt] = 8;
  277.     }
  278.     if(!strcmp(type, "l4", true, 2))
  279.     {
  280.         HouseInfo[id][EnterX] = 2270.1;
  281.         HouseInfo[id][EnterY] = -1210.4;
  282.         HouseInfo[id][EnterZ] = 1047.5;
  283.         HouseInfo[id][EnterInt] = 10;
  284.     }
  285.     // Setting House Information
  286.     new Float: Pos[3];
  287.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  288.     HouseTaken[id] = 1;
  289.     HouseInfo[id][Owned] = 0;
  290.     HouseInfo[id][ExitX] = Pos[0];
  291.     HouseInfo[id][ExitY] = Pos[1];
  292.     HouseInfo[id][ExitZ] = Pos[2];
  293.     HouseInfo[id][ExitInt] = GetPlayerInterior(playerid);
  294.     HouseInfo[id][ExitVW] = GetPlayerVirtualWorld(playerid);
  295.     HouseInfo[id][EnterVW] = GetPlayerVirtualWorld(playerid)+250;
  296.     HouseInfo[id][Price] = 9999999;
  297.     // Visually,creating the House
  298.     format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", id,HouseInfo[id][Price]);
  299.     HouseInfo[id][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  300.     HouseInfo[id][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 0, 0, -1, 40.0);
  301.  
  302.     // Saving
  303.     SaveHouses();
  304.     return 1;
  305. }
  306. CMD:deletehouse(playerid, params[])
  307. {
  308.     new houseid,string[128];
  309.     if(sscanf(params, "d", houseid))
  310.     {
  311.         SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/deletehouse [houseid]");
  312.         return 1;
  313.     }
  314.     if(houseid < 1 || houseid > MAX_HOUSES)
  315.     {
  316.         format(string, sizeof(string), "{2F70D0}[ERROR]:{FFFFFF}House ID cannot be below 0 and above %d.", MAX_HOUSES);
  317.         SendClientMessage(playerid, COLOR_WHITE, string);
  318.         return 1;
  319.     }
  320.     DestroyDynamic3DTextLabel(HouseInfo[houseid][Label]);
  321.     DestroyDynamicPickup(HouseInfo[houseid][PickupID]);
  322.     new file[128];
  323.     // House Information
  324.     HouseInfo[houseid][Owned] = 0;
  325.     HouseInfo[houseid][Price] = 0;
  326.     HouseInfo[houseid][EnterX] = 0.0;
  327.     HouseInfo[houseid][EnterY] = 0.0;
  328.     HouseInfo[houseid][EnterZ] = 0.0;
  329.     HouseInfo[houseid][EnterA] = 0.0;
  330.     HouseInfo[houseid][ExitX] = 0.0;
  331.     HouseInfo[houseid][ExitY] = 0.0;
  332.     HouseInfo[houseid][ExitZ] = 0.0;
  333.     HouseInfo[houseid][ExitA] = 0.0;
  334.     HouseInfo[houseid][PickupID] = 0;
  335.     HouseInfo[houseid][Locked] = 0;
  336.     HouseTaken[houseid] = 0;
  337.     // Deleting the House From ScriptFiles.
  338.     format(file, sizeof(file), HOUSE_PATH, houseid);
  339.     if(fexist(file)) fremove(file);
  340.     return 1;
  341. }
  342. CMD:edithloc(playerid, params[])
  343. {
  344.     new string[128],houseid;
  345.     if(sscanf(params, "d", houseid)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/edithloc [houseid]");
  346.     // Setting House Information
  347.     new Float:X, Float:Y, Float:Z;
  348.     GetPlayerPos(playerid, X, Y, Z);
  349.     HouseInfo[houseid][ExitX] = X;
  350.     HouseInfo[houseid][ExitY] = Y;
  351.     HouseInfo[houseid][ExitZ] = Z;
  352.     HouseInfo[houseid][ExitInt] = GetPlayerInterior(playerid);
  353.     HouseInfo[houseid][ExitVW] = GetPlayerVirtualWorld(playerid);
  354.     DestroyDynamicPickup(HouseInfo[houseid][PickupID]);
  355.     DestroyDynamic3DTextLabel(HouseInfo[houseid][Label]);
  356.     HouseInfo[houseid][PickupID] = 0;
  357.     // Updating the Pickup
  358.     if(HouseInfo[houseid][Owned])
  359.     {
  360.         format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", houseid,HouseInfo[houseid][Owner],HL(houseid));
  361.     }
  362.     else
  363.     {
  364.         format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", houseid,HouseInfo[houseid][Price]);
  365.     }
  366.     HouseInfo[houseid][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 15);
  367.     HouseInfo[houseid][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 0, 0, -1, 40.0);
  368.     // Saving
  369.     SaveHouses();
  370.     return 1;
  371. }
  372. CMD:edithprice(playerid, params[])
  373. {
  374.     new string[128],houseid,price;
  375.     if(sscanf(params, "dd", houseid,price)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/edithprice [houseid] [price]");
  376.     // Setting House Information
  377.     HouseInfo[houseid][Price] = price;
  378.     DestroyDynamicPickup(HouseInfo[houseid][PickupID]);
  379.     HouseInfo[houseid][PickupID] = 0;
  380.     DestroyDynamic3DTextLabel(HouseInfo[houseid][Label]);
  381.     // Updating the Pickup
  382.     format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", houseid,HouseInfo[houseid][Price]);
  383.     HouseInfo[houseid][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 15);
  384.     HouseInfo[houseid][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 0, 0, -1, 40.0);
  385.     // Saving
  386.     SaveHouses();
  387.     return 1;
  388. }
  389. CMD:lock(playerid, params[])
  390. {
  391.     new id;
  392.     new txdstring[128];
  393.     if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]: {FFFFFF}You don't own a House that you can lock.");
  394.     // Getting the House ID
  395.     if(PlayerInfo[playerid][HouseID])
  396.     {
  397.         id = PlayerInfo[playerid][HouseID];
  398.     }
  399.     // Locking/Unlocking
  400.     if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[id][ExitX],HouseInfo[id][ExitY],HouseInfo[id][ExitZ]) || IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[id][EnterX],HouseInfo[id][EnterY],HouseInfo[id][EnterY]))
  401.     {
  402.         if(HouseInfo[id][Locked] == 0)
  403.         {
  404.             new string[128];
  405.             HouseInfo[id][Locked] = 1;
  406.             // Textdraw
  407.             format(txdstring, sizeof(txdstring), "Locked");
  408.             TextDrawSetString(boxtext, txdstring);
  409.             TextDrawShowForPlayer(playerid, Box);
  410.             TextDrawShowForPlayer(playerid, boxtext);
  411.             SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  412.             // Pickup
  413.             DestroyDynamic3DTextLabel(HouseInfo[id][Label]);
  414.             format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", id,HouseInfo[id][Owner],HL(id));
  415.             HouseInfo[id][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  416.             return 1;
  417.         }
  418.         else
  419.         {
  420.             new string[128];
  421.             HouseInfo[id][Locked] = 0;
  422.             // Textdraw
  423.             format(txdstring, sizeof(txdstring), "Unlocked");
  424.             TextDrawSetString(boxtext, txdstring);
  425.             TextDrawShowForPlayer(playerid, Box);
  426.             TextDrawShowForPlayer(playerid, boxtext);
  427.             SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  428.             // Pickup
  429.             DestroyDynamic3DTextLabel(HouseInfo[id][Label]);
  430.             format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", id,HouseInfo[id][Owner],HL(id));
  431.             HouseInfo[id][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  432.             return 1;
  433.         }
  434.     }
  435.     return 1;
  436. }
  437. CMD:buy(playerid, params[])
  438. {
  439.     new string[256],buy;
  440.     new txdstring[128];
  441.     if(PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You already own a House.");
  442.     for(new idx=1; idx < MAX_HOUSES; idx++)
  443.     {
  444.         if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[idx][ExitX], HouseInfo[idx][ExitY], HouseInfo[idx][ExitZ]))
  445.         {
  446.             if(!HouseInfo[idx][Owned])
  447.             {
  448.                 if(GetPlayerMoney(playerid) < HouseInfo[idx][Price]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You cannot afford to purchase this house.");
  449.                 GivePlayerMoney(playerid, -HouseInfo[idx][Price]);
  450.                 PlayerInfo[playerid][HouseKey] = 1;
  451.                 PlayerInfo[playerid][HouseID] = idx;
  452.                 HouseInfo[idx][Owned] = 1;
  453.                 format(HouseInfo[idx][Owner], 32, "%s", GetName(playerid));
  454.                 SendClientMessage(playerid, COLOR_GREEN, "{2F70D0}[INFO]:{FFFFFF} Welcome to your new Home.For more Information,use /househelp.");
  455.                 // Textdraw
  456.                 format(txdstring, sizeof(txdstring), "You have successfully ~g~purchased~w~ a house");
  457.                 TextDrawSetString(Statement, txdstring);
  458.                 TextDrawShowForPlayer(playerid, Statement);
  459.                 SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  460.                 // Pickup
  461.                 DestroyDynamic3DTextLabel(HouseInfo[idx][Label]);
  462.                 HouseInfo[idx][PickupID] = 0;
  463.                 format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", idx,HouseInfo[idx][Owner],HL(idx));
  464.                 HouseInfo[idx][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[idx][ExitX], HouseInfo[idx][ExitY], HouseInfo[idx][ExitZ], 15);
  465.                 HouseInfo[idx][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[idx][ExitX], HouseInfo[idx][ExitY], HouseInfo[idx][ExitZ], 0, 0, -1, 40.0);
  466.                 idx = MAX_HOUSES;
  467.                 // Saving
  468.                 SaveHouses();
  469.                 buy = 1;
  470.             }
  471.             if(idx == MAX_HOUSES-1 && !buy)
  472.             {
  473.                 SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} This house is owned by someone else.");
  474.             }
  475.         }
  476.         if(idx == MAX_HOUSES-1 && !buy)
  477.         {
  478.             SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You are not near a House you can buy.");
  479.             return 1;
  480.         }
  481.     }
  482.     return 1;
  483. }
  484. CMD:sell(playerid, params[])
  485. {
  486.     new string[128],txdstring[128];
  487.     if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You do not own a House that you can sell.");
  488.     {
  489.         new id = PlayerInfo[playerid][HouseID];
  490.         if(!IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[PlayerInfo[playerid][HouseID]][ExitX], HouseInfo[PlayerInfo[playerid][HouseID]][ExitY], HouseInfo[PlayerInfo[playerid][HouseID]][ExitZ])) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You are not near your House.");
  491.         new string2[128];
  492.         new price = HouseInfo[id][Price];
  493.         new percent = SELLPERCENT*price/100;
  494.         GivePlayerMoney(playerid, percent);
  495.         // Textdraw
  496.         format(txdstring, sizeof(txdstring), "You have successfully ~g~sold~w~ your house for $%d.",percent);
  497.         TextDrawSetString(Statement, txdstring);
  498.         TextDrawShowForPlayer(playerid, Statement);
  499.         SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  500.         // Setting the Information
  501.         HouseInfo[id][Owned] = 0;
  502.         HouseInfo[id][Locked] = 0;
  503.         format(HouseInfo[PlayerInfo[playerid][HouseID]][Owner], 32, "Government");
  504.         format(string, sizeof(string), "{2F70D0}[INFO]: {FFFFFF}You have sold your House for $%d.", percent);
  505.         SendClientMessage(playerid, COLOR_WHITE, string);
  506.         DestroyDynamic3DTextLabel(HouseInfo[id][Label]);
  507.  
  508.         format(string2, sizeof(string2), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", id,HouseInfo[id][Price]);
  509.         HouseInfo[id][Label] = CreateDynamic3DTextLabel(string2, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  510.  
  511.         PlayerInfo[playerid][HouseKey] = 0;
  512.         PlayerInfo[playerid][HouseID] = 0;
  513.     }
  514.     return 1;
  515. }
  516. CMD:putmoney(playerid, params[])
  517. {
  518.     new txdstring[128];
  519.     new amount;
  520.     new i = PlayerInfo[playerid][HouseID];
  521.     if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You do not own a House.");
  522.     {
  523.         if(sscanf(params, "i", amount)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX]:{FFFFFF} /putmoney [amount]");
  524.         if(GetPlayerMoney(playerid) < amount) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You don't have that much money on you right now.");
  525.         // Adding the money to the House's Vault.
  526.         HouseInfo[i][Money] += amount;
  527.         // Deducting the Money from the Player
  528.         GivePlayerMoney(playerid, -amount);
  529.         // Textdraw
  530.         format(txdstring, sizeof(txdstring), "You have ~g~deposited~w~ $%d in your house's vault",amount);
  531.         TextDrawSetString(Statement, txdstring);
  532.         TextDrawShowForPlayer(playerid, Statement);
  533.         SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  534.     }
  535.     return 1;
  536. }
  537. CMD:takemoney(playerid, params[])
  538. {
  539.     new txdstring[128];
  540.     new amount;
  541.     new i = PlayerInfo[playerid][HouseID];
  542.     if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You do not own a House.");
  543.     {
  544.         if(sscanf(params, "i", amount)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX]:{FFFFFF} /takemoney [amount]");
  545.         if(HouseInfo[i][Money] < amount) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You don't have that much money in your House's Vault right now.");
  546.         // Adding the money to the House's Vault.
  547.         HouseInfo[i][Money] -= amount;
  548.         // Deducting the Money from the Player
  549.         GivePlayerMoney(playerid, amount);
  550.         // Textdraw
  551.         format(txdstring, sizeof(txdstring), "You have ~g~taken~w~ $%d from your house's vault",amount);
  552.         TextDrawSetString(Statement, txdstring);
  553.         TextDrawShowForPlayer(playerid, Statement);
  554.         SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  555.     }
  556.     return 1;
  557. }
  558. CMD:sethmoney(playerid, params[])
  559. {
  560.     new amount,houseid;
  561.     new txdstring[128];
  562.     if(sscanf(params, "ii", houseid,amount)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX]:{FFFFFF} /sethmoney [houseid] [amount]");
  563.     HouseInfo[houseid][Money] = amount;
  564.     // Textdraw
  565.     format(txdstring, sizeof(txdstring), "You have set ~g~House(%d)'s money~w~ to $%d.",houseid,amount);
  566.     TextDrawSetString(Statement, txdstring);
  567.     TextDrawShowForPlayer(playerid, Statement);
  568.     SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  569.     return 1;
  570. }
  571. // Extra
  572. CMD:saveme(playerid, params[])
  573. {
  574.     SaveUser(playerid);
  575.     SaveHouses();
  576.     return 1;
  577. }
  578. CMD:loadme(playerid, params[])
  579. {
  580.     new File[35];
  581.     format(File, 35, USER_PATH, GetName(playerid));
  582.     {
  583.         INI_ParseFile(File, "LoadUser", .bExtra = true, .extra = playerid);
  584.     }
  585.     return 1;
  586. }
  587. // ====================================[END OF COMMANDS]=================================
  588. forward HideTextdraws(playerid);
  589. public HideTextdraws(playerid)
  590. {
  591.     TextDrawHideForPlayer(playerid, Statement);
  592.     TextDrawHideForPlayer(playerid, Box);
  593.     TextDrawHideForPlayer(playerid, boxtext);
  594.     return 1;
  595. }
  596. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  597. {
  598.     if (PRESSED( KEY_SECONDARY_ATTACK ))
  599.     {
  600.         for(new i = 1; i < sizeof(HouseInfo); i++)
  601.         {
  602.             if(IsPlayerInRangeOfPoint(playerid,4.0,HouseInfo[i][ExitX],HouseInfo[i][ExitY],HouseInfo[i][ExitZ]))
  603.             {
  604.                 if(HouseInfo[i][Locked] == 1) return Showlock(playerid);
  605.                 if(HouseInfo[i][EnterX] == 0) return SendClientMessage(playerid, COLOR_WHITE, "[WARNING] This house has no Interior set up yet.");
  606.                 SetPlayerPos(playerid, HouseInfo[i][EnterX],HouseInfo[i][EnterY],HouseInfo[i][EnterZ]);
  607.                 SetPlayerInterior(playerid, HouseInfo[i][EnterInt]);
  608.                 SetPlayerVirtualWorld(playerid, HouseInfo[i][EnterVW]);
  609.             }
  610.             else if(IsPlayerInRangeOfPoint(playerid,4.0,HouseInfo[i][EnterX],HouseInfo[i][EnterY],HouseInfo[i][EnterZ]))
  611.             {
  612.                 SetPlayerPos(playerid, HouseInfo[i][ExitX],HouseInfo[i][ExitY],HouseInfo[i][ExitZ]);
  613.                 SetPlayerInterior(playerid, HouseInfo[i][ExitInt]);
  614.                 SetPlayerVirtualWorld(playerid, HouseInfo[i][ExitVW]);
  615.             }
  616.         }
  617.     }
  618.     return 1;
  619. }
  620.  
  621. public OnPlayerConnect(playerid)
  622. {
  623.     new File[35];
  624.     format(File, 35, USER_PATH, GetName(playerid));
  625.     {
  626.         INI_ParseFile(File, "LoadUser", .bExtra = true, .extra = playerid);
  627.     }
  628.     return 1;
  629. }
  630. public OnPlayerDisconnect(playerid, reason)
  631. {
  632.     SaveUser(playerid);
  633.     return 1;
  634. }
  635.  
  636. public OnPlayerSpawn(playerid)
  637. {
  638.     return 1;
  639. }
  640.  
  641. public OnPlayerText(playerid, text[])
  642. {
  643.     return 1;
  644. }
  645. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  646. {
  647.     return 1;
  648. }
  649.  
  650. public OnPlayerExitVehicle(playerid, vehicleid)
  651. {
  652.     return 1;
  653. }
  654.  
  655. public OnPlayerStateChange(playerid, newstate, oldstate)
  656. {
  657.     return 1;
  658. }
  659.  
  660. public OnRconCommand(cmd[])
  661. {
  662.     return 1;
  663. }
  664.  
  665. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  666. {
  667.     return 1;
  668. }
  669.  
  670. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  671. {
  672.     return 1;
  673. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement