Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/opensb/scripts/opensb/player/commands.lua27
-rw-r--r--assets/opensb/scripts/opensb/player/identity.lua33
-rw-r--r--assets/opensb/scripts/opensb/player/player.lua2
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