Advertisement
ShomyScript

Untitled

May 5th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. #include < a_samp >
  2. #include < dini2 >
  3. #include < YSI\y_hooks >
  4. #include < YSI\y_commands >
  5.  
  6. #define MAX_HOUSES 1000
  7.  
  8. forward OnHouseCreate(houseid);
  9. forward OnHouseDelete(houseid);
  10. forward OnPlayerEnterHouse(playerid, houseid);
  11. forward OnPlayerExitHouse(playerid, houseid);
  12. forward OnPlayerBuyHouse(playerid, houseid);
  13. forward OnPlayerSellHouse(playerid, houseid);
  14.  
  15. enum HOUSE_INFO {
  16.  
  17. Float:hX,
  18. Float:hY,
  19. Float:hZ,
  20. Float:hIntX,
  21. Float:hIntY,
  22. Float:hIntZ,
  23. hPrice,
  24. hEntvw,
  25. hIntvw,
  26. hIntid,
  27. hType,
  28. hOutintid,
  29. bool:hLocked,
  30. Houseid,
  31. bool:hSold,
  32. hOwner[ MAX_PLAYER_NAME ],
  33. Housepickup
  34. }
  35. enum PLAYER_INFO {
  36.  
  37. hOwnHouse
  38. }
  39. enum {
  40.  
  41. DIALOG_HOUSE,
  42. DIALOG_HOUSEINFO
  43. }
  44.  
  45. new HouseInfo[ MAX_HOUSES ][ HOUSE_INFO ], Text3D:HouseLabel[ sizeof(HouseInfo) ], PlayerInfo[ MAX_PLAYERS ][ PLAYER_INFO ];
  46.  
  47. hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  48.  
  49. if(newkeys == KEY_SECONDARY_ATTACK) {
  50. for(new i; i < MAX_HOUSES; i++) {
  51. if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[ i ][ hX ], HouseInfo[ i ][ hY ], HouseInfo[ i ][ hZ ])) {
  52. if(!strcmp(GetName( playerid ), HouseInfo[ i ][ hOwner ], true)) {
  53. SetPlayerPos(playerid, HouseInfo[ i ][ hIntX ], HouseInfo[ i ][ hIntY ], HouseInfo[ i ][ hIntZ ]);
  54. SetPlayerVirtualWorld(playerid, HouseInfo[ i ][ hIntvw ]);
  55. SetPlayerInterior(playerid, HouseInfo[ i ][ hIntid ]);
  56. CallLocalFunction("OnPlayerEnterHouse", "dd", playerid, i);
  57. }
  58. else {
  59. if(HouseInfo[ i ][ hLocked ]) return SendClientMessage(playerid, -1, "Locked.");
  60. SetPlayerPos(playerid, HouseInfo[ i ][ hIntX ], HouseInfo[ i ][ hIntY ], HouseInfo[ i ][ hIntZ ]);
  61. SetPlayerVirtualWorld(playerid, HouseInfo[ i ][ hIntvw ]);
  62. SetPlayerInterior(playerid, HouseInfo[ i ][ hIntid ]);
  63. CallLocalFunction("OnPlayerEnterHouse", "dd", playerid, i);
  64. }
  65. }
  66. else if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[ i ][ hIntX ], HouseInfo[ i ][ hIntY ], HouseInfo[ i ][ hIntZ ])) {
  67. SetPlayerPos(playerid, HouseInfo[ i ][ hX ], HouseInfo[ i ][ hY ], HouseInfo[ i ][ hZ ]);
  68. SetPlayerVirtualWorld(playerid, HouseInfo[ i ][ hEntvw ]);
  69. SetPlayerInterior(playerid, HouseInfo[ i ][ hOutintid ]);
  70. CallLocalFunction("OnPlayerExitHouse", "dd", playerid, i);
  71. }
  72. }
  73. }
  74. return 1;
  75. }
  76. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  77.  
  78. switch(dialogid) {
  79. case DIALOG_HOUSE: {
  80. if(!response) return 0;
  81. new i = PlayerInfo[ playerid ][ hOwnHouse ];
  82. switch(listitem) {
  83. case 0: {
  84. new str[ 100 ];
  85. if(HouseInfo[ i ][ hType ] == 1) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Small house", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
  86. else if(HouseInfo[ i ][ hType ] == 2) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Medium house", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
  87. else if(HouseInfo[ i ][ hType ] == 3) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Big house", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
  88. else if(HouseInfo[ i ][ hType ] == 4) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Villa", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
  89. ShowPlayerDialog(playerid, DIALOG_HOUSEINFO, DIALOG_STYLE_MSGBOX, "House Info", str, "Exit","");
  90. }
  91. case 1: {
  92. if(HouseInfo[ i ][ hLocked ]) { HouseInfo[ i ][ hLocked ] = false; SendClientMessage(playerid, -1, "Unlocked."); }
  93. else { HouseInfo[ i ][ hLocked ] = true; SendClientMessage(playerid, -1, "Locked."); }
  94. }
  95. case 2: {
  96. new str[ 100 ], str1[ 24 ];
  97. GivePlayerMoney(playerid, HouseInfo[ i ][ hPrice ]/2);
  98. if(HouseInfo[ i ][ hType ] == 1) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Small house\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
  99. else if(HouseInfo[ i ][ hType ] == 2) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Medium house\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
  100. else if(HouseInfo[ i ][ hType ] == 3) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Big house\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
  101. else if(HouseInfo[ i ][ hType ] == 4) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Villa\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
  102. Update3DTextLabelText(HouseLabel[ i ], 0x00FF59AA, str);
  103. HouseInfo[ i ][ hSold ] = false;
  104. format(str1, sizeof(str1), "No-one");
  105. HouseInfo[ i ][ hOwner ] = str1;
  106. HouseInfo[ i ][ hLocked ] = true;
  107. CallLocalFunction("OnPlayerSellHouse", "dd", playerid, i);
  108. }
  109. }
  110. }
  111. }
  112. return 1;
  113. }
  114.  
  115. stock CreateHouse(houseid, Float:entX, Float:entY, Float:entZ, Float:intX, Float:intY, Float:intZ, entvw, intvw, intid, outintid, price, type) {
  116.  
  117. new str[ 100 ];
  118. if(type == 1) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Small house\n/buyhouse", houseid, price); }
  119. else if(type == 2) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Medium house\n/buyhouse", houseid, price); }
  120. else if(type == 3) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Big house\n/buyhouse", houseid, price); }
  121. else if(type == 4) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Villa\n/buyhouse", houseid, price); }
  122. HouseLabel[ houseid ] = Create3DTextLabel(str, 0x00FF59AA, entX, entY, entZ, 10.0, entvw, 0);
  123. HouseInfo[ houseid ][ Housepickup ] = CreatePickup(1273, 1, entX, entY, entZ, entvw);
  124.  
  125. HouseInfo[ houseid ][ hX ] = entX;
  126. HouseInfo[ houseid ][ hY ] = entY;
  127. HouseInfo[ houseid ][ hZ ] = entZ;
  128. HouseInfo[ houseid ][ hIntX ] = intX;
  129. HouseInfo[ houseid ][ hIntY ] = intY;
  130. HouseInfo[ houseid ][ hIntZ ] = intZ;
  131. HouseInfo[ houseid ][ hPrice ] = price;
  132. HouseInfo[ houseid ][ hEntvw ] = entvw;
  133. HouseInfo[ houseid ][ hIntvw ] = intvw;
  134. HouseInfo[ houseid ][ hIntid ] = intid;
  135. HouseInfo[ houseid ][ hOutintid ] = outintid;
  136. HouseInfo[ houseid ][ Houseid ] = houseid;
  137. HouseInfo[ houseid ][ hType ] = type;
  138. HouseInfo[ houseid ][ hLocked ] = true;
  139. new str1[ 24 ];
  140. format(str1, sizeof(str1), "No-one");
  141. HouseInfo[ houseid ][ hOwner ] = str1;
  142.  
  143. CallLocalFunction("OnHouseCreate", "d", houseid);
  144.  
  145. return 1;
  146. }
  147.  
  148. stock DeleteHouse(houseid) {
  149.  
  150. Delete3DTextLabel(HouseLabel[ houseid ]);
  151. DestroyPickup(HouseInfo[ houseid ][ Housepickup ]);
  152.  
  153. HouseInfo[ houseid ][ hX ] = 0;
  154. HouseInfo[ houseid ][ hY ] = 0;
  155. HouseInfo[ houseid ][ hZ ] = 0;
  156. HouseInfo[ houseid ][ hIntX ] = 0;
  157. HouseInfo[ houseid ][ hIntY ] = 0;
  158. HouseInfo[ houseid ][ hIntZ ] = 0;
  159. HouseInfo[ houseid ][ hPrice ] = 0;
  160. HouseInfo[ houseid ][ hEntvw ] = 0;
  161. HouseInfo[ houseid ][ hIntvw ] = 0;
  162. HouseInfo[ houseid ][ hIntid ] = 0;
  163. HouseInfo[ houseid ][ hOutintid ] = 0;
  164. HouseInfo[ houseid ][ hType ] = 0;
  165.  
  166. CallLocalFunction("OnHouseDelete", "d", houseid);
  167.  
  168. return 1;
  169. }
  170. stock GetName( playerid ) {
  171. new pname[ MAX_PLAYER_NAME ];
  172. GetPlayerName(playerid, pname, sizeof(pname));
  173. return pname;
  174. }
  175.  
  176.  
  177. YCMD:buyhouse(playerid, params[], help) {
  178.  
  179. #pragma unused help
  180. #pragma unused params
  181.  
  182. for(new i; i < MAX_HOUSES; i++) {
  183. if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[ i ][ hX ], HouseInfo[ i ][ hY ], HouseInfo[ i ][ hZ ])) {
  184. new str[ 115 ], pname[ MAX_PLAYER_NAME ];
  185. if(HouseInfo[ i ][ hSold ]) return SendClientMessage(playerid, -1, "That house is bought.");
  186. if(GetPlayerMoney(playerid) < HouseInfo[ i ][ hPrice ]) return SendClientMessage(playerid, -1, "You don't have enought money.");
  187. HouseInfo[ i ][ hSold ] = true;
  188. GetPlayerName(playerid, pname, sizeof(pname));
  189. HouseInfo[ i ][ hOwner ] = pname;
  190. Update3DTextLabelText(HouseLabel[ i ], 0x00FF59AA, str);
  191. GivePlayerMoney(playerid, -HouseInfo[ i ][ hPrice ]);
  192. PlayerInfo[ playerid ][ hOwnHouse ] = i;
  193. if(HouseInfo[ i ][ hType ] == 1) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Small house", pname, i, HouseInfo[ i ][ hPrice ]); }
  194. else if(HouseInfo[ i ][ hType ] == 2) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Medium house", pname, i, HouseInfo[ i ][ hPrice ]); }
  195. else if(HouseInfo[ i ][ hType ] == 3) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Big house", pname, i, HouseInfo[ i ][ hPrice ]); }
  196. else if(HouseInfo[ i ][ hType ] == 4) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Villa", pname, i, HouseInfo[ i ][ hPrice ]); }
  197. Update3DTextLabelText(HouseLabel[ i ], 0x00FF59AA, str);
  198. CallLocalFunction("OnPlayerBuyHouse", "dd", playerid, i);
  199. }
  200. }
  201. return 1;
  202. }
  203. YCMD:house(playerid, params[], help) {
  204.  
  205. #pragma unused help
  206. #pragma unused params
  207.  
  208. if(PlayerInfo[ playerid ][ hOwnHouse ] == 0) return SendClientMessage(playerid, -1, "You don't have house.");
  209. ShowPlayerDialog(playerid, DIALOG_HOUSE, DIALOG_STYLE_LIST, "HOUSE","House Info\nLock house\nSell House","Choose","Quit");
  210. return 1;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement