Update utility.lua
This commit is contained in:
1 parent
c5ae1f1bd7
commit
01217efc5b
1 file changed
+7
-48
@@ -506,32 +506,6 @@ function Utility.CopyToClipboard(text)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
|
||||||
local vehicleType = "boat"
|
|
||||||
|
|
||||||
local result = Utility.Switch(vehicleType, {
|
|
||||||
car = function()
|
|
||||||
print("This is a Car")
|
|
||||||
-- Car-related logic here
|
|
||||||
return "Car logic executed"
|
|
||||||
end,
|
|
||||||
bike = function()
|
|
||||||
print("This is a Bike")
|
|
||||||
-- Bike-related logic here
|
|
||||||
return "Bike logic executed"
|
|
||||||
end,
|
|
||||||
[false] = function()
|
|
||||||
print("Unknown vehicle type. Running default logic.")
|
|
||||||
-- Default logic here
|
|
||||||
return "Default logic executed"
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
print("Result:", result)
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
|
|
||||||
--- Pattern match-like function
|
--- Pattern match-like function
|
||||||
---@generic T
|
---@generic T
|
||||||
---@param value T The value to match
|
---@param value T The value to match
|
||||||
@@ -559,28 +533,13 @@ function Utility.Match(value, patterns)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
---Get zone name at coordinates
|
||||||
local input = 42
|
---@param coords vector3
|
||||||
|
---@return string
|
||||||
local result = Utility.Match(input, {
|
function Utility.GetZoneName(coords)
|
||||||
[function(v) return v < 0 end] = function()
|
local zoneHash = GetNameOfZone(coords.x, coords.y, coords.z)
|
||||||
print("Negative number")
|
return GetLabelText(zoneHash)
|
||||||
return "Negative"
|
end
|
||||||
end,
|
|
||||||
[function(v) return v % 2 == 0 end] = function()
|
|
||||||
print("Even number")
|
|
||||||
return "Even"
|
|
||||||
end,
|
|
||||||
[false] = function()
|
|
||||||
print("No match")
|
|
||||||
return "Default"
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
print("Result:", result)
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
|
|
||||||
AddEventHandler('onResourceStop', function(resource)
|
AddEventHandler('onResourceStop', function(resource)
|
||||||
if resource ~= GetCurrentResourceName() then return end
|
if resource ~= GetCurrentResourceName() then return end
|
||||||
|
|||||||
Reference in new issue
Block a user