Advertisement
Guest User

GTAV LUA Forklift

a guest
Oct 10th, 2015
2,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.41 KB | None | 0 0
  1. --
  2. -- Created by roto / mozy
  3. -- Feel free to do wtfever.
  4. --
  5. -- Yes it has some bugs, can be better. Go nuts fixing it.
  6. --
  7.  
  8. -- Create a ScriptThread
  9. -- I recommend matching addon name & script thread name
  10. spawn_forklift = ScriptThread("spawn_forklift")
  11.  
  12. -- Run function
  13. -- This is called once! It's your job to keep this alive!
  14. function spawn_forklift:Run()
  15.     -- while-loop, do not use while true !
  16.     while self:IsRunning() do
  17.    
  18.         -- Spawn us a forklift
  19.         if IsKeyDown(KEY_F7) then
  20.             -- Vehicle Spawn Position
  21.             -- In front of the Player
  22.             local vehicle_pos = LocalPlayer():GetOffsetVector(0,5,0)
  23.  
  24.             -- Load Model
  25.             streaming.RequestModel(VEHICLE_FORKLIFT)
  26.            
  27.             -- Create Vehicle
  28.             game.CreateVehicle(VEHICLE_FORKLIFT, vehicle_pos)
  29.            
  30.             -- Set model as no longer needed
  31.             -- Otherwise it lies around in memory
  32.             streaming.ReleaseModel(VEHICLE_FORKLIFT)
  33.         end
  34.  
  35.         -- Spawn Flatbed
  36.         if IsKeyDown(KEY_F9) then
  37.             local vehicle_pos = LocalPlayer():GetOffsetVector(0,10,0)
  38.             local position = LocalPlayer():GetPosition()
  39.            
  40.             -- Load Model
  41.             streaming.RequestModel(VEHICLE_MONSTER) --VEHICLE_BULLDOZER, VEHICLE_FLATBED, VEHICLE_HANDLER (dock container handler)
  42.            
  43.             -- Create Vehicle
  44.             game.CreateVehicle(VEHICLE_MONSTER, vehicle_pos)
  45.            
  46.             -- Set model as no longer needed
  47.             -- Otherwise it lies around in memory
  48.             streaming.ReleaseModel(VEHICLE_MONSTER)
  49.         end
  50.        
  51.         -- Detach from forklift, give gravity... also lets try some weird shit
  52.         if IsKeyDown(KEY_F10) then
  53.             local position = LocalPlayer():GetOffsetVector(0,10,0)
  54.            
  55.             -- Lets try some vehicle stuff
  56.             local nearby_vehicles = LocalPlayer():GetNearbyVehicles(2) -- has to ALWAYS be a minimum of 2 for some reason
  57.             for _, vehicle in pairs(nearby_vehicles) do
  58.                 --vehicle:Delete()
  59.                 local a_0 = vehicle.ID
  60.                 natives.VEHICLE.SET_VEHICLE_STRONG(a_0, false);
  61.                 natives.VEHICLE.SET_VEHICLE_HAS_STRONG_AXLES(a_0, false);
  62.                 natives.ENTITY.DETACH_ENTITY(a_0, true, true);
  63.                 natives.VEHICLE.SET_VEHICLE_GRAVITY(a_0, true);
  64.                 --natives.VEHICLE.SET_VEHICLE_GRAVITY(a_0, false); -- OK this works.... almost
  65.                 --natives.VEHICLE.SET_VEHICLE_DAMAGE(a_0, 0.84, 2.21, 0.22, 100.0, 400.0, true);
  66.             end
  67.            
  68.         end    
  69.         -- Attach to forklift
  70.         if IsKeyDown(KEY_F11) then         
  71.             -- Vehicle Spawn Position
  72.             -- In front of the Player
  73.             local vehicle_pos = LocalPlayer():GetOffsetVector(0,5,0)
  74.            
  75.             local current_player_vehicle = LocalPlayer():GetVehicle()
  76.             local nearby_vehicles = LocalPlayer():GetNearbyVehicles(2)
  77.             for _, vehicle in pairs(nearby_vehicles) do
  78.                 --vehicle:Delete()
  79.                 local a_0 = vehicle.ID
  80.                 if current_player_vehicle ~= vehicle.ID then
  81.                     natives.VEHICLE.SET_VEHICLE_GRAVITY(a_0, false); -- OK this works.... almost
  82.                     --natives.VEHICLE.SET_VEHICLE_DAMAGE(a_0, 0.84, 2.21, 0.22, 100.0, 400.0, true);
  83.                 end
  84.                    
  85.                 if LocalPlayer():IsInVehicle() then
  86.                     if natives.ENTITY.IS_ENTITY_TOUCHING_ENTITY(current_player_vehicle.ID, vehicle.ID) then
  87.                         --[[
  88.                         Sample: --ENTITY::ATTACH_ENTITY_TO_ENTITY(a_0, a_1._f2, 0, v_5, 0.0, 0.0, 180.0, 0, 0, 0, 0, 2, 1);
  89.                        
  90.                         ATTACH_ENTITY_TO_ENTITY(Entity entity1, -- Nearest Vehicle that we want to attach
  91.                                                 Entity entity2, -- Our vehicle, the receiver
  92.                                                 int boneIndex, -- Guessed this one, #3 is the "forks" of the forklift
  93.                                                 float x, -- Leave at "0" to be centered on fork
  94.                                                 float y, -- Distance from front of forklift body, how far the car should be away
  95.                                                 float z, -- Height above forks, this doesnt work well with SUV's and such. But sportscars are OK.
  96.                                                 float rot_x, -- bla
  97.                                                 float rot_y, -- bla
  98.                                                 float rot_z, -- Rotate car... if you go in from Drivers side, it works fine. Otherwise it rotates 90deg for you.
  99.                                                 BOOL p9, -- dunno
  100.                                                 BOOL p10, -- dunno
  101.                                                 BOOL p11, -- dunno
  102.                                                 BOOL p12, -- dunno
  103.                                                 int unk, -- dunno, took this from decompiled mission scripts
  104.                                                 BOOL p14) -- same as above
  105.                         ]]--
  106.                         natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(vehicle.ID, current_player_vehicle.ID, 3, 0.0, 1.3, -0.09, 0.0, 0, 90.0, false, false, false, false, 2, true)
  107.                     end
  108.                 end
  109.             end
  110.            
  111.         end
  112.        
  113.         -- Wait
  114.         self:Wait(50)
  115.     end
  116. end
  117.  
  118. -- OnError
  119. function spawn_forklift:OnError()
  120.     print("Oh no! Example Thread caused an error!")
  121.     self:Reset()
  122. end
  123.  
  124. -- Register Thread
  125. spawn_forklift:Register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement