I modify the script - idea that only “mechanic” can use this script, but its doesn’t work… anyone see an error, please?
local toggle = false
local rainbowveh = false
local speed = 0.23
-- Crashing
TriggerEvent('es:addGroupCommand', 'rainbow', "mechanic" , function(source, args, user)
toggle = not toggle
if toggle then
rainbowveh = true
TriggerEvent("chatMessage", "", {255,255,255}, "Mechaniker Event: ^2^*Aktiviert")
else
rainbowveh = false
TriggerEvent("chatMessage", "", {255,255,255}, "Mechaniker Event: ^8^*Deaktiviert")
end
for k,v in pairs(args) do
if k == 1 then
speed = v
end
end
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Du hast keine Berechtigung!")
end, {help = "Nur ein Testbefehlsding, yeah!", params = {{name = "speed", help = "Die Geschwindigkeit, mit der sich die Farbe ändert."}}})
RegisterCommand("rainbow", function(source, args, rawCommand)
toggle = not toggle
if toggle then
rainbowveh = true
TriggerEvent("chatMessage", "", {255,255,255}, "Mechaniker Event: ^2^*Aktiviert")
else
rainbowveh = false
TriggerEvent("chatMessage", "", {255,255,255}, "Mechaniker Event: ^8^*Deaktiviert")
end
for k,v in pairs(args) do
if k == 1 then
speed = v
end
end
end,false)
else
Citizen.CreateThread(function()
local function RGBRainbow( frequency )
local result = {}
local curtime = GetGameTimer() / 1000
result.r = math.floor( math.sin( curtime * frequency + 0 ) * 127 + 128 )
result.g = math.floor( math.sin( curtime * frequency + 2 ) * 127 + 128 )
result.b = math.floor( math.sin( curtime * frequency + 4 ) * 127 + 128 )
return result
end
while true do
local rainbow = RGBRainbow( speed )
Citizen.Wait(0)
if rainbowveh then
if IsPedInAnyVehicle(PlayerPedId(), true) then
veh = GetVehiclePedIsUsing(PlayerPedId())
SetVehicleCustomPrimaryColour(veh, rainbow.r, rainbow.g, rainbow.b)
SetVehicleCustomSecondaryColour(veh, rainbow.r, rainbow.g, rainbow.b)
else
rainbowveh = false
toggle = false
end
end
end
end)