Advertisement
Guest User

auto_nuoma

a guest
Aug 23rd, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.26 KB | None | 0 0
  1. //                                                                         
  2. //                                              ||||||||    |||  |||      || ||
  3. //                                              ||          ||| |||     |||   |||
  4. //                                              ||||||||    ||||||     |||     |||
  5. //                                              ||          ||| |||     |||   |||
  6. //                                              ||||||||    |||  |||      || ||
  7. //
  8. // ================================================================================================================================
  9. // Skriptas: automobilių nuoma
  10. // ================================================================================================================================
  11. //      [+]     Nuomos laikotarpis yra 1val.
  12. //      [+]     Nuoma tęsiasi žaidėjui atsijungus
  13. //      [+]     Greitas automobilių pridėjimas į nuomojamų sąrašą
  14. //      [+]     1 galimas nuomojamas automobilis per žaidėją
  15. //      [+]     3D teksto užrašai
  16. // ================================================================================================================================
  17.  
  18. #include <a_samp>
  19. #define FILTERSCRIPT
  20.  
  21. // {model_id, x, y, z, facing_angle, color_a, color_b, NUOMOS_KAINA}
  22. new Float:nuomos_auto[][] =
  23. {
  24.     {541.0,     2039.9009, 1337.6685, 10.2535, 0.0000, 0.0, 0.0,        300.0},
  25.     {541.0,     2039.9009, 1331.6685, 10.2535, 0.0000, 0.0, 0.0,        300.0},
  26.     {541.0,     2039.9009, 1325.6685, 10.2535, 0.0000, 0.0, 0.0,        300.0}
  27. };
  28.  
  29. // Nuomojamų automobilių informacija
  30. enum nAuto_info
  31. {
  32.     Auto_ID,
  33.     Kaina,
  34.     Nuomininkas[MAX_PLAYER_NAME],
  35.     NuomosPabaiga,
  36.     Float:X,
  37.     Float:Y,
  38.     Float:Z,
  39.     Float:Angle
  40. };
  41. new nAuto[sizeof(nuomos_auto)][nAuto_info];
  42. new Text3D:nAutoLabel[sizeof(nuomos_auto)];
  43. new nAutoID[MAX_PLAYERS];
  44.  
  45. // Keletas teksto spalvų
  46. #define ORANDZINE 0xEDB409FF
  47. #define RAUDONA 0xCF5D30FF
  48.  
  49. // Dialog IDs
  50. #define DIALOG_AUTO_NUOMA 9001
  51. #define DIALOG_AUTO_NUOMA_INFO 9002
  52.  
  53. public OnFilterScriptInit()
  54. {
  55.     printf("\n");
  56.     print("----------------------------------------");
  57.     print("         Car Rental System v 1.0        ");
  58.     print("           Successfully loaded          ");
  59.     print("----------------------------------------");
  60.     print("\n");
  61.  
  62.     // [Nuomojami automobiliai]
  63.     for(new i = 0; i < sizeof(nuomos_auto); i++)
  64.     {
  65.         nAuto[i][Kaina] = floatround(nuomos_auto[i][7]);
  66.         format(nAuto[i][Nuomininkas], MAX_PLAYER_NAME, "niekas");
  67.         nAuto[i][X] = nuomos_auto[i][1];
  68.         nAuto[i][Y] = nuomos_auto[i][2];
  69.         nAuto[i][Z] = nuomos_auto[i][3];
  70.         nAuto[i][Angle] = nuomos_auto[i][4];
  71.  
  72.         new model = floatround(nuomos_auto[i][0]);
  73.         new spalva_a = floatround(nuomos_auto[i][5]);
  74.         new spalva_b = floatround(nuomos_auto[i][6]);
  75.         nAuto[i][Auto_ID] = CreateVehicle(model, nuomos_auto[i][1], nuomos_auto[i][2], nuomos_auto[i][3], nuomos_auto[i][4], spalva_a, spalva_b, -1);
  76.  
  77.         new label_text[50];
  78.         format(label_text, sizeof(label_text), "{EDB409}Nuomojamas automobilis\nKaina: {FFFFFF}%i {EDB409}per val.", nAuto[i][Kaina]);
  79.         nAutoLabel[i] = Create3DTextLabel(label_text, 0xFFFFFFFF, 0.0, 0.0, 0.0, 15.0, 0);
  80.         Attach3DTextLabelToVehicle(nAutoLabel[i], nAuto[i][Auto_ID], 0.0, 0.0, 0.0);
  81.     }
  82.  
  83.     // Nuomojamų automobilių timer'is (tikrina, ar nepasibaigė nuoma)
  84.     SetTimer("TikrintiNuoma", 1000*60, true);
  85.     return 1;
  86. }
  87.  
  88. public OnFilterScriptExit()
  89. {
  90.     printf("\n");
  91.     print("----------------------------------------");
  92.     print("         Car Rental System v 1.0        ");
  93.     print("          Successfully unloaded         ");
  94.     print("----------------------------------------");
  95.     print("\n");
  96.  
  97.     for(new i = 0; i < sizeof(nuomos_auto); i++)
  98.     {
  99.         DestroyVehicle(nAuto[i][Auto_ID]);
  100.         Delete3DTextLabel(nAutoLabel[i]);
  101.     }
  102.     return 1;
  103. }
  104.  
  105. forward TikrintiNuoma();
  106. public TikrintiNuoma()
  107. {
  108.     // Šis timer'is tikrins ar nepasibaigė automobilių nuomos laikas (tikrins visus nuomojamus automobilius)
  109.     // Callback kviečiamas kas 1min.
  110.     for(new i = 0; i < sizeof(nuomos_auto); i++)
  111.     {
  112.         if(strcmp(nAuto[i][Nuomininkas], "niekas", true) && nAuto[i][NuomosPabaiga] <= gettime())
  113.         {
  114.             new playerid = GetPlayerID(nAuto[i][Nuomininkas]);
  115.             if(playerid != INVALID_PLAYER_ID)
  116.             {
  117.                 SendClientMessage(playerid, RAUDONA, "Jūsų automobilio nuoma pasibaigė.");
  118.             }
  119.  
  120.             format(nAuto[i][Nuomininkas], MAX_PLAYER_NAME, "niekas");
  121.             SetVehicleToRespawn(nAuto[i][Auto_ID]);
  122.         }
  123.     }
  124.     return 1;
  125. }
  126.  
  127. public OnVehicleStreamIn(vehicleid, forplayerid)
  128. {
  129.     for(new i = 0; i < sizeof(nuomos_auto); i++)
  130.     {
  131.         if(vehicleid == nAuto[i][Auto_ID])
  132.         {
  133.             new vardas[MAX_PLAYER_NAME];
  134.             GetPlayerName(forplayerid, vardas, MAX_PLAYER_NAME);
  135.             if(strcmp(nAuto[i][Nuomininkas], "niekas", true) && strcmp(nAuto[i][Nuomininkas], vardas, true))
  136.             {
  137.                 SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
  138.             }
  139.         }
  140.     }
  141.     return 1;
  142. }
  143.  
  144. public OnPlayerStateChange(playerid, newstate, oldstate)
  145. {
  146.     if(newstate == PLAYER_STATE_DRIVER)
  147.     {
  148.         for(new i = 0; i < sizeof(nuomos_auto); i++)
  149.         {
  150.             if(GetPlayerVehicleID(playerid) == nAuto[i][Auto_ID])
  151.             {
  152.                 new vardas[MAX_PLAYER_NAME], string[125];
  153.                 GetPlayerName(playerid, vardas, MAX_PLAYER_NAME);
  154.                 if(!strcmp(nAuto[i][Nuomininkas], vardas, true))
  155.                 {
  156.                     new likes_laikas = nAuto[i][NuomosPabaiga] - gettime();
  157.                     new liko_min = floatround(likes_laikas/60, floatround_floor);
  158.                     format(string, sizeof(string), "{EDB409}Jūs nuomojates šį automobilį.\nLikęs nuomos laikas: {FFFFFF}%i {EDB409}min.", liko_min);
  159.                     ShowPlayerDialog(playerid, DIALOG_AUTO_NUOMA_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Automobilių nuoma", string, "Gerai", "");
  160.                 }
  161.                 else
  162.                 {
  163.                     nAutoID[playerid] = i;
  164.                     format(string, sizeof(string), "{EDB409}Šis automobilis yra nuomojamas.\nNuomos kaina: {FFFFFF}%i {EDB409}per val.\nAr norite nuomotis šį automobilį?", nAuto[i][Kaina]);
  165.                     ShowPlayerDialog(playerid, DIALOG_AUTO_NUOMA, DIALOG_STYLE_MSGBOX, "{FFFFFF}Automobilių nuoma", string, "Taip", "Ne");
  166.                 }
  167.             }
  168.         }
  169.     }
  170.     return 1;
  171. }
  172.  
  173. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  174. {
  175.     if(dialogid == DIALOG_AUTO_NUOMA)
  176.     {
  177.         new id = nAutoID[playerid];
  178.         if(response)
  179.         {
  180.             if(GetPlayerMoney(playerid) < nAuto[id][Kaina])
  181.             {
  182.                 SendClientMessage(playerid, RAUDONA, "Neturite pakankamai pinigų.");
  183.                 if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleID(playerid) == nAuto[id][Auto_ID])
  184.                 {
  185.                     SetVehicleToRespawn(nAuto[id][Auto_ID]);
  186.                 }
  187.             }
  188.             else
  189.             {
  190.                 new vardas[MAX_PLAYER_NAME];
  191.                 GetPlayerName(playerid, vardas, MAX_PLAYER_NAME);
  192.  
  193.                 for(new i = 0; i < sizeof(nuomos_auto); i++)
  194.                 {
  195.                     if(!strcmp(nAuto[i][Nuomininkas], vardas, true))
  196.                     {
  197.                         SendClientMessage(playerid, RAUDONA, "Jūs jau nuomojates vieną automobilį. Daugiau nuomotis negalite.");
  198.                         return 1;
  199.                     }
  200.                 }
  201.                 // Išnuomojame automobilį
  202.                 GivePlayerMoney(playerid, - nAuto[id][Kaina]);
  203.                 format(nAuto[id][Nuomininkas], MAX_PLAYER_NAME, vardas);
  204.                 nAuto[id][NuomosPabaiga] = gettime() + 60*60;
  205.                 // Užrakiname automobilį visiems kitiems žaidėjams
  206.                 // (dėl atsargumo, jei žaidėjams jau yra rodomas automobilis)
  207.                 for(new p = 0; p <= GetPlayerPoolSize(); p++)
  208.                 {
  209.                     SetVehicleParamsForPlayer(nAuto[id][Auto_ID], p, 0, 1);
  210.                 }
  211.             }
  212.         }
  213.         else
  214.         {
  215.             SetVehicleToRespawn(nAuto[id][Auto_ID]);
  216.         }
  217.     }
  218.     return 1;
  219. }
  220.  
  221. stock GetPlayerID(vardas[])
  222. {
  223.     new z_vardas[MAX_PLAYER_NAME];
  224.  
  225.     for(new p = 0; p <= GetPlayerPoolSize(); p++)
  226.     {
  227.         GetPlayerName(p, z_vardas, MAX_PLAYER_NAME);
  228.  
  229.         if(!strcmp(vardas, z_vardas, true))
  230.         {
  231.             return p;
  232.         }
  233.     }
  234.  
  235.     return -1;
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement