Compare commits
5 Commits
ae99e8b39a
...
0267103c97
Author | SHA1 | Date |
---|---|---|
qwertymine3 | 0267103c97 | |
qwertymine3 | 4752d7285a | |
qwertymine3 | a3b52001ba | |
qwertymine3 | def019e98d | |
qwertymine3 | 8acfb13f2b |
75
init.lua
75
init.lua
|
@ -45,7 +45,6 @@ local function is_space(pos,size)
|
|||
end
|
||||
x = x + 1
|
||||
end
|
||||
--minetest.debug("is space")
|
||||
--[[
|
||||
local _, no_air = minetest.find_nodes_in_area(pos,{x=pos.x+size.x-1,y=pos.y+size.y-1,z=pos.z+size.z-1},{"air"})
|
||||
if no_air ~= size.x*size.y*size.z then
|
||||
|
@ -70,16 +69,17 @@ end
|
|||
local max_no = 1 --per player per spawn attempt
|
||||
|
||||
--Area variables
|
||||
local width = 20
|
||||
local width = 60
|
||||
local half_width = width/2
|
||||
local height = 80
|
||||
local half_height = height/2
|
||||
|
||||
--Timing variables
|
||||
local timer = 0
|
||||
local spawn_interval = 1
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer < 1 then
|
||||
if timer < spawn_interval then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
@ -95,28 +95,19 @@ minetest.register_globalstep(function(dtime)
|
|||
{x=pos.x+rand_x,y=pos.y-half_height,z=pos.z+rand_z}
|
||||
,{x=pos.x+rand_x,y=pos.y+half_height,z=pos.z+rand_z}
|
||||
,mob.nodes)
|
||||
--[[
|
||||
if #nodes >= 1 then
|
||||
minetest.debug("nodes")
|
||||
end
|
||||
--]]
|
||||
local count = 0
|
||||
for _,obj in pairs(minetest.get_objects_inside_radius(pos, 30)) do
|
||||
if obj:is_player() then
|
||||
elseif obj:get_luaentity() and obj:get_luaentity().name == mob.name then
|
||||
count = count+1
|
||||
end
|
||||
end
|
||||
if count > mob.max_no then
|
||||
return
|
||||
end
|
||||
for i=1,#nodes do
|
||||
--Spawn limit conditions
|
||||
--These are tracked by implimentation in the mobs - I can't think
|
||||
--of a better way to do it
|
||||
if spawned > max_no then
|
||||
break
|
||||
end
|
||||
if passive and mobs.passive.now > mobs.passive.max then
|
||||
return
|
||||
elseif not passive and mobs.agressive.now > mobs.agressive.max then
|
||||
return
|
||||
end
|
||||
if mobs[mob.name].now > mobs[mob.name].max_no then
|
||||
break
|
||||
end
|
||||
|
||||
--Tests to check that placement suitiability for mob
|
||||
local lightlevel = minetest.get_node_light(
|
||||
|
@ -129,9 +120,21 @@ minetest.register_globalstep(function(dtime)
|
|||
--chance reduce overall mob spawn rate, but is useful for the programmer
|
||||
if not mob.chance then
|
||||
minetest.add_entity({x=pos.x+rand_x,y=nodes[i].y+1,z=pos.z+rand_z},mob.name)
|
||||
mobs[mob.name].now = mobs[mob.name].now + 1
|
||||
if passive then
|
||||
mobs.passive.now = mobs.passive.now + 1
|
||||
else
|
||||
mobs.agressive.now = mobs.agressive.now + 1
|
||||
end
|
||||
spawned = spawned + 1
|
||||
elseif math.random(1,1000) < mob.chance * 10 then
|
||||
minetest.add_entity({x=pos.x+rand_x,y=nodes[i].y+1,z=pos.z+rand_z},mob.name)
|
||||
mobs[mob.name].now = mobs[mob.name].now + 1
|
||||
if passive then
|
||||
mobs.passive.now = mobs.passive.now + 1
|
||||
else
|
||||
mobs.agressive.now = mobs.agressive.now + 1
|
||||
end
|
||||
spawned = spawned + 1
|
||||
end
|
||||
end
|
||||
|
@ -139,6 +142,36 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
end)
|
||||
|
||||
local mob_count_timer = 0
|
||||
local moblist_update_time = 5
|
||||
minetest.register_globalstep(function(dtime)
|
||||
mob_count_timer = mob_count_timer + dtime
|
||||
if mob_count_timer < moblist_update_time then
|
||||
return
|
||||
end
|
||||
mob_count_timer = 0
|
||||
for k,v in pairs(spawnlite.mobs) do
|
||||
v.now = 0
|
||||
end
|
||||
for k,v in pairs(minetest.luaentities) do
|
||||
if v.name and mobs[v.name] then
|
||||
mobs[v.name].now = mobs[v.name].now + 1
|
||||
end
|
||||
end
|
||||
for i=1,#spawnlite.passive do
|
||||
mobs.passive.now = mobs.passive.now + spawnlite.passive[i].now
|
||||
end
|
||||
for i=1,#spawnlite.agressive do
|
||||
mobs.agressive.now = mobs.agressive.now + spawnlite.agressive[i].now
|
||||
end
|
||||
--[[
|
||||
for k,v in pairs(minetest.luaentities) do
|
||||
minetest.debug(k)
|
||||
minetest.debug(v.name)
|
||||
end
|
||||
--]]
|
||||
end)
|
||||
|
||||
local function get_mob_size(def)
|
||||
local size = {}
|
||||
local box = def.collisionbox
|
||||
|
@ -176,7 +209,7 @@ spawnlite.register_specific = function(name,nodes,ignored_neighbors,min_light
|
|||
mob.min_light = min_light or 0
|
||||
mob.max_light = max_light or 16
|
||||
mob.chance = chance_percent_1dp
|
||||
mob.max_no = max_no or 15
|
||||
mob.max_no = max_no or 5
|
||||
mob.now = 0
|
||||
mob.min_height = min_height or -33000
|
||||
mob.max_height = max_height or 33000
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Qwertymine3
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -2,6 +2,7 @@ mobs = {}
|
|||
|
||||
function mobs:register_mob(name, def)
|
||||
minetest.register_entity(name, {
|
||||
name = name,
|
||||
hp_max = def.hp_max,
|
||||
physical = true,
|
||||
collisionbox = def.collisionbox,
|
||||
|
@ -460,8 +461,6 @@ function mobs:register_mob(name, def)
|
|||
tamed = self.tamed,
|
||||
}
|
||||
|
||||
--Spawnlite
|
||||
spawnlite_tracker("remove",self.name)
|
||||
return minetest.serialize(tmp)
|
||||
end,
|
||||
|
||||
|
|
Loading…
Reference in New Issue