ultra-voltlab icon indicating copy to clipboard operation
ultra-voltlab copied to clipboard

Altering code with result functions breaks the timer

Open 1mRAAAH opened this issue 1 year ago • 0 comments

Hey,

I'm using the following setup:

Citizen.CreateThread(function() while true do Citizen.Wait(0) if DeliveryAdres ~= nil then local coords = GetEntityCoords(GetPlayerPed(-1)) local zone = Config.Zones[DeliveryAdres] local player = PlayerPedId() local dist = GetDistanceBetweenCoords(coords, zone.Pos.x, zone.Pos.y, zone.Pos.z, true) local shock = math.random(1,20) local time = 10

        if dist < 6 then
            if not fixing then
                DrawText3Ds(zone.Pos.x, zone.Pos.y, zone.Pos.z, "[~g~E~s~] Storing verhelpen")
            end
            if dist < 2 then
                if IsControlJustReleased(0, 38) and not fixing then
                        fixing = true
                    if shock == 10 then
                        local health = GetEntityHealth(player)
                        loadAnimDict( "stungun@standing" ) 
                        TaskPlayAnim(GetPlayerPed(-1), "stungun@standing", "damage", 8.0, 1.0, 3000, 1, 0, false, false, false)
                        Wait(1000)
                        SetPedToRagdoll(player, 2000, 2500, 0)                                 
                        setHealth(health-5)
                    else             
                            TriggerEvent('ultra-voltlab', time, function(result,reason)
                                if result == 0 then
                                    print('Hack failed', reason)
                                    TriggerServerEvent('pleb-electrician:server:darkness')
                                    Fixer()
                                elseif result == 1 then
                                    print('Hack successful')
                                    TriggerServerEvent('pleb-electrician:server:reboot')
                                    Fixer()
                                    
                                    StopDelivery()
                                    Wait(1000)
                                    startInterval()     
                                        
                                elseif result == 2 then
                                    print('Timed out')
                                    TriggerServerEvent('pleb-electrician:server:darkness')
                                        Fixer()
                                elseif result == -1 then
                                    print('Error occured',reason)
                                    TriggerServerEvent('pleb-electrician:server:darkness')
                                        Fixer()
                                end
                            end)
                   end -- Shocked of niet
                end -- End Pressed 0, 38
            end
        end
	end
end

end)

function Fixer() if fixing then fixing = false end end

The timer is now broken. If you surpass 10 seconds, it just continues to show the UI. Whenever I remove Fixer() and StopDelivery()/startInterval() its working again. I can't seem to implement functions as followup after any result. Ideas?

-- Somehow the markup is broken :D

1mRAAAH avatar Oct 24 '23 09:10 1mRAAAH