[Release | Utility/Addon]FlowDetector utilities & cfx-switchcase utilities for FXServer

FlowDetector

FlowDetector utilities for FXServer Github: FlowDetector

[DESCRIPTION]
to create a detector to follow a value’s changing

[INSTALLATION]
Set it as a dependency in you fxmanifest.lua
and

client_script '@flowdetector/flowdetector.lua'

[FUNCTIONS]

FlowDetector.Create(name,defaultValue)        --to create a detector to follow a value's changing
FlowDetector.Delete(name)                     --waste the detector
FlowDetector.Register(name,type,cb(name,old,new,islinked,linkto))        --trigger a function when detect something
FlowDetector.Link(name1,name2)                 --link a detector to another detector.
FlowDetector.Check(name,inputValue)                --input a value into the detector

[EXAMPLE]



CreateThread(function()
    FlowDetector.Link({"A","B"},"Pause")
    FlowDetector.Create('Pause')
    FlowDetector.Create('A')
    FlowDetector.Create('B')
    FlowDetector.Create('C')
    FlowDetector.Link("C","Pause")
    FlowDetector.Register("Pause",'change',function(name,old,new,islinked,linkto)
        if islinked then 
        print(linkto.." change ",tostring(old),tostring(new) .. 'from '..name)
        end 
    end )
    FlowDetector.Register("A",'change',function(name,old,new,islinked,linkto)
        if not islinked then 
        print(name.." change ",tostring(old),tostring(new) )
        end 
    end )
        FlowDetector.Check("Pause",1)
        IsPause = FlowDetector.Check("A",IsPauseMenuActive())
        FlowDetector.Check("Pause",2)
    while true do
        IsPause = FlowDetector.Check("A",IsPauseMenuActive())
        FlowDetector.Check("B",not IsPauseMenuActive())
        FlowDetector.Check("C",999+math.random())
        Citizen.Wait(332)
    end
end)


cfx-switchcase

cfx-switchcase utilities for FXServer Github: cfx-switchcase
[INSTALLATION]
Just Copy and Paste to your code which need the switch-case function

local case = {} --cfx-switchcase by negbook https://github.com/negbook/cfx-switchcase/blob/main/cfx-switchcase.lua
local switch = setmetatable({},{__call=function(a,b)case=setmetatable({},{__call=function(a,b)return a[b]end,__index=function(a,c)return c and c==b and setmetatable({},{__call=function(a,d)d()end})or function()end end})return a[b]end,__index=function(a,c)return setmetatable({},{__call=function(a,...)end})end})

[EXAMPLE]

local case = {} --cfx-switchcase by negbook https://github.com/negbook/cfx-switchcase/blob/main/cfx-switchcase.lua
local switch = setmetatable({},{__call=function(a,b)case=setmetatable({},{__call=function(a,b)return a[b]end,__index=function(a,c)return c and c==b and setmetatable({},{__call=function(a,d)d()end})or function()end end})return a[b]end,__index=function(a,c)return setmetatable({},{__call=function(a,...)end})end})

CreateThread(function()
        local a = 4
        local b = "some"
        switch(a)(
            case(1)(function()
                    print(99)
            end),
            case(4)(function()
                    print(98)
            end)
        )
        switch(b)(
            case("some")(function()
                    print(99)
            end),
            case("where")(function()
                    print(98)
            end)
        )
      
end)
1 Like

a description?

1 Like

OK,[DESCRIPTION]
to create a detector to follow a value’s changing

SWIIITCHHHH CASSSEEEEEEE !!!

I’m still wondering why the creator of lua didn’t add this feature
it’s so useful when you’re used to using it.

1 Like

looks nice

1 Like

nice !