Add in lookspawn command for testing hostile mobs

This commit is contained in:
oilboi 2020-05-15 12:01:37 -04:00
parent c66d13ba20
commit 3b6bb37a64
4 changed files with 67 additions and 1 deletions

View File

@ -110,6 +110,9 @@ mob_register.mob = true
mob_register.collision_boundary = def.collision_boundary or 1
if def.pathfinds then
mob_register.path = {}
end
mobs.create_movement_functions(def,mob_register)
mobs.create_interaction_functions(def,mob_register)

View File

@ -272,7 +272,8 @@ mobs.create_interaction_functions = function(def,mob_register)
end
end
elseif self.attack_type == "explode" then
if distance < self.explosion_radius then
--mob will not explode if it cannot see you
if distance < self.explosion_radius and minetest.line_of_sight(vector.new(pos.x,pos.y+self.object:get_properties().collisionbox[5],pos.z), pos2) then
if not self.tnt_timer then
minetest.sound_play("tnt_ignite", {object = self.object, gain = 1.0,})

View File

@ -143,6 +143,10 @@ mobs.create_movement_functions = function(def,mob_register)
end
end
if def.pathfinds then
end
return(mob_register)
end

View File

@ -43,3 +43,61 @@ minetest.register_chatcommand("spawn", {
end,
})
minetest.register_chatcommand("lookspawn", {
params = "<mob>",
description = "Spawn x amount of a mob, used as /spawn 'mob' 10 or /spawn 'mob' for one",
privs = {server = true},
func = function( name, mob)
--local vars
local str = mob
local amount = 1
--checks if a player put a number of mobs
local number_of_mobs = string.find(str, "%s%d+")
--remove spaces from the string
if number_of_mobs == nil then
str:gsub("%s", "")
str = "mob:"..mob
--don't change amount
else--or find values
amount = tonumber(str:match("^.-%s(.*)"))
str = "mob:"..str:match("(.*)%s")
end
--explain formatting
if amount == nil or str == nil then
minetest.chat_send_player(name, "Format as /spawn 'mob' 20 ... or /spawn 'mob'")
end
--add amount of entities if registered
if minetest.registered_entities[str] ~= nil then
local player = minetest.get_player_by_name(name)
local pos = player:get_pos()
pos.y = pos.y + 1.625
local pos2 = vector.add(pos,vector.multiply(player:get_look_dir(),30))
local ray = minetest.raycast(pos,pos2,false,false)
local casted_pos = table.copy(pos)
if ray then
local intersection = ray:next()
if intersection and intersection.above then
casted_pos = intersection.above
end
end
--add in amount through loop
if amount > 1 then
for i = 1,amount do
minetest.add_entity(casted_pos,str)
end
else --add single
minetest.add_entity(casted_pos,str)
end
else --tell player the mob doesn't exist if not a registered entity
minetest.chat_send_player(name, str:match("^.-:(.*)"):gsub("^%l", string.upper).." is not a mob.")
end
end,
})