diff options
author | Degranon <boba09@list.ru> | 2025-02-03 18:38:58 +0100 |
---|---|---|
committer | Degranon <boba09@list.ru> | 2025-02-03 18:38:58 +0100 |
commit | c1e0865f2f1e842ef94bb85b3a1c8b13ebb76ba2 (patch) | |
tree | 5cf390a8d6d7cac4fb7feda4fa96b88f364556e3 /assets | |
parent | 27ffdb020534e3d815038c86d9ac6d1dddaf6598 (diff) |
Identity get / set command
Diffstat (limited to 'assets')
-rw-r--r-- | assets/opensb/scripts/opensb/player/commands.lua | 27 | ||||
-rw-r--r-- | assets/opensb/scripts/opensb/player/identity.lua | 33 | ||||
-rw-r--r-- | assets/opensb/scripts/opensb/player/player.lua | 2 |
3 files changed, 60 insertions, 2 deletions
diff --git a/assets/opensb/scripts/opensb/player/commands.lua b/assets/opensb/scripts/opensb/player/commands.lua index 2d83106..4cd3117 100644 --- a/assets/opensb/scripts/opensb/player/commands.lua +++ b/assets/opensb/scripts/opensb/player/commands.lua @@ -6,6 +6,30 @@ local function register(name, func) commands[name] = func end +local function splitArgs(input) + local args = {} + local spat, epat, buf, quoted = [=[^(['"])]=], [=[(['"])$]=] + for str in input:gmatch("%S+") do + local squoted = str:match(spat) + local equoted = str:match(epat) + local escaped = str:match([=[(\*)['"]$]=]) + + if squoted and not quoted and not equoted then + buf, quoted = str, squoted + elseif buf and equoted == quoted and #escaped % 2 == 0 then + str, buf, quoted = buf .. ' ' .. str, nil, nil + elseif buf then + buf = buf .. ' ' .. str + end + if not buf and str then + local cleaned = str:gsub(spat,""):gsub(epat,"") + table.insert(args, cleaned) + end + end + + return table.unpack(args) +end + function module.init() for name, func in pairs(commands) do message.setHandler({name = "/" .. name, localOnly = true}, func) @@ -47,4 +71,5 @@ register("headrotation", function(arg) end end) -module.register = register
\ No newline at end of file +module.register = register +module.splitArgs = splitArgs
\ No newline at end of file diff --git a/assets/opensb/scripts/opensb/player/identity.lua b/assets/opensb/scripts/opensb/player/identity.lua new file mode 100644 index 0000000..112532a --- /dev/null +++ b/assets/opensb/scripts/opensb/player/identity.lua @@ -0,0 +1,33 @@ +local module = {} +modules.copy_paste = module + +local commands = modules.commands + + +commands.register("identity", function(parms) + method, path, value = commands.splitArgs(parms) + + if not method or method == "get" or method == "" then + local identity = player.humanoidIdentity() + + if path then + if identity[path] then + return string.format(identity[path]) + else + return string.format("%s is not a part of the identity", path) + end + end + + return sb.printJson(player.humanoidIdentity(), 1) + elseif method == "set" and path and value then + local identity = player.humanoidIdentity() + if not identity[path] then + return string.format("%s is not a part of the identity", path) + end + identity[path] = value + player.setHumanoidIdentity(identity) + return string.format("Set %s to %s", path, value) + else + return "Usage: /identity <get|set> [path] [value]" + end +end)
\ No newline at end of file diff --git a/assets/opensb/scripts/opensb/player/player.lua b/assets/opensb/scripts/opensb/player/player.lua index 7670595..8f28b16 100644 --- a/assets/opensb/scripts/opensb/player/player.lua +++ b/assets/opensb/scripts/opensb/player/player.lua @@ -1,2 +1,2 @@ require "/scripts/opensb/util/modules.lua" -modules("/scripts/opensb/player/", {"commands", "copy_paste"})
\ No newline at end of file +modules("/scripts/opensb/player/", {"commands", "copy_paste", "identity"})
\ No newline at end of file |