Various stuff, including track command

master
Ciaran Gultnieks 2014-04-08 21:18:29 +01:00
parent b3f618c881
commit ce2a8f766e
5 changed files with 830 additions and 717 deletions

View File

@ -285,6 +285,11 @@ Lists all people in the word, and their current status (active/inactive).
Sets the skin of the person to the named one. (Or use 'list' to get a
list of available skins, which come from the skins mod).
### /people track `name`
Track the given person (location and distance away) on the HUD.
Use without a parameter to switch it off.
## Autonomy and Activation
People are 'autonomous' - i.e. they will continue to act even when no player

View File

@ -211,7 +211,9 @@ people.actions.go = function(state)
if state.action.footpathdest or state.action.intermediate then
-- If we arrived at the pos, but we still have a
-- pathdest or intermediate dest, we carry on to do that.
state.action.pos = nil
if state.action.footpathdest then
state.action.pos = nil
end
return false
end
-- We've finished!

View File

@ -9,17 +9,17 @@ if moddebug then dbg=moddebug.dbg("people") else dbg={v1=function() end,v2=funct
-- actually exists.
local get_person = function(args)
if not args then return nil, nil, nil end
if not args then return nil, nil, nil end
person_name, args = string.match(args, "^([^ ]+)(.*)")
person_name, args = string.match(args, "^([^ ]+)(.*)")
if person_name and not people.is_valid_name(person_name) then
return nil, nil, nil
end
local person
if person_name then person = people.people[person_name] end
if args then args = string.sub(args, 2) end
return person_name, person, args
if person_name and not people.is_valid_name(person_name) then
return nil, nil, nil
end
local person
if person_name then person = people.people[person_name] end
if args then args = string.sub(args, 2) end
return person_name, person, args
end
@ -35,265 +35,296 @@ end
local subcmd = {}
subcmd.help = {
params = "[<subcmd>]",
desc = "You're being silly, aren't you?",
exec = function(playername, args)
params = "[<subcmd>]",
desc = "You're being silly, aren't you?",
exec = function(playername, args)
if args and args ~= "" then
if not subcmd[args] then
return "No such subcommand"
end
return "/people "..args.." "..subcmd[args].params.." - "..
subcmd[args].desc, true
end
if args and args ~= "" then
if not subcmd[args] then
return "No such subcommand"
end
return "/people "..args.." "..subcmd[args].params.." - "..
subcmd[args].desc, true
end
local msg = "Subcommands (use /people help <subcmd> for more):"
for c, _ in pairs(subcmd) do
msg = msg.." "..c
end
return msg, true
end
local msg = "Subcommands (use /people help <subcmd> for more):"
for c, _ in pairs(subcmd) do
msg = msg.." "..c
end
return msg, true
end
}
subcmd.create = {
params = "<name>",
desc = "Create a person with the given name at your current location",
exec = function(playername, args)
params = "<name>",
desc = "Create a person with the given name at your current location",
exec = function(playername, args)
if not minetest.check_player_privs(playername, {server=true}) then
return "Only admins can create people"
end
if not minetest.check_player_privs(playername, {server=true}) then
return "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"
end
if person then
return "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"
end
local pos = player:getpos()
local obj = minetest.add_entity(pos, "people:person")
if not obj then
return "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
end
local person, person_name
person_name, person, args = get_person(args)
if not person_name then
return "Name needs to be specified"
end
if person then
return "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"
end
local pos = player:getpos()
local obj = minetest.add_entity(pos, "people:person")
if not obj then
return "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
end
}
subcmd.delete = {
params = "<name>",
desc = "Delete the person with the given name",
exec = function(playername, args)
params = "<name>",
desc = "Delete the person with the given name",
exec = function(playername, args)
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "Specify a valid person"
end
local ent = people.people[person_name].entity
if not ent then
return nil, false, 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"
end
end
ent.object:remove()
people.people[person_name] = nil
return "Deleted "..person_name, true
end
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "Specify a valid person"
end
local ent = people.people[person_name].entity
if not ent then
return nil, false, 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"
end
end
ent.object:remove()
people.people[person_name] = nil
return "Deleted "..person_name, true
end
}
subcmd.summon = {
params = "<name>",
desc = "Move the person with the given name to your current location",
exec = function(playername, args)
params = "<name>",
desc = "Move the person with the given name to your current location",
exec = function(playername, args)
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "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"
end
local pos = player:getpos()
local ent = people.people[person_name].entity
if not ent then
return nil, false, true
end
ent.object:setpos(pos)
return "Summoned "..person_name, true
end
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "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"
end
local pos = player:getpos()
local ent = people.people[person_name].entity
if not ent then
return nil, false, true
end
ent.object:setpos(pos)
return "Summoned "..person_name, true
end
}
subcmd.where = {
params = "<name>",
desc = "Report the location and status of the person with the given name",
exec = function(playername, args)
params = "<name>",
desc = "Report the location and status of the person with the given name",
exec = function(playername, args)
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "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
end
return person_name.." is at "..minetest.pos_to_string(ent.object:getpos()), true
end
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "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
end
return person_name.." is at "..minetest.pos_to_string(ent.object:getpos()), true
end
}
subcmd.track = {
params = "[<name>]",
desc = "Track a person on the HUD (or remove, with no parameter)",
exec = function(playername, args)
local function removecur(playername)
if not people.hud_show_by_player[playername] then return end
local hudid = people.hud_show_by_player[playername].hudid
if hudid then
local player = minetest.get_player_by_name(playername)
player:hud_remove(hudid)
end
end
local person, person_name
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
end
removecur(playername)
local n = people.hud_show_by_player[playername].name
people.hud_show_by_player[playername] = nil
return "Stopped tracking "..n, true
end
removecur(playername)
people.hud_show_by_player[playername] = {name=person_name}
return "Now tracking "..person_name, true
end
}
subcmd.setowner = {
params = "<name> <owner>",
desc = "Set the owner of the given person to the given player",
exec = function(playername, args)
params = "<name> <owner>",
desc = "Set the owner of the given person to the given player",
exec = function(playername, args)
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "Specify a valid person"
end
local ent = people.people[person_name].entity
if not ent then
return nil, false, 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"
end
end
if not minetest.get_player_by_name(args) then
return "No such new owner '"..args.."'"
end
ent.owner = args
return "Set owner of "..person_name.. " to "..args, true
end
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "Specify a valid person"
end
local ent = people.people[person_name].entity
if not ent then
return nil, false, 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"
end
end
if not minetest.get_player_by_name(args) then
return "No such new owner '"..args.."'"
end
ent.owner = args
return "Set owner of "..person_name.. " to "..args, true
end
}
subcmd.list = {
params = "",
desc = "List all people in the world",
exec = function(playername, args)
params = "",
desc = "List all people in the world",
exec = function(playername, args)
if not minetest.check_player_privs(playername, {server=true}) then
return "Only admins can list people"
end
if not minetest.check_player_privs(playername, {server=true}) then
return "Only admins can list people"
end
local count = 0
for k, v in pairs(people.people) do
local msg = k.." : "
if v.entity then
msg = msg.."active at "..minetest.pos_to_string(v.entity.object:getpos())
else
if not v.waketime then
msg = msg.."inactive (for unknown time!?)"
else
msg = msg.."inactive for another "..v.waketime - minetest.get_gametime().."s at "..minetest.pos_to_string(v.pos)
end
end
minetest.chat_send_player(playername, msg)
count = count + 1
end
return count.." people", true
end
local count = 0
for k, v in pairs(people.people) do
local msg = k.." : "
if v.entity then
msg = msg.."active at "..minetest.pos_to_string(v.entity.object:getpos())
else
if not v.waketime then
msg = msg.."inactive (for unknown time!?)"
else
msg = msg.."inactive for another "..v.waketime - minetest.get_gametime().."s at "..minetest.pos_to_string(v.pos)
end
end
minetest.chat_send_player(playername, msg)
count = count + 1
end
return count.." people", true
end
}
subcmd.tell = {
params = "<name> <message>",
desc = "Send a message to the given person",
exec = function(playername, args)
if args == "help" then
end
params = "<name> <message>",
desc = "Send a message to the given person",
exec = function(playername, args)
if args == "help" then
end
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "Specify a valid person"
end
local ent = people.people[person_name].entity
if not ent then
return nil, false, true
end
local person, person_name
person_name, person, args = get_person(args)
if not person then
return "Specify a valid person"
end
local ent = people.people[person_name].entity
if not ent then
return nil, false, 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"
end
end
if not minetest.check_player_privs(playername, {server=true}) then
if playername ~= ent.owner then
return person_name.." doesn't listen to you"
end
end
local sender = minetest.get_player_by_name(playername)
if not sender then return end
ent.on_tell(ent, sender, args)
end
local sender = minetest.get_player_by_name(playername)
if not sender then return end
ent.on_tell(ent, sender, args)
end
}
subcmd.skin = {
params = "(<name> <skin>)|(<list>)",
desc = "Set a person's skin, or list available skins",
exec = function(playername, args)
params = "(<name> <skin>)|(<list>)",
desc = "Set a person's skin, or list available skins",
exec = function(playername, args)
local person, person_name
person_name, person, args = get_person(args)
if not args then
return "More arguments needed"
end
local person, person_name
person_name, person, args = get_person(args)
if not args then
return "More arguments needed"
end
if not minetest.get_modpath("skins") then
return "Skins mod is not installed"
end
if not minetest.get_modpath("skins") then
return "Skins mod is not installed"
end
if person_name == "list" then
local texlist = ""
for _, skin in ipairs(skins.list) do
if string.match(skin, "^character_") then
if texlist ~= "" then texlist = texlist.." " end
texlist = texlist..string.sub(skin, 11)
end
end
return "Available skins: "..texlist, true
end
if person_name == "list" then
local texlist = ""
for _, skin in ipairs(skins.list) do
if string.match(skin, "^character_") then
if texlist ~= "" then texlist = texlist.." " end
texlist = texlist..string.sub(skin, 11)
end
end
return "Available skins: "..texlist, true
end
if not person then
return "Specify a valid person, or 'list'"
end
if not args then
return "Specify skin"
end
if not person then
return "Specify a valid person, or 'list'"
end
if not args then
return "Specify skin"
end
local ent = person.entity
if not ent then
return nil, false, 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"
end
end
local ent = person.entity
if not ent then
return nil, false, 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"
end
end
local req = "character_"..args
for _, skin in ipairs(skins.list) do
if skin == req then
ent.props.textures = {req..".png"}
ent:update_props()
return "Skin updated", true
end
end
return "No such skin as '"..args.."'"
local req = "character_"..args
for _, skin in ipairs(skins.list) do
if skin == req then
ent.props.textures = {req..".png"}
ent:update_props()
return "Skin updated", true
end
end
return "No such skin as '"..args.."'"
end
end
}
--- Handle a chat command.
@ -302,44 +333,44 @@ subcmd.skin = {
-- and was subsequently activated.
people.do_command = function(name, param)
local cmd, args
cmd, args = string.match(param, "^([^ ]+)(.*)")
if not cmd then return subcmd.help.exec() end
local cmd, args
cmd, args = string.match(param, "^([^ ]+)(.*)")
if not cmd then return subcmd.help.exec() end
if subcmd[cmd] then
if args then args = string.sub(args, 2) end
reply, success, 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!
local person
_, person, _ = get_person(args)
person.waketime = minetest.get_gametime()
local add = {name, param}
if person.wakecmds then
table.insert(person.wakecmds, add)
else
person.wakecmds = {add}
end
return "Person is inactivate - activating...", true
end
return reply, success
end
return "No such people command '"..cmd.."' - see 'people help'"
if subcmd[cmd] then
if args then args = string.sub(args, 2) end
reply, success, 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!
local person
_, person, _ = get_person(args)
person.waketime = minetest.get_gametime()
local add = {name, param}
if person.wakecmds then
table.insert(person.wakecmds, add)
else
person.wakecmds = {add}
end
return "Person is inactivate - activating...", true
end
return reply, success
end
return "No such people command '"..cmd.."' - see 'people help'"
end
minetest.register_chatcommand("people", {
params = "<cmd> [name] [args]",
description = "Commands for working with the people module. '/people help' for help.",
func = people.do_command
params = "<cmd> [name] [args]",
description = "Commands for working with the people module. '/people help' for help.",
func = people.do_command
})
minetest.register_chatcommand("tell", {
params = "<name> <message>",
description = "Send a message to a 'person' from the people module",
func = function(name, param)
subcmd.tell.exec(name, param)
end
params = "<name> <message>",
description = "Send a message to a 'person' from the people module",
func = function(name, param)
subcmd.tell.exec(name, param)
end
})

980
init.lua

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ if event.type == "program" then
mem.actions = {
{"go", name="Ciaran's Farm"},
{"wait", time=10},
{"go", pos={x=174, y=11.5, z=319}},
{"gather", nodes={"farming:weed", "farming:wheat_8"}, plant="farming:seed_wheat"},
{"go", pos={x=174, y=11.5, z=346}},
@ -11,17 +12,25 @@ if event.type == "program" then
{"go", pos={x=178, y=11.5, z=319}},
{"go", pos={x=182, y=11.5, z=319}},
{"go", pos={x=182, y=11.5, z=346}},
{"wait", time=5},
{"gather"},
{"wait", time=20},
{"go", pos={x=191, y=11.5, z=347}},
{"gather", nodes={"farming:weed", "farming:cotton_8"}, plant="farming:seed_cotton"},
{"go", pos={x=191, y=11.5, z=341}},
{"gather", nodes={"farming:weed", "farming:carrot_3"}, plant="farming_plus:carrot_seed"},
{"go", pos={x=191, y=11.5, z=329}},
{"wait", time=5},
{"gather"},
{"wait", time=20},
{"go", pos={x=191, y=11.5, z=332}},
{"gather", nodes={"farming:weed", "farming_plus:carrot"}, plant="farming_plus:carrot_seed"},
{"go", pos={x=191, y=11.5, z=330}},
{"wait", time=5},
{"gather"},
{"go", pos={x=174, y=11.5, z=341}},
{"stash", dest="default:chest", items={"farming:weed", "farming:string", "farming:wheat", "farming_plus:carrot", "farming:seed_wheat", "farming_plus:carrot_seed", "farming:seed_cotton"}},
{"go", name="Sugar Harbour"},
}
elseif event.type == "act" then