Advertisement
Guest User

oikzdas

a guest
May 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.41 KB | None | 0 0
  1. -- Neons table
  2. local neon = {
  3.         rightNeon = {},
  4.         leftNeon = {},
  5. }
  6.  
  7. -- Colors' IDs
  8. local idModel = {
  9.         ["Red"] = 14399,
  10.         ["Blue"] = 14400,
  11.         ["Green"] = 14401,
  12.         ["Yellow"] = 14402,
  13.         ["Pink"] = 14403,
  14.         ["White"] = 14404
  15. }
  16.  
  17.  
  18. -- All the automobiles are allowed to use neons but some of them look buggy with neons so here you can add their IDs to blacklist the usage of them.
  19. local notAllowedAutomobiles = {
  20.         [568] = true, -- Bandito
  21.         [457] = true, -- Caddy
  22. }
  23.  
  24. -- table = {string object file, integer object ID}
  25. local neonModels = {
  26.         {"models/redNeon.dff", 14399}, -- Red
  27.         {"models/blueNeon.dff", 14400}, -- Blue
  28.         {"models/greenNeon.dff", 14401}, -- Green
  29.         {"models/yellowNeon.dff", 14402}, -- Yellow
  30.         {"models/pinkNeon.dff", 14403}, -- Pink
  31.         {"models/whiteNeon.dff", 14404}, -- White
  32. }
  33.  
  34. -- replace the ingame objects with neons models.
  35. function replacefiles()
  36.         for i,value in ipairs (neonModels) do -- loop the table above.
  37.                 dff = engineLoadDFF (value[1], value[2]) -- loads the DFF file.
  38.                 engineReplaceModel ( dff, value[2]) -- replaces the DFF files with the IDs given above in the table.
  39.         end
  40. end
  41. addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replacefiles)
  42.  
  43.  
  44.  
  45. ---- Add neon function, use it to give a neon to a specific vehicle.
  46. -- vehicle: the vehicle element.
  47. -- color: Whether it should be "Red","Green","Blue","Yellow","Pink" or "White" (like the table above).
  48. function addVehicleNeon(vehicle,color)
  49.         if not (vehicle and color) then return false end -- checks if the vehicle and color arguments were given.
  50.                 local idColorOfNeon = idModel[color] -- gets the neon ID from its string.
  51.                 setElementData(vehicle,"neon",idColorOfNeon) -- sets the neon element data.
  52. end
  53.  
  54.  
  55. ---- returns sting of the color ("Red","Green","Blue","Yellow","Pink" or "White").
  56. -- vehicle: the vehicle element you want to get its neon lights color.
  57. function getVehicleNeonColor(vehicle)
  58.         local elements = getAttachedElements(vehicle) -- gets all the attached elements to the specific vehicle.
  59.         for index, value in ipairs (elements) do -- loop the elements table above.
  60.         local id = getElementModel(value) -- gets the neon id
  61.                 for i,v in pairs (idModel) do -- loop the idModel table
  62.                         if (id == v) then -- checks if the id model of the neons equal the value of the table.
  63.                         return I -- returns the neon name.
  64.                         end
  65.                 end
  66.         end
  67. end
  68.  
  69.  
  70. ---- Remove neon function, use it remove neons from a specific vehicle.
  71. -- vehicle: the vehicle element
  72. function removeVehicleNeon(vehicle)
  73.         if not (vehicle) then return false end -- checkes if the vehicle argument was given.
  74.                 setElementData(vehicle,"neon",nil)
  75.                 destroyElement(neon.leftNeon[vehicle])
  76.                 destroyElement(neon.rightNeon[vehicle])
  77.                 neon.leftNeon[vehicle] = nil
  78.                 neon.rightNeon[vehicle] = nil
  79. end
  80.  
  81.  
  82. ---- does vehicle have neon function, use it to check if the vehicle have neon or not.
  83. -- vehicle: the vehicle element
  84. function doesVehicleHaveNeon(vehicle)
  85.         if not (vehicle) then return false end -- checks if the vehicle argument was given
  86.         if (getElementData(vehicle,"neon")) then -- checks if the vehicle have a neon.
  87.                 return true -- returns true if it does have neon.
  88.         else
  89.                 return false -- returns false if it does not have neon.
  90.         end
  91. end
  92.  
  93. ---- can vehicle use neon function, use it to check if the vehicle able to use neons.
  94. -- vehicleID: The vehicle model ID of the vehicle that you want to check.
  95. function canVehicleUseNeon(vehicleID)
  96.         if not (vehicleID) then return false end -- checks if the vehicleID argument was given.
  97.         if (getVehicleType(vehicleID) == "Automobile") and not (notAllowedAutomobiles[vehicleID]) then -- checks if the vehicle type is automobile and it's not blacklisted.
  98.                 return true --  returns true if the vehicle can have neon.
  99.                 else
  100.                 return false -- returns false if the vehicle can not have neon.
  101.         end
  102. end
  103.  
  104. ---- This function destroys all the vehicle's neons once the vehicle get destroyed.
  105. function removeNeonsOnVehicleDestroy()
  106.         if not (doesVehicleHaveNeon(source)) then return false end -- checks if the vehicle does have neon.
  107.                 removeVehicleNeon(source) -- removes the neon.
  108. end
  109. addEventHandler("onClientElementDestroy",root, removeNeonsOnVehicleDestroy)
  110.  
  111.  
  112. ---- This function creates the neon lights whenever the vehicle streamed in.
  113. function createTheNeon()
  114.         if not (getElementType(source) == "vehicle") then return false end -- checkes if the streamed in element is a vehicle.
  115.         if not (getElementData(source,"neon")) then return false end -- checkes if the vehicle has neon lights or not.
  116.         if neon.leftNeon[source] or neon.rightNeon[source] then return false end -- checkes if the neons are already created or not.
  117.                 local x,y,z = getElementPosition(source) -- gets the vehicle coordinates.
  118.                 neon.leftNeon[source] = createObject ( getElementData(source,"neon"), x, y, z ) -- creates the right side neon.
  119.                 neon.rightNeon[source] = createObject ( getElementData(source,"neon"), x, y, z ) -- creates the left side neon.
  120.                 setElementCollisionsEnabled(neon.leftNeon[source],false) -- disables the left neon collision.
  121.                 setElementCollisionsEnabled(neon.rightNeon[source],false) -- disables the right neon collision.
  122.                 attachElements ( neon.rightNeon[source], source , 0.85, 0, -0.50 ) -- attaches the left neon to the vehicle .
  123.                 attachElements ( neon.leftNeon[source], source , -0.85, 0, -0.50 ) -- attaches the right neon to the vehicle.
  124.                                
  125. end
  126. addEventHandler("onClientElementStreamIn",root,createTheNeon)
  127.  
  128.  
  129. -- This for test purposes.
  130. addCommandHandler("neon",
  131. function(_,id)
  132.         local vehicle = getPedOccupiedVehicle(localPlayer)
  133.         if (canVehicleUseNeon(vehicle)) then
  134.             addVehicleNeon(vehicle,id)
  135.         else
  136.             outputChatBox("This vehicle can not have neon lights.",255,0,0)
  137.         end
  138. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement