First commit

This commit is contained in:
TomasJLuis 2015-04-06 17:06:05 +02:00
commit 80c3bf2f4a
28 changed files with 578 additions and 0 deletions

288
api.lua Normal file
View File

@ -0,0 +1,288 @@
slimes = {}
function slimes:register_slime (name, def)
local defbox = def.size/2
minetest.register_entity(name,{
initial_properties = {
name = name,
hp_max = def.max_hp,
visual_size = {x = def.size, y = def.size, z = def.size},
visual = "cube",
textures = def.textures, -- top, bottom, front, back, left, right
collisionbox = {-defbox, -defbox, -defbox, defbox, defbox, defbox},
physical = true,
},
alpha = 160,
timer = 6,
timer2 = 1,
timer3 = 0, --regularly check if slime touches ground and possibly set x/z velocity/acceleration to 0
yaw = 0,
direction = {},
status = 2, --1 = jump, 2 = rotate
found_target = false,
-- ON ACTIVATE --
on_activate = function(self)
self.object:setacceleration({x = 0, y = -def.gravity, z = 0})
end,
-- ON PUNCH --
on_punch = function(self)
local pos = self.object:getpos()
minetest.sound_play(def.sounds.damage.file, {pos = pos,gain = (def.sounds.damage.gain or 0.25)})
effect(pos, 20*math.random(), def.blood)
check_for_slime_death (self,def)
end,
-- ON STEP --
on_step = function(self, dtime)
self.timer2 = self.timer2 + dtime
local pos = self.object:getpos()
if self.status == 2 and (self.timer2 >= 0.5) then
self.timer2 = 1.2
self.status = 1
-- FIXME
if slime_lonely(pos) and not minetest.env:find_node_near(pos, 24, def.spawn) then
self.object:remove()
end
-- FIXME improve IA
local objs = minetest.env:get_objects_inside_radius(pos, 24)
local ppos = {}
self.found_target = false
self.yaw = math.random() * 360
for i, obj in ipairs(objs) do
if obj:is_player() and damage_enabled and not def.passive then self.found_target = obj break end
if self.found_target == false
and obj:get_luaentity()
and (obj:get_luaentity().name == "slimes:" .. def.class .. "biga"
or obj:get_luaentity().name == "slimes:" .. def.class .. "medium") then
self.found_target = obj
end
end
if self.found_target ~= false then
local target = self.found_target:getpos()
ppos = {x = target.x - pos.x, z = target.z - pos.z}
if ppos.x ~= 0 and ppos.z ~= 0 then --found itself as an object
self.yaw = math.abs(math.atan(ppos.x/ppos.z) - math.pi / 2)
if ppos.z < 0 then self.yaw = self.yaw + math.pi end
--self.found_target = true
end
end
self.object:setyaw(self.yaw)
self.object:set_properties({automatic_rotate = 0})
self.direction = {x = math.cos(self.yaw)*2, y = 6, z = math.sin(self.yaw)*2}
minetest.sound_play(def.sounds.jump.file, {pos = pos,gain = (def.sounds.jump.gain or 0.25)})
self.object:set_properties({visual_size = {x = def.size, y = def.size - (def.size/8), z = def.size}})
end
self.timer = self.timer + dtime
self.timer3 = self.timer3 + dtime
if self.timer2 > 1.3 and self.object:getvelocity().y == 0 then
self.object:setvelocity(self.direction)
self.object:setacceleration({x = self.direction.x/5, y = -def.gravity, z = self.direction.z/5})
self.timer2 = 0
self.object:set_properties({visual_size = {x = def.size, y = def.size + (def.size/8), z = def.size}})
end
if (self.timer >= 6
or (self.timer >= 1
and self.found_target ~= false))
and self.object:getvelocity().y == 0 then
self.timer = 0
self.timer2 = 0
self.status = 2
if self.found_target == false then self.object:set_properties({automatic_rotate = math.pi * 8}) end
minetest.sound_play(def.sounds.land.file, {pos = pos,gain = (def.sounds.land.gain or 0.25)})
local n = minetest.get_node(pos)
if def.footprint
and minetest.get_item_group(n.name, "water") == 0
then minetest.set_node(pos, {name=def.footprint}) end
effect(pos, 20*math.random(), def.blood)
self.object:set_properties({visual_size = {x = def.size, y = def.size - (def.size/8), z = def.size}})
if damage_enabled then
local tod = minetest.get_timeofday()
--FIXME water and lava damage detection is not working like it should.
-- sunlight damage
if def.light_damage and def.light_damage ~= 0
and minetest.get_item_group(n.name, "water") == 0 -- no sun damage in water
and pos.y > 0
and (minetest.get_node_light(pos) or 0) > 10 -- direct sunlight (was 4)
and tod > 0.2 and tod < 0.8 then
self.object:set_hp(self.object:get_hp()-def.light_damage)
effect(pos, 20*math.random(), "tnt_smoke.png")
minetest.chat_send_all("me derrito ".. (minetest.get_node_light(pos) or 0))
end
-- water damage
if def.water_damage and def.water_damage ~= 0
and minetest.get_item_group(n.name, "water") ~= 0 then
self.object:set_hp(self.object:get_hp()-def.water_damage)
effect(pos, 20*math.random(), "bubble.png")
end
-- lava damage
if def.lava_damage and def.lava_damage ~= 0
and minetest.get_item_group(n.name, "lava") ~= 0 then
self.object:set_hp(self.object:get_hp()-def.lava_damage)
effect(pos, 20*math.random(), "fire_basic_flame.png")
end
-- fall damage
if self.fall_damage == 1 and self.object:getvelocity().y == 0 then
local d = self.old_y - self.object:getpos().y
self.old_y = self.object:getpos().y
if d > 5 then
self.object:set_hp(self.object:get_hp() - math.floor(d - 5))
end
end
check_for_slime_death (self,def)
local objs = minetest.env:get_objects_inside_radius(pos, def.size*1.75)
for i, obj in ipairs(objs) do
if obj:is_player() and not def.passive then
obj:punch(self.object, 1.0, {full_punch_interval=1.0,damage_groups = {fleshy=def.damage}})
minetest.sound_play(def.sounds.attack.file, {pos = pos,gain = (def.sounds.attack.gain or 0.25)})
end
end
end
end
if self.timer3 > 0.07 then
local vel = self.object:getvelocity()
if vel.y == 0 and (vel.x ~= 0 or vel.z ~= 0) then
self.object:setvelocity({x = 0, y = 0, z = 0})
self.object:setacceleration({x = 0, y = -def.gravity, z = 0})
self.object:set_properties({visual_size = {x = def.size, y = def.size, z = def.size}})
end
self.timer3 = 0
end
end,
})
end
-- check if slime is alone
function slime_lonely (pos)
local objs = minetest.env:get_objects_inside_radius(pos, 32)
for i, obj in pairs(objs) do
if obj:is_player() then return false end
end
return true
end
-- check for death
function check_for_slime_death(self,def)
if self.object:get_hp() > 0 then return end
local pos = self.object:getpos()
pos.y = pos.y + 0.5
if (def.sounds.death.file ~= nil ) then minetest.sound_play(def.sounds.death.file, {pos = pos,gain = (def.sounds.death.gain or 0.25)}) end
self.object:remove()
local chance = def.drops.chance
if math.random(1, def.drops.chance+1) == 1 or def.drops.chance == 0 then
local min = def.drops.min
local max = def.drops.max
local num = math.floor(math.random(min, max+1))
if def.drops.type == "item" then
for i=1,num do minetest.env:add_item(pos, def.drop) end
end
if def.drops.type == "entity" then
for i=1,num do minetest.env:add_entity({x=pos.x, y=pos.y + (def.size*math.random()), z=pos.z + (def.size*math.random())}, def.drops.name) end
end
end
end
-- particle effects
function effect(pos, amount, texture)
minetest.add_particlespawner({
amount = amount,
time = 0.25,
minpos = pos,
maxpos = pos,
minvel = {x=-0, y=-2, z=-0},
maxvel = {x=2, y=2, z=2},
minacc = {x=-4, y=-4, z=-4},
maxacc = {x=4, y=4, z=4},
minexptime = 0.1,
maxexptime = 1,
minsize = 0.5,
maxsize = 1,
texture = texture,
})
end
-- spawn slimes
slimes.spawn = {}
function slimes:register_spawn(name, nodes, neighbors, max_light, min_light, chance, active_object_count, max_height)
slimes.spawn[name] = true
minetest.register_abm({
nodenames = nodes,
neighbors = neighbors,
interval = 30,
chance = chance,
action = function(pos, node, _, active_object_count_wider)
-- do not spawn if too many active in area
if active_object_count_wider > active_object_count
or not pos then
return
end
-- mobs cannot spawn inside protected areas
if minetest.is_protected(pos, "") then
return
end
-- spawn above node
pos.y = pos.y + 1
-- check if light and height levels are ok to spawn
local light = minetest.get_node_light(pos)
if not light or light > max_light or light < min_light
or pos.y > max_height then
return
end
-- are we spawning inside a solid node?
local nod = minetest.get_node_or_nil(pos)
if not nod or not minetest.registered_nodes[nod.name]
or minetest.registered_nodes[nod.name].walkable == true then
return
end
pos.y = pos.y + 1
nod = minetest.get_node_or_nil(pos)
if not nod or not minetest.registered_nodes[nod.name]
or minetest.registered_nodes[nod.name].walkable == true then
return
end
-- spawn mob half block higher
pos.y = pos.y - 0.5
minetest.add_entity(pos, name)
end
})
end

2
depends.txt Normal file
View File

@ -0,0 +1,2 @@
mesecons_materials
default:tnt

94
greenslimes.lua Normal file
View File

@ -0,0 +1,94 @@
-- sounds
local green_sounds = {
damage = { file = "green_slime_damage", gain = 0.25},
death = { file = "green_slime_death", gain = 0.25},
jump = { file = "green_slime_jump", gain = 0.25},
land = { file = "green_slime_land", gain = 0.25},
attack = { file = "green_slime_attack", gain = 0.25},
random = {}
}
-- textures: top, bottom, front, back, left, right
local green_textures = {"green_slime_top.png", "green_slime_bottom.png", "green_slime_front.png", "green_slime_sides.png", "green_slime_sides.png", "green_slime_sides.png"}
slimes:register_slime ("slimes:greenbig", {
name = "slimes:greenbig",
type = "monster",
class = "green",
passive = false,
size = 2,
textures = green_textures,
blood = "green_slime_blood.png",
gravity = 9.8,
min_hp = 4,
max_hp = 6,
damage = 2,
sounds = green_sounds,
drops = {
type = "entity",
name = "slimes:greenmedium",
chance = 0, min = 1, max = 2},
-- damage by
water_damage = 0,
lava_damage = 10,
light_damage = 0,
fall_damage = 0,
-- spawn block
spawn = "default:junglegrass"
})
slimes:register_slime ("slimes:greenmedium", {
name = "slimes:greenmedium",
type = "monster",
class ="green",
passive = false,
size = 1,
min_hp = 3,
max_hp = 4,
damage = 1,
sounds = green_sounds,
textures = green_textures,
blood = "green_slime_blood.png",
gravity = 9.8,
drop = "",
drops = {
type = "entity",
name = "slimes:greensmall",
chance = 0, min = 2, max = 4},
-- damage by
water_damage = 0,
lava_damage = 10,
light_damage = 0,
fall_damage = 0,
spawn = "default:junglegrass"
})
slimes:register_slime ("slimes:greensmall", {
name = "slimes:greensmall",
type = "monster",
class ="green",
passive = false,
size = 0.5,
min_hp = 1,
max_hp = 2,
damage = 1,
sounds = green_sounds,
textures = green_textures,
blood = "green_slime_blood.png",
gravity = 9.8,
drop = "mesecons_materials:glue 1",
drops = {
type = "item",
name = "mesecons_materials:glue 1",
chance = 4, min = 1, max = 2},
-- damage by
water_damage = 0,
lava_damage = 10,
light_damage = 0,
fall_damage = 0,
spawn = "default:junglegrass"
})
slimes:register_spawn("slimes:greenbig", {"default:junglegrass"},{"air","default:junglegrass"}, 20, 4, 5000, 8, 32000)
slimes:register_spawn("slimes:greenmedium", {"default:junglegrass"},{"air","default:junglegrass"}, 20, 4, 10000, 8, 32000)
slimes:register_spawn("slimes:greensmall", {"default:junglegrass"},{"air","default:junglegrass"}, 20, 4, 15000, 8, 32000)
slimes:register_spawn("slimes:greenmedium", {"default:mossycobble"},{"air"}, 20, 4, 10000, 8, 32000)
slimes:register_spawn("slimes:greensmall", {"default:mossycobble"},{"air"}, 20, 4, 10000, 8, 32000)

