Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Neons table
- local neon = {
- rightNeon = {},
- leftNeon = {},
- }
- -- Colors' IDs
- local idModel = {
- ["Red"] = 14399,
- ["Blue"] = 14400,
- ["Green"] = 14401,
- ["Yellow"] = 14402,
- ["Pink"] = 14403,
- ["White"] = 14404
- }
- -- 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.
- local notAllowedAutomobiles = {
- [568] = true, -- Bandito
- [457] = true, -- Caddy
- }
- -- table = {string object file, integer object ID}
- local neonModels = {
- {"models/redNeon.dff", 14399}, -- Red
- {"models/blueNeon.dff", 14400}, -- Blue
- {"models/greenNeon.dff", 14401}, -- Green
- {"models/yellowNeon.dff", 14402}, -- Yellow
- {"models/pinkNeon.dff", 14403}, -- Pink
- {"models/whiteNeon.dff", 14404}, -- White
- }
- -- replace the ingame objects with neons models.
- function replacefiles()
- for i,value in ipairs (neonModels) do -- loop the table above.
- dff = engineLoadDFF (value[1], value[2]) -- loads the DFF file.
- engineReplaceModel ( dff, value[2]) -- replaces the DFF files with the IDs given above in the table.
- end
- end
- addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replacefiles)
- ---- Add neon function, use it to give a neon to a specific vehicle.
- -- vehicle: the vehicle element.
- -- color: Whether it should be "Red","Green","Blue","Yellow","Pink" or "White" (like the table above).
- function addVehicleNeon(vehicle,color)
- if not (vehicle and color) then return false end -- checks if the vehicle and color arguments were given.
- local idColorOfNeon = idModel[color] -- gets the neon ID from its string.
- setElementData(vehicle,"neon",idColorOfNeon) -- sets the neon element data.
- end
- ---- returns sting of the color ("Red","Green","Blue","Yellow","Pink" or "White").
- -- vehicle: the vehicle element you want to get its neon lights color.
- function getVehicleNeonColor(vehicle)
- local elements = getAttachedElements(vehicle) -- gets all the attached elements to the specific vehicle.
- for index, value in ipairs (elements) do -- loop the elements table above.
- local id = getElementModel(value) -- gets the neon id
- for i,v in pairs (idModel) do -- loop the idModel table
- if (id == v) then -- checks if the id model of the neons equal the value of the table.
- return I -- returns the neon name.
- end
- end
- end
- end
- ---- Remove neon function, use it remove neons from a specific vehicle.
- -- vehicle: the vehicle element
- function removeVehicleNeon(vehicle)
- if not (vehicle) then return false end -- checkes if the vehicle argument was given.
- setElementData(vehicle,"neon",nil)
- destroyElement(neon.leftNeon[vehicle])
- destroyElement(neon.rightNeon[vehicle])
- neon.leftNeon[vehicle] = nil
- neon.rightNeon[vehicle] = nil
- end
- ---- does vehicle have neon function, use it to check if the vehicle have neon or not.
- -- vehicle: the vehicle element
- function doesVehicleHaveNeon(vehicle)
- if not (vehicle) then return false end -- checks if the vehicle argument was given
- if (getElementData(vehicle,"neon")) then -- checks if the vehicle have a neon.
- return true -- returns true if it does have neon.
- else
- return false -- returns false if it does not have neon.
- end
- end
- ---- can vehicle use neon function, use it to check if the vehicle able to use neons.
- -- vehicleID: The vehicle model ID of the vehicle that you want to check.
- function canVehicleUseNeon(vehicleID)
- if not (vehicleID) then return false end -- checks if the vehicleID argument was given.
- if (getVehicleType(vehicleID) == "Automobile") and not (notAllowedAutomobiles[vehicleID]) then -- checks if the vehicle type is automobile and it's not blacklisted.
- return true -- returns true if the vehicle can have neon.
- else
- return false -- returns false if the vehicle can not have neon.
- end
- end
- ---- This function destroys all the vehicle's neons once the vehicle get destroyed.
- function removeNeonsOnVehicleDestroy()
- if not (doesVehicleHaveNeon(source)) then return false end -- checks if the vehicle does have neon.
- removeVehicleNeon(source) -- removes the neon.
- end
- addEventHandler("onClientElementDestroy",root, removeNeonsOnVehicleDestroy)
- ---- This function creates the neon lights whenever the vehicle streamed in.
- function createTheNeon()
- if not (getElementType(source) == "vehicle") then return false end -- checkes if the streamed in element is a vehicle.
- if not (getElementData(source,"neon")) then return false end -- checkes if the vehicle has neon lights or not.
- if neon.leftNeon[source] or neon.rightNeon[source] then return false end -- checkes if the neons are already created or not.
- local x,y,z = getElementPosition(source) -- gets the vehicle coordinates.
- neon.leftNeon[source] = createObject ( getElementData(source,"neon"), x, y, z ) -- creates the right side neon.
- neon.rightNeon[source] = createObject ( getElementData(source,"neon"), x, y, z ) -- creates the left side neon.
- setElementCollisionsEnabled(neon.leftNeon[source],false) -- disables the left neon collision.
- setElementCollisionsEnabled(neon.rightNeon[source],false) -- disables the right neon collision.
- attachElements ( neon.rightNeon[source], source , 0.85, 0, -0.50 ) -- attaches the left neon to the vehicle .
- attachElements ( neon.leftNeon[source], source , -0.85, 0, -0.50 ) -- attaches the right neon to the vehicle.
- end
- addEventHandler("onClientElementStreamIn",root,createTheNeon)
- -- This for test purposes.
- addCommandHandler("neon",
- function(_,id)
- local vehicle = getPedOccupiedVehicle(localPlayer)
- if (canVehicleUseNeon(vehicle)) then
- addVehicleNeon(vehicle,id)
- else
- outputChatBox("This vehicle can not have neon lights.",255,0,0)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement