cleanup and add spawnfunc
This commit is contained in:
parent
165795dd99
commit
80a6f79436
95
spawn.lua
95
spawn.lua
@ -10,6 +10,7 @@ local random = water_life.random
|
|||||||
local landinterval = 120
|
local landinterval = 120
|
||||||
local waterinterval = 30
|
local waterinterval = 30
|
||||||
|
|
||||||
|
|
||||||
local function getcount(name)
|
local function getcount(name)
|
||||||
if not name then
|
if not name then
|
||||||
return 0
|
return 0
|
||||||
@ -18,8 +19,9 @@ local function getcount(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function spawnstep(dtime)
|
|
||||||
-- dtime measurement by Termos
|
local function measure_dtime()
|
||||||
|
|
||||||
if dtnum < 10001 then
|
if dtnum < 10001 then
|
||||||
dttot=dttot+dtime
|
dttot=dttot+dtime
|
||||||
dtnum=dtnum+1
|
dtnum=dtnum+1
|
||||||
@ -38,34 +40,62 @@ local function spawnstep(dtime)
|
|||||||
dtmax = 0
|
dtmax = 0
|
||||||
dttimer = 10
|
dttimer = 10
|
||||||
end
|
end
|
||||||
-- end dtime measurement
|
end
|
||||||
|
|
||||||
timer = timer + dtime
|
|
||||||
landtimer = landtimer + dtime
|
local function poison_player(player)
|
||||||
if timer > waterinterval then
|
|
||||||
for _,plyr in ipairs(minetest.get_connected_players()) do
|
local meta = player:get_meta()
|
||||||
local toomuch = false
|
|
||||||
if plyr and plyr:is_player() then
|
|
||||||
local meta = plyr:get_meta()
|
|
||||||
if meta:get_int("snakepoison") > 0 then
|
if meta:get_int("snakepoison") > 0 then
|
||||||
local score = plyr:get_hp()
|
local score = player:get_hp()
|
||||||
plyr:set_hp(score - 1)
|
player:set_hp(score - 1)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function repel_insects(player)
|
||||||
|
|
||||||
|
local meta = player:get_meta()
|
||||||
if meta:get_int("repellant") > 0 then
|
if meta:get_int("repellant") > 0 then
|
||||||
if math.floor(os.time()) - meta:get_int("repellant")
|
if math.floor(os.time()) - meta:get_int("repellant")
|
||||||
> water_life.repeltime then
|
> water_life.repeltime then
|
||||||
water_life.change_hud(plyr,"repellant",0)
|
water_life.change_hud(player,"repellant",0)
|
||||||
meta:set_int("repellant",0)
|
meta:set_int("repellant",0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function spawn_it_here(pos, mobname)
|
||||||
|
|
||||||
|
minetest.chat_send_all("Spawned: "..mobname);
|
||||||
|
minetest.add_entity(pos,mobname)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function spawnstep(dtime)
|
||||||
|
|
||||||
|
if water_life.apionly then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
-- spawn only between -50 < y < 150
|
timer = timer + dtime
|
||||||
if plyr and plyr:is_player() and plyr:get_pos().y > -50
|
landtimer = landtimer + dtime
|
||||||
and plyr:get_pos().y < 150 and not water_life.apionly then
|
if timer <= waterinterval then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _,plyr in ipairs(minetest.get_connected_players()) do
|
||||||
|
local toomuch = false
|
||||||
local pos = plyr:get_pos()
|
local pos = plyr:get_pos()
|
||||||
local yaw = plyr:get_look_horizontal()
|
local yaw = plyr:get_look_horizontal()
|
||||||
local animal = water_life.count_objects(pos)
|
local animal = water_life.count_objects(pos)
|
||||||
local meta = plyr:get_meta()
|
local meta = plyr:get_meta()
|
||||||
|
|
||||||
|
if not plyr or not plyr:is_player() then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
poison_player(plyr)
|
||||||
|
repel_insects(plyr)
|
||||||
|
if pos.y < -50 or pos.y > 150 then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
if animal.all > water_life.maxmobs then toomuch = true end
|
if animal.all > water_life.maxmobs then toomuch = true end
|
||||||
local radius = (water_life.abo * 12)
|
local radius = (water_life.abo * 12)
|
||||||
radius = random(7,radius)
|
radius = random(7,radius)
|
||||||
@ -125,8 +155,7 @@ local function spawnstep(dtime)
|
|||||||
string.match(landdata.name,"savanna"))
|
string.match(landdata.name,"savanna"))
|
||||||
and not fits and
|
and not fits and
|
||||||
landdata.temp > 15 then
|
landdata.temp > 15 then
|
||||||
local obj=minetest.add_entity(
|
spawn_it_here(landpos,mobname)
|
||||||
landpos,mobname)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -136,7 +165,7 @@ local function spawnstep(dtime)
|
|||||||
if random(100) < faktor then
|
if random(100) < faktor then
|
||||||
if string.match(landdata.name,"coniferous")
|
if string.match(landdata.name,"coniferous")
|
||||||
and landdata.temp > -5 and landdata.temp < 20 then
|
and landdata.temp > -5 and landdata.temp < 20 then
|
||||||
local obj=minetest.add_entity(landpos,mobname)
|
spawn_it_here(landpos,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -149,7 +178,7 @@ local function spawnstep(dtime)
|
|||||||
if (string.match(landdata.name,"rainforest")
|
if (string.match(landdata.name,"rainforest")
|
||||||
or string.match(landdata.name,"savanna"))
|
or string.match(landdata.name,"savanna"))
|
||||||
and landdata.temp > 20 then
|
and landdata.temp > 20 then
|
||||||
local obj=minetest.add_entity(geckopos,mobname)
|
spawn_it_here(geckopos,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -192,7 +221,7 @@ local function spawnstep(dtime)
|
|||||||
if string.match(bdata.name,"swampz") and
|
if string.match(bdata.name,"swampz") and
|
||||||
liquidflag == "swamp" then fits = true end
|
liquidflag == "swamp" then fits = true end
|
||||||
if depth < 4 and fits then
|
if depth < 4 and fits then
|
||||||
local obj=minetest.add_entity(surface,mobname)
|
spawn_it_here(surface,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -206,7 +235,7 @@ local function spawnstep(dtime)
|
|||||||
fits = true
|
fits = true
|
||||||
end
|
end
|
||||||
if depth < 4 and fits and pool == false then
|
if depth < 4 and fits and pool == false then
|
||||||
local obj=minetest.add_entity(surface,mobname)
|
spawn_it_here(surface,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -219,7 +248,7 @@ local function spawnstep(dtime)
|
|||||||
fits = true
|
fits = true
|
||||||
end
|
end
|
||||||
if depth < 3 and fits then
|
if depth < 3 and fits then
|
||||||
local obj=minetest.add_entity(surface,mobname)
|
spawn_it_here(surface,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -231,7 +260,7 @@ local function spawnstep(dtime)
|
|||||||
not bcheck["water_life:shark_buoy"] and
|
not bcheck["water_life:shark_buoy"] and
|
||||||
not animal["water_life:croc"] then
|
not animal["water_life:croc"] then
|
||||||
if depth > 4 and pool == false then
|
if depth > 4 and pool == false then
|
||||||
local obj=minetest.add_entity(
|
spawn_it_here(
|
||||||
mobkit.pos_shift(ground,{y=2}),mobname)
|
mobkit.pos_shift(ground,{y=2}),mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -242,7 +271,7 @@ local function spawnstep(dtime)
|
|||||||
local faktor = 100 - getcount(animal[mobname]) * 20
|
local faktor = 100 - getcount(animal[mobname]) * 20
|
||||||
if random(100) < faktor and (liquidflag == "sea" or liquidflag == "river") then
|
if random(100) < faktor and (liquidflag == "sea" or liquidflag == "river") then
|
||||||
if depth > 2 and not water_life.check_for_pool(nil,2,10,surface)then
|
if depth > 2 and not water_life.check_for_pool(nil,2,10,surface)then
|
||||||
local obj=minetest.add_entity(surface,mobname)
|
spawn_it_here(surface,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -289,7 +318,7 @@ local function spawnstep(dtime)
|
|||||||
local faktor = 100 - getcount(animal[mobname]) * 20
|
local faktor = 100 - getcount(animal[mobname]) * 20
|
||||||
if random(100) < faktor and liquidflag == "sea" and
|
if random(100) < faktor and liquidflag == "sea" and
|
||||||
depth > 2 then
|
depth > 2 then
|
||||||
local obj=minetest.add_entity(
|
spawn_it_here(
|
||||||
mobkit.pos_shift(ground,{y=2}),mobname)
|
mobkit.pos_shift(ground,{y=2}),mobname)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -305,7 +334,7 @@ local function spawnstep(dtime)
|
|||||||
cfish.y = cfish.y +1
|
cfish.y = cfish.y +1
|
||||||
local maxfish = random(3,7)
|
local maxfish = random(3,7)
|
||||||
for i = 1,maxfish,1 do
|
for i = 1,maxfish,1 do
|
||||||
local obj=minetest.add_entity(cfish,mobname)
|
spawn_it_here(cfish,mobname)
|
||||||
if obj then
|
if obj then
|
||||||
local entity = obj:get_luaentity()
|
local entity = obj:get_luaentity()
|
||||||
entity.base = cfish
|
entity.base = cfish
|
||||||
@ -320,7 +349,7 @@ local function spawnstep(dtime)
|
|||||||
#coraltable > 1 then
|
#coraltable > 1 then
|
||||||
local cfish = coraltable[random(#coraltable)]
|
local cfish = coraltable[random(#coraltable)]
|
||||||
cfish.y = cfish.y +1
|
cfish.y = cfish.y +1
|
||||||
local obj=minetest.add_entity(cfish,mobname)
|
spawn_it_here(cfish,mobname)
|
||||||
if obj then
|
if obj then
|
||||||
local entity = obj:get_luaentity()
|
local entity = obj:get_luaentity()
|
||||||
entity.base = cfish
|
entity.base = cfish
|
||||||
@ -344,11 +373,11 @@ local function spawnstep(dtime)
|
|||||||
end
|
end
|
||||||
if depth > 2 then
|
if depth > 2 then
|
||||||
if mobname == "water_life:fish" then
|
if mobname == "water_life:fish" then
|
||||||
local obj=minetest.add_entity(pos2,mobname)
|
spawn_it_here(pos2,mobname)
|
||||||
else
|
else
|
||||||
if getcount(animal[mobname]) < 10 then
|
if getcount(animal[mobname]) < 10 then
|
||||||
for i = 1,3,1 do
|
for i = 1,3,1 do
|
||||||
local obj=minetest.add_entity(pos2,mobname)
|
spawn_it_here(pos2,mobname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -372,18 +401,18 @@ local function spawnstep(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if gotwhale then
|
if gotwhale then
|
||||||
local obj=minetest.add_entity(surface,mobname)
|
spawn_it_here(surface,mobname)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
if landtimer > landinterval then
|
if landtimer > landinterval then
|
||||||
landtimer = 0
|
landtimer = 0
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_globalstep(spawnstep)
|
minetest.register_globalstep(spawnstep)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user