Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.58 KB | None | 0 0
  1. #include < a_samp >
  2. #include < YSI\y_ini >
  3. #include < zcmd >
  4. #include < sscanf2 >
  5.  
  6. #define MAX_RENTS 30
  7. #define RENT_FILE "/Rent/%d.ini"
  8.  
  9. enum {
  10. DIALOG_RENT,
  11. DIALOG_RENTVREME
  12. }
  13.  
  14. enum RENT_INFO {
  15.  
  16. Float:rentX,
  17. Float:rentY,
  18. Float:rentZ,
  19. Text3D:RentLabel,
  20. rentID
  21. }
  22.  
  23. new RentInfo[ MAX_RENTS ][ RENT_INFO ], IznajmioVozilo[ MAX_PLAYERS ], RentVeh[ MAX_PLAYERS ], RentOdabir[ MAX_PLAYERS ],
  24. RentVreme[ MAX_PLAYERS ], RentTimer[ MAX_PLAYERS ], Text3D:RentVehLabel[ MAX_VEHICLES ], TipVozila[ MAX_VEHICLES ];
  25.  
  26. public OnGameModeInit() {
  27.  
  28. for(new i; i < MAX_RENTS; i++) {
  29. new jFile[ 50 ];
  30. format(jFile, sizeof(jFile), RENT_FILE, i);
  31. if(fexist(jFile)) {
  32. INI_ParseFile(jFile, "LoadRent", .bExtra = true, .extra = i);
  33. RentInfo[ i ][ rentID ] = CreatePickup(19132, 1, RentInfo[ i ][ rentX ], RentInfo[ i ][ rentY ], RentInfo[ i ][ rentZ ], 0);
  34. RentInfo[ i ][ RentLabel ] = Create3DTextLabel("[ RENT ]\n{FFFFFF}Da iznajmite vozilo, kucajte\n{0077C7}/rent", 0x0077C7FF, RentInfo[ i ][ rentX ], RentInfo[ i ][ rentY ], RentInfo[ i ][ rentZ ], 10.0, 0, 0);
  35. }
  36. }
  37. return 1;
  38. }
  39. forward LoadRent(id, name[], value[]);
  40. public LoadRent(id, name[], value[]) {
  41.  
  42. INI_Float("Lokacija_X", RentInfo[ id ][ rentX ]);
  43. INI_Float("Lokacija_Y", RentInfo[ id ][ rentY ]);
  44. INI_Float("Lokacija_Z", RentInfo[ id ][ rentZ ]);
  45. return 1;
  46. }
  47. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  48.  
  49. switch(dialogid) {
  50. case DIALOG_RENT: {
  51. if(!response) return 1;
  52. switch(listitem) {
  53. case 0: {
  54. RentOdabir[ playerid ] = 1;
  55. ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 100$","U redu","Izlaz");
  56. }
  57. case 1: {
  58. RentOdabir[ playerid ] = 2;
  59. ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 70$","U redu","Izlaz");
  60. }
  61. }
  62. }
  63. case DIALOG_RENTVREME: {
  64. if(!response) return 1;
  65. new i = GetNearestRent(playerid);
  66. if(RentOdabir[ playerid ] == 1) {
  67. new vreme;
  68. if(GetPlayerMoney(playerid) < RentVreme[ playerid ]*100) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Nemate dovoljno novca.");
  69. if(sscanf(inputtext, "d", vreme)) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 100$","U redu","Izlaz");
  70. if(vreme < 1 || vreme > 30) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 100$","U redu","Izlaz");
  71. RentVreme[ playerid ] = vreme;
  72. RentVeh[ playerid ] = CreateVehicle(405, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 0.0, 1, 1, -1);
  73. PutPlayerInVehicle(playerid, RentVeh[ playerid ], 0);
  74. IznajmioVozilo[ playerid ] = GetPlayerVehicleID(playerid);
  75. GivePlayerMoney(playerid, -RentVreme[ playerid ]*100);
  76. RentTimer[ playerid ] = SetTimerEx("TimerRent", 60000, true, "i", playerid);
  77. SendClientMessage(playerid, 0x0077C7FF, "[RENT] {FFFFFF}Uspesno ste iznajmili vozilo.");
  78. RentVehLabel[ RentVeh[ playerid ] ] = Create3DTextLabel("[RENTANO VOZILO]", 0x0077C7FF, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 10.0, 0, 0);
  79. Attach3DTextLabelToVehicle(RentVehLabel[ RentVeh[ playerid ] ], RentVeh[ playerid ], 0.0, 0.0, 0.0);
  80. TipVozila[ RentVeh[ playerid ] ] = 1; // 1 - Rent Vozilo
  81. }
  82. else if(RentOdabir[ playerid ] == 2) {
  83. new vreme;
  84. if(GetPlayerMoney(playerid) < RentVreme[ playerid ]*70) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Nemate dovoljno novca.");
  85. if(sscanf(inputtext, "d", vreme)) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 70$","U redu","Izlaz");
  86. if(vreme < 1 || vreme > 30) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 70$","U redu","Izlaz");
  87. RentVreme[ playerid ] = vreme;
  88. RentVeh[ playerid ] = CreateVehicle(462, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 0.0, 1, 1, -1);
  89. PutPlayerInVehicle(playerid, RentVeh[ playerid ], 0);
  90. IznajmioVozilo[ playerid ] = GetPlayerVehicleID(playerid);
  91. GivePlayerMoney(playerid, -RentVreme[ playerid ]*70);
  92. RentTimer[ playerid ] = SetTimerEx("TimerRent", 60000, true, "i", playerid);
  93. SendClientMessage(playerid, 0x0077C7FF, "[RENT] {FFFFFF}Uspesno ste iznajmili vozilo.");
  94. RentVehLabel[ RentVeh[ playerid ] ] = Create3DTextLabel("[RENTANO VOZILO]", 0x0077C7FF, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 10.0, 0, 0);
  95. Attach3DTextLabelToVehicle(RentVehLabel[ RentVeh[ playerid ] ], RentVeh[ playerid ], 0.0, 0.0, 0.0);
  96. TipVozila[ RentVeh[ playerid ] ] = 1; // 1 - Rent Vozilo
  97. }
  98. }
  99. }
  100. return 1;
  101. }
  102. public OnPlayerStateChange(playerid, newstate, oldstate) {
  103.  
  104. if(newstate == PLAYER_STATE_DRIVER) {
  105. if(TipVozila[ playerid ] == 1 && RentVeh[ playerid ] != GetPlayerVehicleID(playerid)) {
  106. RemovePlayerFromVehicle(playerid);
  107. SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Rentano vozilo.");
  108. }
  109. }
  110. return 1;
  111. }
  112. forward TimerRent(playerid);
  113. public TimerRent(playerid) {
  114.  
  115. RentVreme[ playerid ]--;
  116. if(RentVreme[ playerid ] == 0) {
  117. KillTimer(RentTimer[ playerid ]);
  118. DestroyVehicle(RentVeh[ playerid ]);
  119. Delete3DTextLabel(RentVehLabel[ RentVeh[ playerid ] ]);
  120. IznajmioVozilo[ playerid ] = 0;
  121. RentOdabir[ playerid ] = 0;
  122. RentVreme[ playerid ] = 0;
  123. RentVeh[ playerid ] = 0;
  124. SendClientMessage(playerid, 0x0077C7FF, "[RENT] {FFFFFF}Isteklo vam je vreme iznamljivanja vozila.");
  125. }
  126. return 1;
  127. }
  128. public OnPlayerDisconnect(playerid, reason) {
  129.  
  130. if(IznajmioVozilo[ playerid ] != 0) {
  131. KillTimer(RentTimer[ playerid ]);
  132. DestroyVehicle(RentVeh[ playerid ]);
  133. Delete3DTextLabel(RentVehLabel[ RentVeh[ playerid ] ]);
  134. IznajmioVozilo[ playerid ] = 0;
  135. RentOdabir[ playerid ] = 0;
  136. RentVreme[ playerid ] = 0;
  137. RentVeh[ playerid ] = 0;
  138. }
  139. return 1;
  140. }
  141.  
  142. CMD:kreirajrent(playerid, params[]) {
  143.  
  144. #pragma unused params
  145.  
  146. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste RCON admin.");
  147. new Float:X, Float:Y, Float:Z, i = NextRentID(MAX_RENTS);
  148. GetPlayerPos(playerid, X,Y,Z);
  149. RentInfo[ i ][ rentID ] = CreatePickup(19132, 1, X,Y,Z, 0);
  150. RentInfo[ i ][ RentLabel ] = Create3DTextLabel("[ RENT ]\n{FFFFFF}Da iznajmite vozilo, kucajte\n{0077C7}/rent", 0x0077C7FF, X, Y, Z, 10.0, 0, 0);
  151. RentInfo[ i ][ rentX ] = X;
  152. RentInfo[ i ][ rentY ] = Y;
  153. RentInfo[ i ][ rentZ ] = Z;
  154. SaveRent(i);
  155. return 1;
  156. }
  157. CMD:izbrisirent(playerid, params[]) {
  158.  
  159. #pragma unused params
  160.  
  161. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste RCON admin.");
  162. new i = GetNearestRent(playerid), rentFile[ 60 ];
  163. if(i == -1) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste blizu rent pickup-a.");
  164. DestroyPickup(RentInfo[ i ][ rentID ]);
  165. Delete3DTextLabel(RentInfo[ i ][ RentLabel ]);
  166. RentInfo[ i ][ rentX ] = 0.0;
  167. RentInfo[ i ][ rentY ] = 0.0;
  168. RentInfo[ i ][ rentZ ] = 0.0;
  169. format(rentFile, sizeof(rentFile), RENT_FILE, i);
  170. if(fexist(rentFile)) { fremove(rentFile); }
  171. return 1;
  172. }
  173. // Sentinel 405 Faggio 462
  174. CMD:rent(playerid, params[]) {
  175.  
  176. #pragma unused params
  177.  
  178. if(GetNearestRent(playerid) == -1) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste blizu rent pickup-a.");
  179. if(IznajmioVozilo[ playerid ] != 0) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Vec ste iznajmili vozilo.");
  180. ShowPlayerDialog(playerid, DIALOG_RENT, DIALOG_STYLE_LIST, "{0077C7}Iznamljivanje {FFFFFF}vozila", "Sentinel\nFaggio", "Izaberi","Izlaz");
  181. return 1;
  182. }
  183. CMD:unrent(playerid, params[]) {
  184.  
  185. #pragma unused params
  186.  
  187. if(IznajmioVozilo[ playerid ] == 0) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste iznajmili vozilo.");
  188. KillTimer(RentTimer[ playerid ]);
  189. DestroyVehicle(RentVeh[ playerid ]);
  190. Delete3DTextLabel(RentVehLabel[ RentVeh[ playerid ] ]);
  191. IznajmioVozilo[ playerid ] = 0;
  192. if(RentOdabir[ playerid ] == 1) {
  193. GivePlayerMoney(playerid, RentVreme[ playerid ]*100);
  194. new str[ 120 ];
  195. format(str, sizeof(str), "[UNRENT] {FFFFFF}Uspesno ste vratili iznamljeno vozilo te vam je vraceno %d$", RentVreme[ playerid ]*100);
  196. SendClientMessage(playerid, 0x0077C7FF, str);
  197. RentOdabir[ playerid ] = 0;
  198. RentVreme[ playerid ] = 0;
  199. RentVeh[ playerid ] = 0;
  200. }
  201. else if(RentOdabir[ playerid ] == 2) {
  202. GivePlayerMoney(playerid, RentVreme[ playerid ]*70);
  203. new str[ 120 ];
  204. format(str, sizeof(str), "[UNRENT] {FFFFFF}Uspesno ste vratili iznamljeno vozilo te vam je vraceno %d$", RentVreme[ playerid ]*70);
  205. SendClientMessage(playerid, 0x0077C7FF, str);
  206. RentOdabir[ playerid ] = 0;
  207. RentVreme[ playerid ] = 0;
  208. RentVeh[ playerid ] = 0;
  209. }
  210. return 1;
  211. }
  212.  
  213. GetNearestRent( playerid ) {
  214.  
  215. for( new i = 1; i < MAX_RENTS; i++) {
  216.  
  217. if( IsPlayerInRangeOfPoint( playerid, 3.0, RentInfo[ i ][ rentX ], RentInfo[ i ][ rentY ], RentInfo[ i ][ rentZ ] ) ) { return i; }
  218. }
  219. return -1;
  220. }
  221. stock NextRentID(const len) {
  222. new id = (-1);
  223. for( new loop = ( 0 ), provjera = ( -1 ), Data_[ 64 ] = "\0"; loop != len; ++ loop ) {
  224. provjera = ( loop+1 );
  225. format( Data_, ( sizeof Data_ ), RENT_FILE, provjera );
  226. if(!fexist(Data_)) {
  227. id = ( provjera );
  228. break; } }
  229. return ( id );
  230. }
  231. stock SaveRent(id) {
  232.  
  233. new rentFile[ 60 ];
  234. format(rentFile, sizeof(rentFile), RENT_FILE, id);
  235. new INI:File = INI_Open(rentFile);
  236. INI_WriteFloat(File, "Lokacija_X", RentInfo[ id ][ rentX ]);
  237. INI_WriteFloat(File, "Lokacija_Y", RentInfo[ id ][ rentY ]);
  238. INI_WriteFloat(File, "Lokacija_Z", RentInfo[ id ][ rentZ ]);
  239. INI_Close(File);
  240. return 1;
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement