Advertisement
Guest User

Untitled

a guest
Apr 30th, 2011
2,768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.97 KB | None | 0 0
  1. /*
  2.         Commands: /rentcar, /unrentcar, /exitrental, /renthelp, /addrental (easy function generator)
  3.         Author:   admantis
  4. */
  5.  
  6. #include    a_samp
  7. #include    zcmd
  8.  
  9. #define      RENT_COST       300  // Change for car rent cost
  10.  
  11. new IsRentable[MAX_VEHICLES];
  12. new IsRented[MAX_VEHICLES];
  13. new RentedBy[MAX_VEHICLES][24];
  14.  
  15. public OnFilterScriptInit()
  16. {
  17.     /* Under this callback you can create the rental cars with this simple function:
  18.     CreateRentalVehicle(iModel, Float:fX, Float:fY, Float:fZ, Float:Angle, iCol1, iCol2); */
  19.     return 1;
  20. }
  21.  
  22. public OnPlayerConnect(playerid)
  23. {
  24.     SetPVarInt(playerid, "Renting", 0);
  25.     SetPVarInt(playerid, "CarRentID", 0);
  26.     return 1;
  27. }
  28.  
  29. public OnPlayerDisconnect(playerid, reason)
  30. {
  31.     if (GetPVarInt(playerid, "Renting") == 1)
  32.         IsRented[GetPVarInt(playerid, "CarRentID")] = 0,
  33.         SetVehicleToRespawn(GetPVarInt(playerid, "CarRentID"));
  34.     DeletePVar(playerid, "Renting");
  35.     DeletePVar(playerid, "CarRentID");
  36.     return 1;
  37. }
  38.  
  39. public OnPlayerStateChange(playerid, newstate, oldstate)
  40. {
  41.     if (newstate == 2)
  42.     {
  43.         if (oldstate == 1)
  44.         {
  45.             new
  46.                 vID = GetPlayerVehicleID(playerid);
  47.             if (IsRentableCar(vID))
  48.             {
  49.                 if (!IsRentedCar(vID))
  50.                 {
  51.                     new
  52.                         String[128];
  53.                     format(String, 128, "~p~~n~rent cost: ~b~%d~n~~w~type ~b~/rentcar~n~~w~to exit it type~n~~p~/exitrental", RENT_COST);
  54.                     GameTextForPlayer(playerid, String, 30000, 4);
  55.                     SendClientMessage(playerid, -1, "Type {3399CC}/exitrental{FFFFFF} to exit this rental car.");
  56.                     TogglePlayerControllable(playerid, 0);
  57.                 }
  58.                 else if (IsRentedCar(vID))
  59.                 {
  60.                     if (GetPVarInt(playerid, "CarRentID") == vID)
  61.                     {
  62.                         return SendClientMessage(playerid, -1, "{3399CC}Welcome{FFFFFF} to your rented car.");
  63.                     }
  64.                     else if (GetPVarInt(playerid, "CarRentID") != vID)
  65.                     {
  66.                         new
  67.                             String[128];
  68.                         format(String, 128, "This vehicle is rented by: {3399CC}%s{FFFFFF}", RentedBy[vID]);
  69.                         SendClientMessage(playerid, -1, String);
  70.                         SendClientMessage(playerid, -1, "Use {3399CC}/exitrental{FFFFFF} to exit this vehicle.");
  71.                         return 1;
  72.                     }
  73.                 }
  74.             }
  75.         }
  76.     }
  77.     return 0;
  78. }
  79.  
  80.  
  81. CMD:renthelp(playerid, params[])
  82. {
  83.     SendClientMessage(playerid, -1, "{3399CC}Rent Commands:{FFFFFF} /rentcar, /unrentcar, /exitrental");
  84.     return 1;
  85. }
  86.  
  87. CMD:addrental(playerid, params[])
  88. {
  89.     new iVeh, iModel, Float:X, Float:Y, Float:Z, Float:Angle, szString[128];
  90.     if (!IsPlayerAdmin(playerid) && !IsPlayerInAnyVehicle(playerid))
  91.         return SendClientMessage(playerid, -1, "{3399CC}System:{FFFFFF} You are not an admin / not in any car");
  92.  
  93.     iVeh = GetPlayerVehicleID(playerid);
  94.     iModel = GetVehicleModel(iVeh);
  95.     GetVehiclePos(iVeh, X, Y, Z);
  96.     GetVehicleZAngle(iVeh, Angle);
  97.  
  98.     format(szString, 128, "CreateRentalVehicle(%d, %f, %f, %f, %f, %d, %d);", iModel, X, Y, Z, Angle, -1, -1);
  99.     printf(szString);
  100.     SendClientMessage(playerid, -1, szString);
  101.     return 1;
  102. }
  103.  
  104. CMD:exitrental(playerid, params[])
  105. {
  106.     new
  107.         vID = GetPlayerVehicleID(playerid);
  108.     if (!vID)
  109.     {
  110.         SendClientMessage(playerid, -1, "You are {3399CC}not{FFFFFF} in a rental car!");
  111.         return 1;
  112.     }
  113.     RemovePlayerFromVehicle(playerid);
  114.     TogglePlayerControllable(playerid, 1);
  115.     GameTextForPlayer(playerid, " ", 500, 4);
  116.     return 1;
  117. }
  118.  
  119. CMD:unrentcar(playerid, params[])
  120. {
  121.     GameTextForPlayer(playerid, " ", 500, 4);
  122.     if (GetPVarInt(playerid, "Renting") == 0)
  123.     {
  124.         SendClientMessage(playerid, -1, "You {3399CC}don't{FFFFFF} even rent a car!");
  125.         return 1;
  126.     }
  127.     new
  128.         vID = GetPVarInt(playerid, "CarRentID");
  129.     IsRented[vID] = 0;
  130.     SetPVarInt(playerid, "CarRentID", 0);
  131.     SetPVarInt(playerid, "Renting", 0);
  132.     new
  133.         Float:X,
  134.         Float:Y,
  135.         Float:Z;
  136.     GetPlayerPos(playerid, X, Y, Z);
  137.     SetPlayerPos(playerid, X, Y, Z+1);
  138.     TogglePlayerControllable(playerid, 1);
  139.     SetVehicleToRespawn(vID);
  140.     RentedBy[vID] = "No-one";
  141.     return 1;
  142. }
  143.  
  144. CMD:rentcar(playerid, params[])
  145. {
  146.     GameTextForPlayer(playerid, " ", 500, 4);
  147.     new
  148.         vID = GetPlayerVehicleID(playerid);
  149.     if (!vID)
  150.     {
  151.         SendClientMessage(playerid, -1, "You are {3399CC}not{FFFFFF} in any car!");
  152.         return 1;
  153.     }
  154.     if (!IsRentableCar(vID))
  155.     {
  156.         SendClientMessage(playerid, -1, "This car is {3399CC}not{FFFFFF} rentable!");
  157.         return 1;
  158.     }
  159.     if (IsRentedCar(vID))
  160.     {
  161.         SendClientMessage(playerid, -1, "This car is {3399CC}already rented{FFFFFF} by someone else!");
  162.         return 1;
  163.     }
  164.     if (GetPVarInt(playerid, "Renting") == 1)
  165.     {
  166.         SendClientMessage(playerid, -1, "You {3399CC}already rent{FFFFFF} a car!");
  167.         return 1;
  168.     }
  169.     if (!CanAffordRental(playerid))
  170.     {
  171.         new String[128];
  172.         format(String, 128, "You don't have money to rent this! {3399CC}(Cost: %d)", RENT_COST);
  173.         SendClientMessage(playerid, -1, String);
  174.         return 1;
  175.     }
  176.     IsRented[vID] = 1;
  177.     TogglePlayerControllable(playerid, 1);
  178.     SetPVarInt(playerid, "CarRentID", vID);
  179.     SetPVarInt(playerid, "Renting", 1);
  180.     new String[128];
  181.     format(String, 128, "~w~you have rented this car~n~it costed you: ~g~%d$", RENT_COST);
  182.     GameTextForPlayer(playerid, String, 4000, 4);
  183.     RentedBy[vID] = GetName(playerid);
  184.     GivePlayerMoney(playerid, -RENT_COST);
  185.     SendClientMessage(playerid, -1, "{3399CC}Car rented,{FFFFFF} you may now turn on the engine!");
  186.     return 1;
  187. }
  188.  
  189. stock CreateRentalVehicle(iModel, Float:fX, Float:fY, Float:fZ, Float:fAngle, iCol1, iCol2)
  190. {
  191.     new
  192.         TMP;
  193.    
  194.     TMP = AddStaticVehicle(iModel, Float:fX, Float:fY, Float:fZ, Float:fAngle, iCol1, iCol2);
  195.    
  196.     SetVehicleNumberPlate(TMP, "Rental");
  197.     SetVehicleToRespawn(TMP);
  198.    
  199.     IsRentable[TMP] = 1;
  200.     IsRented[TMP] = 0;
  201.     RentedBy[TMP] = "No-one";
  202.     return TMP;
  203. }
  204.  
  205. stock GetName(playerid)
  206. {
  207.     new
  208.         Name[24];
  209.     GetPlayerName(playerid, Name, 24);
  210.     return Name;
  211. }
  212.  
  213. stock IsRentableCar(vehicleid)
  214. {
  215.     if (IsRentable[vehicleid])
  216.         return 1;
  217.     return 0;
  218. }
  219.  
  220. stock CanAffordRental(playerid)
  221. {
  222.     new
  223.         Money;
  224.     Money = GetPlayerMoney(playerid);
  225.     if (Money >= RENT_COST)
  226.         return 1;
  227.     return 0;
  228. }
  229.  
  230. stock IsRentedCar(vehicleid)
  231. {
  232.     if (IsRented[vehicleid])
  233.         return 1;
  234.     return 0;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement