sqpp15

Advanced Car Script 0.1a

Mar 14th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. --------------------------------------------------
  2. -------  ADVANCED VEHICLE SYSTEM FOR CS2D  -------
  3. --------------------------------------------------
  4.  
  5. colors = {
  6.     RED = "©255000000",
  7.     GREEN = "©000255000",
  8.     BLUE = "©000000255",
  9.     BLACK = "©000000000",
  10.     WHITE = "©255255255",
  11.     WBLUE = "©000190255",
  12.     DARK_GREEN = "©000100000"
  13. }
  14.  
  15. vehicles = {
  16.     [1] = {
  17.         name = "Car 1"; -- name of car
  18.         speed = 20; -- speed of car
  19.         gfx_path = "gfx/MafiaRP/cars/red.png"; -- path to car's gfx
  20.         fly = false; -- flyable or not
  21.         top = 0;
  22.         health = 100; -- car's health
  23.         fuel_type = "benzol";
  24.         fuel_tank = 30; -- maximum fuel in car
  25.         usage = 10; -- uses 10 litre on 100km
  26.         plate = "HUF-666";
  27.         radio = true;
  28.         rentable = true;
  29.         handling = 1.0;
  30.         price = 5000;
  31.         price_rent = 50;
  32.         age = 5; -- Age of car
  33.         owner = 6943;-- BY USGN ID
  34.         transmission = 6;-- X SPEED TRANSMISSION
  35.         transmission_type = 1;-- auto or manual
  36.         turbo = true;
  37.         doors = 2;
  38.         anti_bullet = true;
  39.         }
  40. }
  41.  
  42. veh = {}
  43. _vehid = 1;
  44.  
  45. function GetCar(veh, x, y, rotation, owner)
  46.     if not rotation then rotation = 0 end;
  47.     if owner then
  48.         if Player[owner] ~= nil then
  49.             table.insert(Player[owner].veh, _vehid);
  50.         end
  51.     end
  52.    
  53.     local info = {};
  54.     info.enabled = true;
  55.     info.x = x;
  56.     info.y = y;
  57.     info.type = veh;
  58.     info.gfx = image(vehicles[veh].gfx_path, x, y, vehicles[veh].top);
  59.     imagepos(info.gfx, x, y, rotation);
  60.     info.owner = 0;
  61.     info.players = {};
  62.     info.vid = _vehid;
  63.     info.vowner = owner;
  64.     info.rent = 0;
  65.     info.vplayers = {};
  66.     info.vdrivers = {};
  67.     info.health = vehicle[veh].health;
  68.     veh[_vehid] = info;
  69.     local _, info;
  70.     _vehid = _vehid + 1;
  71. end
  72.  
  73. function RemoveCar(veh)
  74.     if veh.owner > 0 then
  75.         Player[veh.owner].vehowner = nil;
  76.     end
  77.     veh.owner = nil;
  78.     local _, info;
  79.     for _, info in pairs(veh.players) do
  80.         Player[k].veh = nil;
  81.     veh.players = nil;
  82.     freeimage(veh.gfx);
  83.     veh.gfx = nil;
  84.     veh.health = nil;
  85.     veh.vplayers = nil;
  86.     veh.vdrivers = nil;
  87.     veh.vid = nil;
  88.     veh.type = nil;
  89.     veh.x = nil;
  90.     veh.y = nil;
  91.     veh.enabled = false;
  92.     veh.rent = nil;
  93. end
  94. end
  95.  
  96. GetCar(1, 138.5 * 32 + 16, 186 * 32 + 16, 90);
  97.  
  98. function checkvehHealth(veh)
  99.     if veh.health <= 0 then
  100.         local x, y = veh.x, veh.y;
  101.         RemoveCar(veh);
  102.         parse("explosion ".. x .." ".. y .." 256 1000 0");
  103.     end
  104. end
  105.  
  106. function RentCar(veh)
  107.     if veh.rentable == true then
  108.     parse("hudtxt 1 "..colors[GREEN].."Rentable "..veh.x.." "..veh.y.."")
  109.     end
  110.    
  111.     if veh.rentable == false then
  112.     parse("hudtxt 2 "..colors[RED].."Buyable "..veh.x.." "..veh.y"")
  113.     end
  114. end
  115.  
  116. function getDist(x1, y1, x2, y2)
  117.     return math.floor(((x1 - x2)^2 + (y1 - y2)^2)^.5)
  118. end
  119.  
  120.  
  121. addhook("use","Rent_menu")
  122. function Rent_menu(id)
  123.     if veh.rentable == true then
  124.     if getDist(player(i, 'x'), player(i, 'y'), player(id, 'x'), player(id, 'y')) <= distance then
  125.     menu(id, "Renting Vehicles, 1 Hour")
  126.     end
  127.     elseif veh.rentable == false then
  128.     msg2(id,""..color[WHITE]"This Vehicle"..color[RED].."NOT RENTABLE!")
  129.     end
  130. end
  131.  
  132.  
  133. addhook("menu","Renting")
  134. function Renting(id,title,sel)
  135.     if veh.rentable == true then
  136.         if title=="Renting Vehicles" then
  137.         if sel==1 then
  138.         if veh.owner > 0 then
  139.         msg2(id,""..color[WHITE]"This Vehicle"..color[RED].."HAS BEEN ALREADY RENT!")
  140.         end
  141.         end
  142.         end
  143.     end
  144.     if veh.owner == 0 then do
  145.     veh.owner = (player(id,"usgn"))
  146.     end
  147.     end
  148. end
Advertisement
Add Comment
Please, Sign In to add comment