People can now drop things

master
Ciaran Gultnieks 2014-04-05 09:13:05 +01:00
parent a378d4dccf
commit b34dcea746
4 changed files with 38 additions and 1 deletions

View File

@ -170,6 +170,10 @@ Do nothing for that many seconds. This may allow the entity to be deactivated
and unloaded, in which case it will be reactivated at the appropriate time.
Short waits may not result in deactivation.
#### drop, with item="itemspec"
Drop the given item. The itemspec is the node name, with or without a
count. e.g. "default:cobble" or "default:cobble 25".
#### 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

30
actions/drop.lua Normal file
View File

@ -0,0 +1,30 @@
local dbg
if moddebug then dbg=moddebug.dbg("people") else dbg={v1=function() end,v2=function() end,v3=function() end} end
people.actions.drop = function(state)
if not state.action.item or type(state.action.item) ~= "string" then
dbg.v1(state.ent.name.." has invalid drop action")
return true
end
local stack = state.ent.inventory:remove_item("main", state.action.item)
if not stack then
dbg.v1(state.ent.name.." couldn't drop "..state.action.item)
return true
end
local v = vector.from_speed_yaw(1, state.yaw)
local p = {x=state.pos.x+v.x, y=state.pos.y+1.5, z=state.pos.z+v.z}
local obj = minetest.add_item(p, stack)
if obj then
v.x = v.x * 2
v.y = v.y * 2 + 1
v.z = v.z * 2
obj:setvelocity(v)
end
dbg.v1(state.ent.name.." dropped "..state.action.item)
return true
end

View File

@ -19,6 +19,7 @@ dofile(people_modpath .. "/actions/face.lua")
dofile(people_modpath .. "/actions/wait.lua")
dofile(people_modpath .. "/actions/follow.lua")
dofile(people_modpath .. "/actions/go.lua")
dofile(people_modpath .. "/actions/drop.lua")
people.presets = {}

View File

@ -14,7 +14,9 @@ elseif event.type == "tell" then
z=math.floor(event.senderpos.z + 0.5)}}
elseif msg == "stop" then
action = {"wait", time=60}
elseif string.sub(msg, 1,7) == "follow " then
elseif string.sub(msg, 1, 5) == "drop " then
action = {"drop", item=string.sub(msg, 6)}
elseif string.sub(msg, 1, 7) == "follow " then
followtarget = string.sub(msg, 8)
if followtarget == "me" then
followtarget = event.sender