mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 11:47:45 +00:00
Split up the command arguments on the Rust side
This removes some boilerplate code we need in every command to do this ourselves. See #65
This commit is contained in:
parent
ed1263d587
commit
e6536da9dd
6 changed files with 15 additions and 21 deletions
|
@ -1,6 +1,5 @@
|
|||
required_rank = GM_RANK_DEBUG
|
||||
|
||||
function onCommand(args, player)
|
||||
local parts = split(args)
|
||||
player:set_classjob(parts[1])
|
||||
player:set_classjob(tonumber(args[1]))
|
||||
end
|
||||
|
|
|
@ -4,14 +4,12 @@ required_rank = GM_RANK_DEBUG
|
|||
command_sender = "[festival] "
|
||||
|
||||
function onCommand(args, player)
|
||||
local parts = split(args)
|
||||
local argc = #parts
|
||||
local usage = "\nUsage: !festival <id1> <id2> <id3> <id4>"
|
||||
|
||||
local id1 = tonumber(parts[1]) or 0
|
||||
local id2 = tonumber(parts[2]) or 0
|
||||
local id3 = tonumber(parts[3]) or 0
|
||||
local id4 = tonumber(parts[4]) or 0
|
||||
local id1 = args[1]
|
||||
local id2 = args[2] or 0
|
||||
local id3 = args[3] or 0
|
||||
local id4 = args[4] or 0
|
||||
|
||||
player:set_festival(id1, id2, id3, id4)
|
||||
printf(player, "Festival(s) changed to %s, %s, %s and %s.", id1, id2, id3, id4)
|
||||
|
|
|
@ -4,14 +4,13 @@ required_rank = GM_RANK_DEBUG
|
|||
command_sender = "[nudge] "
|
||||
|
||||
function onCommand(args, player)
|
||||
local parts = split(args)
|
||||
local argc = #parts
|
||||
local argc = #args
|
||||
local pos = player.position
|
||||
local angle = player.rotation + (math.pi / 2)
|
||||
local distance = 5
|
||||
local direction = 0
|
||||
local arg1 = parts[1]
|
||||
local arg2 = parts[2]
|
||||
local arg1 = args[1]
|
||||
local arg2 = args[2]
|
||||
local checkArg1 = tonumber(arg1)
|
||||
local checkArg2 = tonumber(arg2)
|
||||
local vertical = {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
required_rank = GM_RANK_DEBUG
|
||||
|
||||
function onCommand(args, player)
|
||||
local parts = split(args)
|
||||
player:set_position({ x = tonumber(parts[1]), y = tonumber(parts[2]), z = tonumber(parts[3]) }, 0)
|
||||
player:set_position({ x = tonumber(args[1]), y = tonumber(args[2]), z = tonumber(args[3]) }, 0)
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@ required_rank = GM_RANK_DEBUG
|
|||
command_sender = "[unlock] "
|
||||
|
||||
function onCommand(args, player)
|
||||
local parts = split(args)
|
||||
local argc = #parts
|
||||
local argc = #args
|
||||
|
||||
local usage = "\nThis command teaches the user an action, emote, etc.\nUsage: !useaction <id/all>"
|
||||
|
||||
|
@ -12,13 +11,13 @@ function onCommand(args, player)
|
|||
return
|
||||
end
|
||||
|
||||
if parts[1] == "all" then
|
||||
if args[1] == "all" then
|
||||
for i = 0, 511, 1 do
|
||||
player:unlock(i)
|
||||
end
|
||||
printf(player, "Everything is unlocked!", id)
|
||||
else
|
||||
local id = tonumber(parts[1])
|
||||
local id = tonumber(args[1])
|
||||
|
||||
if not id then
|
||||
printf(player, "Error parsing unlock id! Make sure the id is an integer."..usage)
|
||||
|
|
|
@ -546,10 +546,10 @@ async fn client_loop(
|
|||
lua.globals().set("required_rank", mlua::Value::Nil)?;
|
||||
|
||||
if connection.player_data.gm_rank as u8 >= required_rank? {
|
||||
let mut func_args = "";
|
||||
let mut func_args = Vec::new();
|
||||
if parts.len() > 1 {
|
||||
func_args = &chat_message.message[command_name.len() + 2..];
|
||||
tracing::info!("Args passed to Lua command {}: {}", command_name, func_args);
|
||||
func_args = (&parts[1..]).to_vec();
|
||||
tracing::info!("Args passed to Lua command {}: {:?}", command_name, func_args);
|
||||
} else {
|
||||
tracing::info!("No additional args passed to Lua command {}.", command_name);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue