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