Actually add attack support
parent
c60362027e
commit
49d1d808d4
|
@ -0,0 +1,52 @@
|
|||
|
||||
local dbg
|
||||
if moddebug then dbg=moddebug.dbg("people") else dbg={v1=function() end,v2=function() end,v3=function() end} end
|
||||
|
||||
people.actions.attackplayer = function(state)
|
||||
|
||||
if not state.action.name or type(state.action.name) ~= "string" then
|
||||
dbg.v1(state.ent.name.." has invalid attack target")
|
||||
return true
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(state.action.name)
|
||||
if not player then
|
||||
dbg.v1(state.ent.name.." can't find "..state.action.name.." to follow them")
|
||||
return true
|
||||
end
|
||||
|
||||
local targetpos = player:getpos()
|
||||
local dir = vector.subtract(targetpos, state.pos)
|
||||
local dist = vector.length(dir)
|
||||
if dist > 30 then
|
||||
dbg.v1(state.ent.name.." target out of range")
|
||||
return true
|
||||
end
|
||||
if dist < 2 then
|
||||
-- We're near enough...
|
||||
local caps = {
|
||||
full_punch_interval=2,
|
||||
groupcaps={
|
||||
fleshy={times={1, 1, 1}},
|
||||
snappy={times={1, 1, 1}},
|
||||
},
|
||||
damage_groups = {fleshy=5},
|
||||
}
|
||||
player:punch(state.ent.object, 5, caps, dir)
|
||||
state.yaw = vector.get_yaw(state.pos, targetpos)
|
||||
state.wait = 2
|
||||
return false
|
||||
end
|
||||
|
||||
local dir = math.random(math.pi*2)
|
||||
targetpos = vector.add(targetpos, vector.from_speed_yaw(2, dir))
|
||||
targetpos = vector.round(targetpos)
|
||||
-- TODO find surface Y
|
||||
dbg.v3(state.ent.name.." attacking "..state.action.name.." via "..minetest.pos_to_string(targetpos))
|
||||
state.action = {"go", pos=targetpos, prevaction=state.action}
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue