Code: Select all
2019-12-02 20:12:27: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'zombiestrd' in callback luaentity_Step(): ...storage/emulated/0/Minetest/mods/mobkit_dev/init.lua:994: attempt to index field 'lastvelocity' (a nil value)
2019-12-02 20:12:27: ERROR[Main]: stack traceback:
2019-12-02 20:12:27: ERROR[Main]: ...storage/emulated/0/Minetest/mods/mobkit_dev/init.lua:994: in function <...storage/emulated/0/Minetest/mods/mobkit_dev/init.lua:984>
2019-12-02 20:12:27: ERROR[Main]: [C]: in function 'add_entity'
2019-12-02 20:12:27: ERROR[Main]: ...age/emulated/0/Minetest/mods/zombiestrd_dev/init.lua:234: in function '?'
2019-12-02 20:12:27: ERROR[Main]: ...torage/emulated/0/Minetest/builtin/game/register.lua:419: in function <...torage/emulated/0/Minetest/builtin/game/register.lua:399>
2019-12-02 20:12:27: ACTION[Server]: singleplayer leaves game. List of players:
2019-12-02 20:12:27: ACTION[Main]: Server: Shutting down
Code: Select all
function mobkit.actfunc(self, staticdata, dtime_s)
self.logic = self.logic or self.brainfunc
self.physics = self.physics or mobkit.physics
self.lqueue = {}
self.hqueue = {}
self.nearby_objects = {}
self.nearby_players = {}
self.pos_history = {}
self.path_dir = 1
self.time_total = 0
self.water_drag = self.water_drag or 1
local name = self.name
local head = minetest.registered_entities[name].head
if head then
if self.head then -- check if a head for the object was already attached before the game restart
self.head:set_detach() -- then remove it and reset the new one with updated coords
self.head:remove()
end
local rel_pos = minetest.registered_entities[head].pos
local pos = self.object:get_pos()
local real_pos = {x = pos.x+rel_pos.x, y=pos.y+rel_pos.y, z=pos.z+rel_pos.z}
local head_obj = minetest.add_entity(rel_pos, head)
local rot = self.object:get_rotation()
head_obj:set_attach(self.object, "", rel_pos, {x=deg(rot.x), y=deg(rot.y), z=deg(rot.z)})
self.head = head_obj
else -- if a head was set before and an user deleted 'head' field after, delete that head
if self.head then
self.head:set_detach()
self.head:remove()
self.head = nil
end
end
local sdata = minetest.deserialize(staticdata)
if sdata then
for k,v in pairs(sdata) do
self[k] = v
end
end
if self.timeout and self.timeout>0 and dtime_s > self.timeout and next(self.memory)==nil then
self.object:remove()
end
if not self.memory then -- this is the initial activation
self.memory = {}
-- texture variation
if #self.textures > 1 then self.texture_no = random(#self.textures) end
end
-- apply texture
if self.texture_no then
local props = {}
props.textures = {self.textures[self.texture_no]}
self.object:set_properties(props)
end
--hp
self.max_hp = self.max_hp or 10
self.hp = self.hp or self.max_hp
--armor
if type(self.armor_groups) ~= 'table' then
self.armor_groups={}
end
self.armor_groups.immortal = 1
self.object:set_armor_groups(self.armor_groups)
self.buoyancy = self.buoyancy or 0
self.oxygen = self.oxygen or self.lung_capacity
self.lastvelocity = {x=0,y=0,z=0}
self.sensefunc=sensors()
end
function mobkit.stepfunc(self,dtime) -- not intended to be modified
self.dtime = min(dtime,0.2)
self.height = mobkit.get_box_height(self)
-- physics comes first
-- self.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
local vel = self.object:get_velocity()
-- if self.lastvelocity.y == vel.y then
-- if abs(self.lastvelocity.y-vel.y)<0.001 then
if self.lastvelocity.y==0 and vel.y==0 then -- ERROR! No 'lastvelocity' available in 'self'
self.isonground = true
else
self.isonground = false
end
self:physics()
if self.logic then
if self.view_range then self:sensefunc() end
self:logic()
execute_queues(self)
end
self.lastvelocity = self.object:get_velocity()
self.time_total=self.time_total+self.dtime
end