11
init.lua Normal file
View File

@ -0,0 +1,11 @@
-- API
dofile(minetest.get_modpath("slimes").."/api.lua")
-- SLIMES
dofile(minetest.get_modpath("slimes").."/greenslimes.lua")
dofile(minetest.get_modpath("slimes").."/lavaslimes.lua")
--dofile(minetest.get_modpath("slimes").."/waterslimes.lua")
if minetest.setting_get("log_mods") then minetest.log("action", "Slimes loaded") end
damage_enabled = minetest.setting_getbool("enable_damage")

90
lavaslimes.lua Normal file
View File

@ -0,0 +1,90 @@
-- sounds
local lava_sounds = {
damage = { file = "lava_slime_damage", gain = 0.25},
death = { file = "lava_slime_death", gain = 0.25},
jump = { file = "lava_slime_jump", gain = 0.25},
--land = { file = "default_cool_lava.3", gain = 5},
land = { file = "lava_slime_land", gain = 0.25},
attack = { file = "lava_slime_attack", gain = 0.25},
random = {}
}
-- textures : top, bottom, front, back, left, right
local lava_textures = {"lava_slime_top.png", "lava_slime_bottom.png", "lava_slime_front.png", "lava_slime_sides.png", "lava_slime_sides.png", "lava_slime_sides.png"}
slimes:register_slime ("slimes:lavabig", {
type = "monster",
class ="lava",
name = "slimes:lavabig",
passive = false,
size = 2,
max_hp = 6,
damage = 3,
sounds = lava_sounds,
textures = lava_textures,
blood = "lava_slime_blood.png",
footprint = "fire:basic_flame",
gravity = 9.8,
drops = {
type = "entity",
name = "slimes:lavamedium",
chance = 0, min = 1, max = 2},
-- damage by
water_damage = 10,
lava_damage = 0,
light_damage = 0,
fall_damage = 0,
spawn = "default:lava_source"
})
slimes:register_slime ("slimes:lavamedium", {
type = "monster",
class ="lava",
name = "slimes:lavamedium",
passive = false,
size = 1,
max_hp = 4,
damage = 2,
sounds = lava_sounds,
textures = lava_textures,
blood = "lava_slime_blood.png",
footprint = "fire:basic_flame",
gravity = 9.8,
drops = {
type = "entity",
name = "slimes:lavasmall",
chance = 0, min = 1, max = 4},
-- damage by
water_damage = 10,
lava_damage = 0,
light_damage = 0,
fall_damage = 0,
spawn = "default:lava_source"
})
slimes:register_slime ("slimes:lavasmall", {
type = "monster",
class ="lava",
name = "slimes:lavasmall",
passive = false,
size = 0.5,
max_hp = 2,
damage = 1,
sounds = lava_sounds,
textures = lava_textures,
blood = "lava_slime_blood.png",
footprint = "fire:basic_flame",
gravity = 9.8,
drops = {
type = "item",
name = "tnt:gunpowder",
chance = 4, min = 1, max = 2},
-- damage by
water_damage = 10,
lava_damage = 0,
light_damage = 0,
fall_damage = 0,
spawn = "default:lava_source"
})
slimes:register_spawn("slimes:lavabig", {"default:lava_source"},{"default:lava_source","default:lava_flowing"}, 20, 4, 5000, 8, -64)
slimes:register_spawn("slimes:lavamedium", {"default:lava_source"},{"default:lava_source","default:lava_flowing"}, 20, 4, 10000, 8, -64)
slimes:register_spawn("slimes:lavasmall", {"default:lava_source"},{"default:lava_source","default:lava_flowing"}, 20, 4, 15000, 8, -64)

93
readme.txt Normal file
View File

@ -0,0 +1,93 @@
"Slimes Redone" - Mod for Minetest (http://www.minetest.net/)
Introduction
==========================================================================================================================
This mod adds two type of mobs in the world of Minetest: green slimes and lava slimes. They are hostile and will attack the
players as soon as they see them. If they are defeated, the slimes maybe will reward the player with useful resources.
Green slimes live in the tall grass of the jungles and in the ancient ruins of lost temples. And lava slimes live deep
underground near the lava pools.
I've made this mod inspired by this other: https://forum.minetest.net/viewtopic.php?f=11&t=2979&hilit=slimes which adds friendly
slimes. Thank you Jeija!
Details
==========================================================================================================================
- Adds two new hostile mobs: green slimes and lava slimes.
- They attack players and hurt them on touch. (i'm not sure if the amount of damage is enough or too much...:/)
- The biger ones split in a random amout of smaller versions when defeated: big > medium > small.
- They can get different enviromental damage: water, lava, sunlight and falling.
- They use custom textures and sounds. (more work needs to be done here ;P)
- Cartoonish animation (they deform a bit when landing and stretch out when jumping).
- Effects (blood, smoke, bubbles, footprints,..).
- API to add new slimes.
Green slimes:
> spawn in jungle grass or in temples mossy cobble (default:mossycobble).
> on die, they drop a randomish amount of glue (from mesecon mod)
> Lava hurts them.
Lava slimes:
> spawn in lava pools deep under ground.
> on die, they drop a randomish amount of gunpowder (from default tnt mod).
> water hurts them.
> when they jump they leave behind a footprint of fire. ^^
Install
==========================================================================================================================
Unzip the archive an place it in minetest-base-directory/mods/minetest/
If you have a windows client or a linux run-in-place client.
If you have a linux system-wide instalation place it in ~/.minetest/mods/minetest/.
If you want to install this mod only in one world create the folder worldmods/ in your world directory.
For further information or help see: http://wiki.minetest.com/wiki/Installing_Mods
How to use the mod:
==========================================================================================================================
Just install it an everything should work.
Mod Information
==========================================================================================================================
Version: 0.1
Required Minetest Version: >=0.4.12
Dependencies: default, default:tnt, mesecon (https://forum.minetest.net/viewtopic.php?f=11&t=628&hilit=mesecon)
Soft Dependencies: (none)
Highly Recommended: (none)
Craft Recipies: (none)
Git Repo: https://github.com/TomasJLuis/mt-slimes-redone
Modders/Developers
=========================================================================================================================
If you are a modder, you should know that I've never used LUA before. this is my first mod for Mintetest, and I've used
this mod to learn how to mod on Minetest. So may be you will find a code full of mistakes and bad practices... ;P
If you spot someting that can/must be improved/changed/removed and want to help me to improve this mode and my knowledge,
please tell me here: https://forum.minetest.net/viewtopic.php?f=9&t=11743&p=175186#p175186
Thank you!
Version history
==========================================================================================================================
0.1 - Initial release
Copyright and Licensing
==========================================================================================================================
- Author: Tomas J. Luis
- Original sound for slime damage by RandomationPictures under licence CC0 1.0.
http://www.freesound.org/people/RandomationPictures/sounds/138481/
- Original sounds for slime jump, land and death by Dr. Minky under licence CC BY 3.0.
http://www.freesound.org/people/DrMinky/sounds/
- Source code and images by Tomas J. Luis under WTFPL.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

BIN
screenshots/image10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 KiB

BIN
screenshots/image11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
sounds/green_slime_jump.ogg Normal file

Binary file not shown.

BIN
sounds/green_slime_land.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
sounds/lava_slime_death.ogg Normal file

Binary file not shown.

BIN
sounds/lava_slime_jump.ogg Normal file

Binary file not shown.

BIN
sounds/lava_slime_land.ogg Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
textures/lava_slime_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB