More stuff, including pickup implementation
parent
49d1d808d4
commit
a954a9f5b8
26
README.md
26
README.md
|
@ -219,6 +219,8 @@ Places the given item. Must be in the inventory, and in range.
|
|||
* Optional parameter: dest="node" - node name to stash in
|
||||
(e.g. "default:chest")
|
||||
|
||||
(You need either pos or dest, or nothing will happen)
|
||||
|
||||
Places items into a destination node, which should be something like a chest.
|
||||
Specifically, it needs to be a node with a "main" inventory list. So for a
|
||||
normal chest, use "default:chest" for the nodename.
|
||||
|
@ -246,9 +248,12 @@ Changes current gathering settings.
|
|||
|
||||
All parameters are optional:
|
||||
|
||||
* `nodes = {}` - list of nodes to dig
|
||||
* `items = {}` - list of items to pick up
|
||||
* `plant = ""` - seed to plant
|
||||
* `nodes = {}` - list of nodes to dig
|
||||
* `topnodes = {}` - list of nodes to dig only if there is a) air above,
|
||||
and b) the same node below - think of harvesting cactus/papyrus while
|
||||
still allowing them to grow back!
|
||||
* `items = {}` - list of items to pick up
|
||||
* `plant = ""` - seed to plant
|
||||
|
||||
So calling with no parameters at all turns off gathering.
|
||||
|
||||
|
@ -256,6 +261,21 @@ Gathering remains in effect until it is switched off, or until the person
|
|||
is re-programmed. Gathering actually happens during "go" and "wait" actions
|
||||
only (but this includes any action that uses "go" as a subaction).
|
||||
|
||||
#### attackplayer
|
||||
|
||||
Attack a player. Parameters:
|
||||
|
||||
* `name = "name"` - name of player to attack
|
||||
|
||||
The action will cancel when the player is out of range.
|
||||
|
||||
#### pickup
|
||||
|
||||
Picks up an item. Paramaters:
|
||||
|
||||
* `pos = {x,y,z}` - position of the item (required)
|
||||
* `item = "name"` - name of item, e.g. "default:dirt"
|
||||
|
||||
#### step
|
||||
Allow's the person's lua code to handle on_step itself. It will receive
|
||||
"step" events (with dtime) and should reset the action when it no longer
|
||||
|
|
|
@ -43,7 +43,7 @@ people.actions.dig = function(state)
|
|||
local n = minetest.get_node(state.action.pos)
|
||||
for _, item in pairs(minetest.get_node_drops(n.name, "")) do
|
||||
state.ent.inventory:add_item("main", ItemStack(item))
|
||||
dbg.v1(state.ent.name.." dug "..item)
|
||||
dbg.v1(state.ent.name.." got "..item.." from dig")
|
||||
end
|
||||
minetest.dig_node(state.action.pos)
|
||||
dbg.v1(state.ent.name.." dug "..n.name.." at "..minetest.pos_to_string(state.action.pos))
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
|
||||
people.actions.gather = function(state)
|
||||
state.gather = {}
|
||||
state.gather.nodes = state.action.nodes or {}
|
||||
state.gather.items = state.action.items or {}
|
||||
state.gather.plant = state.action.plant
|
||||
state.gather = {}
|
||||
state.gather.nodes = state.action.nodes or {}
|
||||
state.gather.topnodes = state.action.topnodes or {}
|
||||
state.gather.items = state.action.items or {}
|
||||
state.gather.plant = state.action.plant
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
|
@ -186,9 +186,15 @@ people.actions.go = function(state)
|
|||
if colres.collides_xz then
|
||||
dbg.v3(state.ent.name.." collided at "..minetest.pos_to_string(state.pos).." : "..dump(colres))
|
||||
-- We've hit something...
|
||||
|
||||
-- Apply some damage for bashing into something. Apart from being
|
||||
-- the right thing to do, it will also kill of things that get
|
||||
-- stuck in a wall. ;)
|
||||
state.damage = 0.5
|
||||
|
||||
if distance < 32 then
|
||||
local path = minetest.find_path(state.pos, curdest,
|
||||
distance + 2, 1, 3, "A*_noprefetch")
|
||||
distance + 6, 1, 3, "A*_noprefetch")
|
||||
if not path then
|
||||
|
||||
dbg.v2(state.ent.name.." cannot find path from "..
|
||||
|
@ -204,8 +210,7 @@ people.actions.go = function(state)
|
|||
if not state.action.intermediate or #state.action.intermediate > 10 then
|
||||
state.action.intermediate = {}
|
||||
end
|
||||
-- for i = #path, 2, -1 do -- OLD implementation - opposite order to new implementation!
|
||||
for i = 1, #path-1 do
|
||||
for i = #path, 2, -1 do
|
||||
table.insert(state.action.intermediate, 1, {x=path[i].x, y=path[i].y + 0.5, z=path[i].z})
|
||||
end
|
||||
dbg.v3(state.ent.name.." found path: "..dump(path))
|
||||
|
|
2
form.lua
2
form.lua
|
@ -33,7 +33,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
|||
end
|
||||
|
||||
-- Some things get reset when programming...
|
||||
entity.gather = {items={}, nodes={}, plant=nil}
|
||||
entity.gather = {items={}, nodes={}, topnodes={}, plant=nil}
|
||||
entity.action = nil
|
||||
entity.wait = 0
|
||||
|
||||
|
|
36
init.lua
36
init.lua
|
@ -27,6 +27,7 @@ dofile(people_modpath .. "/actions/place.lua")
|
|||
dofile(people_modpath .. "/actions/gather.lua")
|
||||
dofile(people_modpath .. "/actions/stash_and_retrieve.lua")
|
||||
dofile(people_modpath .. "/actions/attackplayer.lua")
|
||||
dofile(people_modpath .. "/actions/pickup.lua")
|
||||
|
||||
people.footpath_load()
|
||||
|
||||
|
@ -141,6 +142,7 @@ minetest.register_entity("people:person" ,{
|
|||
--
|
||||
gather = {
|
||||
nodes = {}, -- list of nodes to dig up
|
||||
topnodes = {}, -- list of topnodes to dig
|
||||
items = {}, -- list of items to pick up
|
||||
plant = nil, -- name of seed to plant, or nil
|
||||
},
|
||||
|
@ -192,9 +194,14 @@ minetest.register_entity("people:person" ,{
|
|||
end
|
||||
if restored.gather then
|
||||
self.gather = restored.gather
|
||||
-- backward compatibility...
|
||||
if not self.gather.topnodes then
|
||||
self.gather.topnodes = {}
|
||||
end
|
||||
else
|
||||
self.gather = {
|
||||
nodes = {},
|
||||
topnodes = {},
|
||||
items = {},
|
||||
}
|
||||
end
|
||||
|
@ -327,7 +334,7 @@ minetest.register_entity("people:person" ,{
|
|||
if self.action and (self.action[1] == "go" or
|
||||
self.action[1] == "follow" or
|
||||
self.action[1] == "wait") and
|
||||
(#self.gather.items + #self.gather.nodes > 0 or
|
||||
(#self.gather.items + #self.gather.nodes + #self.gather.topnodes > 0 or
|
||||
self.gather.plant) then
|
||||
local dist = 99
|
||||
if self.gather.lastpos then
|
||||
|
@ -349,17 +356,35 @@ minetest.register_entity("people:person" ,{
|
|||
done = true
|
||||
end
|
||||
end
|
||||
if not done and #self.gather.topnodes > 0 then
|
||||
dbg.v2(self.name.." looking for topnodes "..dump(self.gather.topnodes).." near "..minetest.pos_to_string(pos))
|
||||
local minp = vector.add(pos, {x=-3,y=-3,z=-3})
|
||||
local maxp = vector.add(pos, {x=3, y=3, z=3})
|
||||
local pp = minetest.find_nodes_in_area(minp, maxp, self.gather.topnodes)
|
||||
for _, ppp in pairs(pp) do
|
||||
local n = minetest.get_node(ppp)
|
||||
local pabove = vector.add(ppp, {x=0, y=1, z=0})
|
||||
if minetest.get_node(pabove).name == "air" then
|
||||
local pbelow = vector.add(ppp, {x=0, y=-1, z=0})
|
||||
if minetest.get_node(pbelow).name == n.name then
|
||||
dbg.v2(self.name.." found "..n.name.." at "..minetest.pos_to_string(ppp))
|
||||
self.action = {"dig", pos=ppp, prevaction=self.action}
|
||||
done = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not done and #self.gather.items > 0 then
|
||||
dbg.v2(self.name.." looking for items "..dump(self.gather.items).." near "..minetest.pos_to_string(pos))
|
||||
local objects = minetest.get_objects_inside_radius(
|
||||
vector.add(vector.round(pos), {x=0,y=1,z=0}), 6)
|
||||
for _, obj in ipairs(objects) do
|
||||
if obj:get_entity_name() == "__builtin:item" then
|
||||
local ent = obj:get_lua_entity()
|
||||
local ent = obj:get_luaentity()
|
||||
if ent.itemstring then
|
||||
for _, ti in ipairs(self.gather.items) do
|
||||
if string.match("^" + ti + " .*", ent.itemstring) then
|
||||
self.action = {"pickup", pos=obj:get_pos(),
|
||||
if string.match("^" .. ti .. " .*", ent.itemstring) then
|
||||
self.action = {"pickup", pos=obj:getpos(),
|
||||
item=ti, prevaction=self.action}
|
||||
done = true
|
||||
break
|
||||
|
@ -437,6 +462,9 @@ minetest.register_entity("people:person" ,{
|
|||
-- select automatically
|
||||
anim = nil,
|
||||
|
||||
-- In - 0, Out - damage to be applied.
|
||||
damage = 0,
|
||||
|
||||
-- In - the entity, in case anything needs to be called on it (avoid
|
||||
-- that if possible, but for example, getting the last collision
|
||||
-- result is currently done this way)
|
||||
|
|
|
@ -3,6 +3,66 @@ if event.type == "program" then
|
|||
mem.cur = 1
|
||||
mem.actions = {
|
||||
|
||||
-- *****************
|
||||
-- Tree Farm
|
||||
{"go", name="Jeiffel Tree Farm"},
|
||||
{"wait", time=10},
|
||||
|
||||
{"go", pos={x=-173,y=9.5,z=-244}},
|
||||
{"gather", nodes={"default:tree", "default:leaves", "default:apple"},
|
||||
items={"default:apple", "default:sapling"},
|
||||
plant="default:sapling"},
|
||||
{"go", pos={x=-173,y=9.5,z=-250}},
|
||||
{"go", pos={x=-169,y=9.5,z=-250}},
|
||||
{"go", pos={x=-169,y=9.5,z=-244}},
|
||||
{"wait", time=10},
|
||||
|
||||
-- Leave the item gathering on f0r the rest of the time - might as
|
||||
-- well clean up any that are lying around near the paths.
|
||||
{"gather", items={"default:apple", "default:sapling"}},
|
||||
|
||||
-- Chuck all harvested stuff in the recycle bin. It will end up
|
||||
-- at the factory.
|
||||
{"go", name="Jeiffel Tower"},
|
||||
{"wait", time=5},
|
||||
{"go", pos={x=-221,y=1.5,z=-187}},
|
||||
{"stash", dest="default:chest",
|
||||
items={"*default:tree",
|
||||
"*default:leaves",
|
||||
"*default:apple",
|
||||
"*default:sapling"}},
|
||||
|
||||
-- Turn off gathering now
|
||||
{"gather"},
|
||||
|
||||
|
||||
-- ********************
|
||||
-- Cactus Farm
|
||||
{"go", name="Cactus Farm"},
|
||||
{"wait", time=10},
|
||||
{"gather", topnodes={"default:cactus"}},
|
||||
{"go", pos={x=-40, y=11.5, z=-462}},
|
||||
{"gather"},
|
||||
{"go", name="Cactusville Square"},
|
||||
{"stash", items={"*default:cactus"}, dest="default:chest"},
|
||||
|
||||
|
||||
-- *****************
|
||||
-- Get some paprus on the way
|
||||
{"go", name="Sugar Station Entrance"},
|
||||
{"gather", topnodes="default:papyrus"},
|
||||
{"go", name="Industrial Corner"},
|
||||
{"gather"},
|
||||
{"go", pos={x=153, y=4.5, z=203}},
|
||||
{"go", pos={x=156, y=4.5, z=202}},
|
||||
{"go", pos={x=156, y=4.5, z=199}},
|
||||
{"stash", items={"*default:papyrus"}, dest="default:chest"},
|
||||
{"go", pos={x=156, y=4.5, z=202}},
|
||||
{"go", pos={x=153, y=4.5, z=203}},
|
||||
{"go", name="Industrial Estate"},
|
||||
|
||||
-- *****************
|
||||
-- Ciaran's Farm
|
||||
{"go", name="Ciaran's Farm"},
|
||||
{"wait", time=10},
|
||||
|
||||
|
@ -25,6 +85,7 @@ if event.type == "program" then
|
|||
{"go", pos={x=178, y=11.5, z=346}},
|
||||
{"go", pos={x=178, y=11.5, z=319}},
|
||||
{"go", pos={x=182, y=11.5, z=319}},
|
||||
{"gather", nodes={"farming:weed", "farming_plus:potato"}, plant="farming_plus:potato_seed"},
|
||||
{"go", pos={x=182, y=11.5, z=346}},
|
||||
{"wait", time=5},
|
||||
{"gather"},
|
||||
|
@ -57,11 +118,13 @@ if event.type == "program" then
|
|||
{"wait", time=10},
|
||||
|
||||
{"go", pos={x=167,y=11.5,z=316}},
|
||||
{"stash", pos={x=167,y=12,z=314}, items={"farming:seed_wheat 20",
|
||||
"farming:seed_cotton 20",
|
||||
"farming_plus:carrot_seed 20",
|
||||
"farming_plus:tomato_seed 20",
|
||||
"farming_plus:strawberry_seed 20"}},
|
||||
{"stash", pos={x=167,y=12,z=314},
|
||||
items={"farming:seed_wheat 20",
|
||||
"farming:seed_cotton 20",
|
||||
"farming_plus:carrot_seed 20",
|
||||
"farming_plus:tomato_seed 20",
|
||||
"farming_plus:potato_seed 20",
|
||||
"farming_plus:strawberry_seed 20"}},
|
||||
{"go", name="Ciaran's Farm"},
|
||||
{"go", pos={x=174, y=11.5, z=319}},
|
||||
|
||||
|
@ -70,21 +133,19 @@ if event.type == "program" then
|
|||
"*farming:wheat", "*farming_plus:carrot_item", "*farming:seed_wheat",
|
||||
"*farming_plus:carrot_seed", "*farming:seed_cotton",
|
||||
"*farming_plus:tomato_seed", "*farming_plus:tomato_item",
|
||||
"*farming_plus:potato_seed", "*farming_plus:potato_item",
|
||||
"*farming_plus:strawberry_item", "*farming_plus:strawberry_seed"}},
|
||||
|
||||
{"go", pos={x=174, y=11.5, z=319}},
|
||||
|
||||
-- *****************
|
||||
-- A bit of random wandering f0r test purposes
|
||||
{"go", name="Building Supplies Shop"},
|
||||
{"go", pos={x=127, y=12.5, z=-54}},
|
||||
{"wait", time=20},
|
||||
{"go", pos={x=133, y=12.5, z=-54}},
|
||||
{"wait", time=20},
|
||||
{"go", pos={x=127, y=12.5, z=-54}},
|
||||
{"wait", time=60},
|
||||
{"go", name="Building Supplies Shop"},
|
||||
|
||||
{"wait", time=10},
|
||||
{"go", name="Mia's Shop"},
|
||||
{"wait", time=10},
|
||||
{"go", name="Adventure Shop"},
|
||||
{"go", name="Lava Falls"},
|
||||
--{"go", name="Lava Falls"},
|
||||
{"go", name="Jake's House"},
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue