Decided to make something a little bit wacky, but I think the code might be useful as an example to some:
Introducing the turbo snail, a snail that moves so fast he leaves a trail of flames everywhere he goes. He also comes with a relatively simple custom brain that has him wander until the party is adjacent to him, and then he'll turn and bite them.
Code: Select all
defineObject{
name = "snail_turbo",
baseObject = "base_monster",
components = {
{
class = "Model",
model = "assets/models/monsters/snail.fbx",
storeSourceData = true,
},
{
class = "Animation",
name = "animation",
currentLevelOnly = true,
animations = {
idle = "assets/animations/monsters/snail/snail_idle.fbx",
moveForward = "assets/animations/monsters/snail/snail_walk.fbx",
turnLeft = "assets/animations/monsters/snail/snail_turn_left.fbx",
turnRight = "assets/animations/monsters/snail/snail_turn_right.fbx",
attack = "assets/animations/monsters/snail/snail_attack.fbx",
getHitFrontLeft = "assets/animations/monsters/snail/snail_get_hit_front_left.fbx",
getHitFrontRight = "assets/animations/monsters/snail/snail_get_hit_front_right.fbx",
getHitBack = "assets/animations/monsters/snail/snail_get_hit_back.fbx",
getHitLeft = "assets/animations/monsters/snail/snail_get_hit_left.fbx",
getHitRight = "assets/animations/monsters/snail/snail_get_hit_right.fbx",
fall = "assets/animations/monsters/snail/snail_get_hit_front_left.fbx",
},
},
{
class = "Monster",
meshName = "snail_mesh",
level=1,
health = 240,
evasion = -10,
exp = 500,
lootDrop = { 75, "snail_slice", 10, "snail_slice" },
traits = { "animal" },
hitEffect = "hit_goo",
capsuleHeight = 0.2,
capsuleRadius = 0.7,
hitSound = "snail_hit",
dieSound = "snail_die",
resistances = { fire="immune"},
onPerformAction = function(self, name)
if name == "move" then
local fire = spawn("wall_fire", self.go.level, self.go.x, self.go.y, 0, self.go.elevation)
fire.particle:disable()
fire.particle2:disable()
fire.impact:disable()
fire.light:disable()
end
end,
},
{
class = "Brain",
name = "brain",
sight = 0.5,
allAroundSight = true,
onThink = function(self)
--print(math.abs(self.go.x - party.x))
--print(math.abs(self.go.y - party.y))
if math.abs(self.go.x - party.x) + math.abs(self.go.y - party.y) == 1 then
self:turnTowardsParty()
self:meleeAttack()
else
self:wander()
self:moveForward()
end
end
},
{
class = "MonsterMove",
name = "move",
sound = "snail_walk",
resetBasicAttack = false,
turnDir = 0,
cooldown = 0,
animationSpeed = 8,
},
{
class = "MonsterTurn",
name = "turn",
sound = "snail_walk",
cooldown = 0,
animationSpeed = 8,
},
{
class = "MonsterAttack",
name = "basicAttack",
sound = "snail_attack",
cooldown = 0,
attackPower = 14,
animationSpeed = 8,
animation = "attack",
},
}
}
Note: If you don't already have them, this snail uses the sounds, materials, and animation events from the original snail.