Skip to content

Instantly share code, notes, and snippets.

@Local9
Last active May 18, 2024 05:29
Show Gist options
  • Save Local9/6c59ffafcd3dca6ef1524de0067842cf to your computer and use it in GitHub Desktop.
Save Local9/6c59ffafcd3dca6ef1524de0067842cf to your computer and use it in GitHub Desktop.
Stupid thing made in FiveM (Warning, don't use if you suffer from epilepsy)
print("Loading light client.lua")
local lights = {
"h4_prop_battle_lights_fx_riga",
"h4_prop_battle_lights_fx_rigb",
"h4_prop_battle_lights_fx_rigc",
"h4_prop_battle_lights_fx_rigd",
"h4_prop_battle_lights_fx_rige",
"h4_prop_battle_lights_fx_rigf",
"h4_prop_battle_lights_fx_rigg",
"h4_prop_battle_lights_fx_righ",
}
local lamps = {
{
entity = nil,
rotation = 0,
}
}
local function createLamps()
-- get a random model from the lights table
local lampModel = lights[math.random(1, #lights)]
local keypadModel = GetHashKey(lampModel)
RequestModel(keypadModel)
repeat Wait(0) until HasModelLoaded(keypadModel)
print "Model Loaded"
local positionOffset = GetOffsetFromEntityInWorldCoords(PlayerPedId(), math.random(1, 10) + .0, math.random(1, 10) + .0,
math.random(2, 3) + .0);
local prop = CreateObjectNoOffset(keypadModel, positionOffset, true, true, false);
FreezeEntityPosition(prop, true)
SetModelAsNoLongerNeeded(keypadModel)
lamps[#lamps + 1] = { entity = prop, rotation = 0 }
end
local pitch = 0
function RandomiseBeamColour(lamp)
SetObjectLightColor(lamp, true, math.random(0, 255), math.random(0, 255), math.random(0, 255))
end
local function UpdateLamp(lamp, idx)
-- Assuming you have an entity with a model that you want to rotate
local entity = lamp.entity
local entityPos = GetEntityCoords(entity)
local targetPos = GetEntityCoords(PlayerPedId())
-- Calculate the direction from entity to target
local direction = targetPos - entityPos
-- Calculate the pitch angle
local roll = math.deg(math.atan(direction.z, math.sqrt(direction.x * direction.x + direction.y * direction.y))) +
30.0
-- Calculate the yaw angle
local yaw = math.deg(math.atan(direction.y, direction.x))
-- if direction.x >= 0.0 then
-- yaw = yaw + 180.0
-- end
lamp.rotation = lamp.rotation + 5.0
if lamp.rotation > 360 then
lamp.rotation = 0.0
end
if lamp.rotation == 0.0 then
RandomiseBeamColour(entity)
ResetEntityAlpha(entity)
end
if lamp.rotation == 300 then
SetEntityAlpha(entity, 180, false)
end
-- Set the entity's rotation
SetEntityRotation(entity, lamp.rotation + .0, -roll + .0, yaw + .0, 2, true)
end
CreateThread(function()
while true do
Wait(0)
if IsControlJustPressed(0, 51) then
createLamps()
end
-- set the game to nighttime
NetworkOverrideClockTime(23, 0, 0)
-- for each lamp in the lamps table do the following code
for i = 1, #lamps do
UpdateLamp(lamps[i], i)
end
end
end)
@Local9
Copy link
Author

Local9 commented May 20, 2023

2023-05-20.19-23-10.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment