Update commands to match new api
parent
6a9e37a3bb
commit
24e89a4029
110
commands.lua
110
commands.lua
|
@ -26,8 +26,8 @@ end
|
|||
-- All chat commands are defined by simply adding the handler function to
|
||||
-- this table. The handler receives the name of the player and the command
|
||||
-- arguments, and it should return:
|
||||
-- 1. reply message (or nil)
|
||||
-- 2. success status (true or false)
|
||||
-- 1. success status (true or false)
|
||||
-- 2. reply message (or nil)
|
||||
-- 3. optionally, true to queue the command and wake the entity, which
|
||||
-- it should only do if the enitity is inactive. In this case, the
|
||||
-- other two return values are ignored. The command will execute
|
||||
|
@ -41,17 +41,17 @@ subcmd.help = {
|
|||
|
||||
if args and args ~= "" then
|
||||
if not subcmd[args] then
|
||||
return "No such subcommand"
|
||||
return false, "No such subcommand"
|
||||
end
|
||||
return "/people "..args.." "..subcmd[args].params.." - "..
|
||||
subcmd[args].desc, true
|
||||
return true, "/people "..args.." "..subcmd[args].params.." - "..
|
||||
subcmd[args].desc
|
||||
end
|
||||
|
||||
local msg = "Subcommands (use /people help <subcmd> for more):"
|
||||
for c, _ in pairs(subcmd) do
|
||||
msg = msg.." "..c
|
||||
end
|
||||
return msg, true
|
||||
return true, msg
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -61,14 +61,14 @@ subcmd.footpath_update = {
|
|||
exec = function(playername, args)
|
||||
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
return "Only admins can update the footpath node graph"
|
||||
return false, "Only admins can update the footpath node graph"
|
||||
end
|
||||
|
||||
response = people.footpath_make_pathnodes()
|
||||
if response then
|
||||
return response
|
||||
return false, response
|
||||
end
|
||||
return "Footpath node graph updated successfully"
|
||||
return true, "Footpath node graph updated successfully"
|
||||
|
||||
end
|
||||
}
|
||||
|
@ -79,31 +79,31 @@ subcmd.create = {
|
|||
exec = function(playername, args)
|
||||
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
return "Only admins can create people"
|
||||
return false, "Only admins can create people"
|
||||
end
|
||||
|
||||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not person_name then
|
||||
return "Name needs to be specified"
|
||||
return false, "Name needs to be specified"
|
||||
end
|
||||
if person then
|
||||
return "Person "..person_name.." already exists"
|
||||
return false, "Person "..person_name.." already exists"
|
||||
end
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
if not player then
|
||||
return "people create can only be used by a player"
|
||||
return false, "people create can only be used by a player"
|
||||
end
|
||||
local pos = player:getpos()
|
||||
local obj = minetest.add_entity(pos, "people:person")
|
||||
if not obj then
|
||||
return "Failed to add_entity"
|
||||
return false, "Failed to add_entity"
|
||||
end
|
||||
local ent = obj:get_luaentity()
|
||||
ent.name = person_name
|
||||
ent.owner = playername
|
||||
people.people_add(ent)
|
||||
return "Created "..person_name, true
|
||||
return true, "Created "..person_name
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -115,20 +115,20 @@ subcmd.delete = {
|
|||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not person then
|
||||
return "Specify a valid person"
|
||||
return false, "Specify a valid person"
|
||||
end
|
||||
local ent = people.people[person_name].entity
|
||||
if not ent then
|
||||
return nil, false, true
|
||||
return false, nil, true
|
||||
end
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
if playername ~= ent.owner then
|
||||
return person_name.." isn't yours, so so can't do that"
|
||||
return false, person_name.." isn't yours, so so can't do that"
|
||||
end
|
||||
end
|
||||
ent.object:remove()
|
||||
people.people[person_name] = nil
|
||||
return "Deleted "..person_name, true
|
||||
return true, "Deleted "..person_name
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -140,19 +140,19 @@ subcmd.summon = {
|
|||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not person then
|
||||
return "Specify a valid person"
|
||||
return false, "Specify a valid person"
|
||||
end
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
if not player then
|
||||
return "people summon can only be used by a player"
|
||||
return false, "people summon can only be used by a player"
|
||||
end
|
||||
local pos = player:getpos()
|
||||
local ent = people.people[person_name].entity
|
||||
if not ent then
|
||||
return nil, false, true
|
||||
return false, nil, true
|
||||
end
|
||||
ent.object:setpos(pos)
|
||||
return "Summoned "..person_name, true
|
||||
return true, "Summoned "..person_name
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -164,13 +164,13 @@ subcmd.where = {
|
|||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not person then
|
||||
return "Specify a valid person"
|
||||
return false, "Specify a valid person"
|
||||
end
|
||||
local ent = people.people[person_name].entity
|
||||
if not ent then
|
||||
return person_name.." is inactive at "..minetest.pos_to_string(people.people[person_name].pos), true
|
||||
return true, person_name.." is inactive at "..minetest.pos_to_string(people.people[person_name].pos)
|
||||
end
|
||||
return person_name.." is at "..minetest.pos_to_string(ent.object:getpos()), true
|
||||
return true, person_name.." is at "..minetest.pos_to_string(ent.object:getpos())
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -192,16 +192,16 @@ subcmd.track = {
|
|||
person_name, person, args = get_person(args)
|
||||
if not person then
|
||||
if not people.hud_show_by_player[playername] then
|
||||
return "No person was being tracked", false
|
||||
return false, "No person was being tracked"
|
||||
end
|
||||
removecur(playername)
|
||||
local n = people.hud_show_by_player[playername].name
|
||||
people.hud_show_by_player[playername] = nil
|
||||
return "Stopped tracking "..n, true
|
||||
return true, "Stopped tracking "..n
|
||||
end
|
||||
removecur(playername)
|
||||
people.hud_show_by_player[playername] = {name=person_name}
|
||||
return "Now tracking "..person_name, true
|
||||
return true, "Now tracking "..person_name
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -213,22 +213,22 @@ subcmd.setowner = {
|
|||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not person then
|
||||
return "Specify a valid person"
|
||||
return false, "Specify a valid person"
|
||||
end
|
||||
local ent = people.people[person_name].entity
|
||||
if not ent then
|
||||
return nil, false, true
|
||||
return false, nil, true
|
||||
end
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
if playername ~= ent.owner then
|
||||
return person_name.." isn't yours, so so can't do that"
|
||||
return false, person_name.." isn't yours, so so can't do that"
|
||||
end
|
||||
end
|
||||
if not minetest.get_player_by_name(args) then
|
||||
return "No such new owner '"..args.."'"
|
||||
return false, "No such new owner '"..args.."'"
|
||||
end
|
||||
ent.owner = args
|
||||
return "Set owner of "..person_name.. " to "..args, true
|
||||
return true, "Set owner of "..person_name.. " to "..args
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ subcmd.list = {
|
|||
exec = function(playername, args)
|
||||
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
return "Only admins can list people"
|
||||
return false, "Only admins can list people"
|
||||
end
|
||||
|
||||
local count = 0
|
||||
|
@ -256,7 +256,7 @@ subcmd.list = {
|
|||
minetest.chat_send_player(playername, msg)
|
||||
count = count + 1
|
||||
end
|
||||
return count.." people", true
|
||||
return true, count.." people"
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -268,23 +268,23 @@ subcmd.tell = {
|
|||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not person then
|
||||
return "Specify a valid person"
|
||||
return false, "Specify a valid person"
|
||||
end
|
||||
local ent = people.people[person_name].entity
|
||||
if not ent then
|
||||
return nil, false, true
|
||||
return false, nil, true
|
||||
end
|
||||
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
if playername ~= ent.owner then
|
||||
return person_name.." doesn't listen to you"
|
||||
return false, person_name.." doesn't listen to you"
|
||||
end
|
||||
end
|
||||
|
||||
local sender = minetest.get_player_by_name(playername)
|
||||
if not sender then return nil, false end
|
||||
if not sender then return false, "No such sender" end
|
||||
ent.on_tell(ent, sender, args)
|
||||
return nil, true
|
||||
return true, nil
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -296,11 +296,11 @@ subcmd.skin = {
|
|||
local person, person_name
|
||||
person_name, person, args = get_person(args)
|
||||
if not args then
|
||||
return "More arguments needed"
|
||||
return false, "More arguments needed"
|
||||
end
|
||||
|
||||
if not minetest.get_modpath("skins") then
|
||||
return "Skins mod is not installed"
|
||||
return false, "Skins mod is not installed"
|
||||
end
|
||||
|
||||
if person_name == "list" then
|
||||
|
@ -311,23 +311,23 @@ subcmd.skin = {
|
|||
texlist = texlist..string.sub(skin, 11)
|
||||
end
|
||||
end
|
||||
return "Available skins: "..texlist, true
|
||||
return true, "Available skins: "..texlist
|
||||
end
|
||||
|
||||
if not person then
|
||||
return "Specify a valid person, or 'list'"
|
||||
return false, "Specify a valid person, or 'list'"
|
||||
end
|
||||
if not args then
|
||||
return "Specify skin"
|
||||
return false, "Specify skin"
|
||||
end
|
||||
|
||||
local ent = person.entity
|
||||
if not ent then
|
||||
return nil, false, true
|
||||
return false, nil, true
|
||||
end
|
||||
if not minetest.check_player_privs(playername, {server=true}) then
|
||||
if playername ~= ent.owner then
|
||||
return person_name.." isn't yours, so so can't do that"
|
||||
return false, person_name.." isn't yours, so so can't do that"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -336,10 +336,10 @@ subcmd.skin = {
|
|||
if skin == req then
|
||||
ent.props.textures = {req..".png"}
|
||||
ent:update_props()
|
||||
return "Skin updated", true
|
||||
return true, "Skin updated"
|
||||
end
|
||||
end
|
||||
return "No such skin as '"..args.."'"
|
||||
return false, "No such skin as '"..args.."'"
|
||||
|
||||
end
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ subcmd.skin = {
|
|||
-- This gets called in the usual way, as a registered chat command handler.
|
||||
-- It can also get called if a person was inactive when a command was sent
|
||||
-- and was subsequently activated.
|
||||
-- @return reply, success
|
||||
-- @return success, reply
|
||||
people.do_command = function(name, param)
|
||||
|
||||
local cmd, args
|
||||
|
@ -357,7 +357,7 @@ people.do_command = function(name, param)
|
|||
|
||||
if subcmd[cmd] then
|
||||
if args then args = string.sub(args, 2) end
|
||||
reply, success, queue_and_activate = subcmd[cmd].exec(name, args)
|
||||
success, reply, queue_and_activate = subcmd[cmd].exec(name, args)
|
||||
if queue_and_activate then
|
||||
-- Queue a command to happen when the entity wakes up,
|
||||
-- and make it wake up!
|
||||
|
@ -370,11 +370,11 @@ people.do_command = function(name, param)
|
|||
else
|
||||
person.wakecmds = {add}
|
||||
end
|
||||
return "Person is inactivate - activating...", true
|
||||
return true, "Person is inactivate - activating..."
|
||||
end
|
||||
return reply, success
|
||||
return success, reply
|
||||
end
|
||||
return "No such people command '"..cmd.."' - see '/people help'"
|
||||
return false, "No such people command '"..cmd.."' - see '/people help'"
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue