Last active
May 18, 2024 05:29
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2023-05-20.19-23-10.mp4