Advertisement
Guest User

Untitled

a guest
Jun 7th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. --[[
  2. ================
  3. Script Variables
  4. ================
  5. --]]
  6. local towTruck = {
  7.     handle      = nil,
  8.     hash        = nil,
  9.    
  10.     model       = "towtruck2", -- 50's tow truck
  11.     color       = {128, 235, 90},
  12.    
  13.     position    = {249.138150, 2600.628000, 44.709800},
  14.     rotation    = {0.410125, 1.653700, -35.268880},
  15. }
  16.  
  17. --[[
  18. ================
  19. Script Functions
  20. ================
  21. --]]
  22. function init_towtruck()
  23.     -- make sure hash is initialized
  24.     if towTruck.hash == nil then
  25.         towTruck.hash = GAMEPLAY.GET_HASH_KEY(towTruck.model)
  26.     end
  27.     if towTruck.handle == nil then
  28.         STREAMING.REQUEST_MODEL(towTruck.hash)
  29.        
  30.         local pos = towTruck.position
  31.         local rot = towTruck.rotation
  32.        
  33.         local numTicks = 0
  34.         local loadFailed = false
  35.        
  36.         while not STREAMING.HAS_MODEL_LOADED(towTruck.hash) do
  37.             if numTicks > 250 then
  38.                 loadFailed = true
  39.                 break
  40.             else
  41.                 numTicks = numTicks + 1
  42.             end
  43.         end
  44.        
  45.         if loadFailed then
  46.             print "Tow truck failed to spawn!!!"
  47.             return
  48.         end
  49.        
  50.         -- create towtruck
  51.         towTruck.handle = VEHICLE.CREATE_VEHICLE(towTruck.hash, pos[1], pos[2], pos[3], 0.0, false, true)
  52.        
  53.         -- setup rotation
  54.         ENTITY.SET_ENTITY_ROTATION(towTruck.handle, rot[1], rot[2], rot[3], 2, true)
  55.        
  56.         -- make sure no other tow trucks spawn (we don't want any competition :P)
  57.         VEHICLE.SET_VEHICLE_MODEL_IS_SUPPRESSED(towTruck.hash, true)
  58.     end
  59. end
  60.  
  61. function unload_towtruck()
  62.     if towTruck.handle ~= nil then
  63.         -- we must assume the hash has not been screwed with
  64.         VEHICLE.SET_VEHICLE_MODEL_IS_SUPPRESSED(towTruck.hash, false)
  65.         --STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(towTruck.hash)
  66.         ENTITY.SET_VEHICLE_AS_NO_LONGER_NEEDED(towTruck.handle)
  67.         VEHICLE.DELETE_VEHICLE(towTruck.handle)
  68.        
  69.         -- TEMPORARY HACK!!!
  70.         towTruck.handle = nil
  71.         towTruck.hash = nil
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement