autoeat: timed eat when certain things are happening
This commit is contained in:
parent
7f09824e89
commit
aec3fb38f5
@ -1,10 +1,12 @@
|
|||||||
autoeat = {}
|
autoeat = {}
|
||||||
|
autoeat.last = 0
|
||||||
local last_step_eating = false
|
local last_step_eating = false
|
||||||
|
local interval = 1
|
||||||
|
|
||||||
function autoeat.eat()
|
function autoeat.eat()
|
||||||
local player = minetest.localplayer
|
local player = minetest.localplayer
|
||||||
local owx=player:get_wield_index()
|
local owx=player:get_wield_index()
|
||||||
|
autoeat.eating = true
|
||||||
player:set_wield_index(8)
|
player:set_wield_index(8)
|
||||||
minetest.place_node(player:get_pos())
|
minetest.place_node(player:get_pos())
|
||||||
minetest.after("0.2",function()
|
minetest.after("0.2",function()
|
||||||
@ -12,10 +14,15 @@ function autoeat.eat()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function autoeat.conditional()
|
||||||
|
if os.time() < autoeat.last + ( interval * 60 ) then return end
|
||||||
|
autoeat.last = os.time()
|
||||||
|
autoeat.eat()
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_damage_taken(function()
|
minetest.register_on_damage_taken(function()
|
||||||
if not minetest.settings:get_bool("autoeat") then return end
|
if not minetest.settings:get_bool("autoeat") then return end
|
||||||
autoeat.eat()
|
autoeat.eat()
|
||||||
autoeat.eating = true
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function()
|
minetest.register_globalstep(function()
|
||||||
@ -24,6 +31,12 @@ minetest.register_globalstep(function()
|
|||||||
elseif autoeat.eating then
|
elseif autoeat.eating then
|
||||||
last_step_eating = true
|
last_step_eating = true
|
||||||
end
|
end
|
||||||
|
if ( autofly.speed ~= 0 and minetest.settings:get_bool("autosprint") )
|
||||||
|
or (minetest.settings:get_bool("autosprintfsprint") and minetest.settings:get_bool("continuous_forward") )
|
||||||
|
or (minetest.settings:get_bool("killaura")) then
|
||||||
|
autoeat.conditional()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ local storage = minetest.get_mod_storage()
|
|||||||
local wpr=false;
|
local wpr=false;
|
||||||
local twpname=nil
|
local twpname=nil
|
||||||
local oldpm=false
|
local oldpm=false
|
||||||
|
local lpos={x=0,y=0,z=0}
|
||||||
local info=minetest.get_server_info()
|
local info=minetest.get_server_info()
|
||||||
local stprefix="autofly-".. info['address'] .. '-'
|
local stprefix="autofly-".. info['address'] .. '-'
|
||||||
|
|
||||||
@ -117,6 +118,7 @@ minetest.register_globalstep(function()
|
|||||||
if lpos then
|
if lpos then
|
||||||
local dst=vector.distance(minetest.localplayer:get_pos(),lpos)
|
local dst=vector.distance(minetest.localplayer:get_pos(),lpos)
|
||||||
speed=round2(dst,1)
|
speed=round2(dst,1)
|
||||||
|
autofly.speed=speed
|
||||||
end
|
end
|
||||||
lpos=minetest.localplayer:get_pos()
|
lpos=minetest.localplayer:get_pos()
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user