I'm super stoked about this one as it took a lot of scripting to get it work, but the effect is cool.
Push Monster
An air magic spell.. currently level 0 with a mana cost of 20 and two runes. Feel free to tweak it how you want.
The basic idea is that the monster directly in front of you is teleported one space away from the party in the same direction. This gives you enough time to either close a door, or sneak forward and potentially get out of a dead end. Because of the complex nature of the spell I have built it up using functions, so there is a minimal amount to put in spells.lua, a script_entity that needs placing in the editor and a custom monster to add to monsters.lua.
spells.lua
Code: Select all
-- Monster Pushback Spell
defineSpell{
name = "pushback",
uiName = "Push Monster",
skill = "air_magic",
level = 0,
runes = "CF",
manaCost = 20,
onCast = function(caster, x, y, direction, skill)
return pushback_spell_script.pushbackSpell(caster,x,y,direction,skill)
end,
}
monsters.lua
Code: Select all
cloneObject{
name = "teleport_probe",
baseObject = "snail",
}
script entity called
pushback_spell_script
Code: Select all
function isInTable(table, element)
for _,value in pairs(table) do
if value == element then
return true
end
end
return false
end
function pushDestroy()
push_teleport:destroy()
push_timer:destroy()
end
function monsterThere(level,eggs,why)
local allMonsters = {"crab", "crowern", "goromorg", "green_slime", "herder", "herder_big", "herder_small", "herder_swarm", "ice_lizard", "ogre", "scavenger", "scavenger_swarm", "shrakk_torr", "skeleton_archer", "skeleton_archer_patrol", "skeleton_warrior", "snail", "spider", "uggardian", "warden", "wyvern"}
for i in entitiesAt(level,eggs,why) do
if isInTable(allMonsters,i.name)
then
return true
end
end
return false
end
function isValidTarget(L,X,Y)
spawn("spawner", L, X, Y, 0, "probe"):setSpawnedEntity("teleport_probe"):activate()
for j in entitiesAt(L,X,Y) do
if j.name == "teleport_probe"
then
probe:destroy()
j:destroy()
return true
end
end
probe:destroy()
return false
end
function pushbackSpell(caster,x,y,dir,skill)
local dx,dy = getForward(dir)
if monsterThere(party.level,x+dx,y+dy)
then
-- hudPrint("Monster!")
if isValidTarget(party.level,x+2*dx,y+2*dy)
then
hudPrint("PUSH!!!!")
-- spawn("fx", party.level, x+dx, y+dy, dir, "push_smoke")
-- :setParticleSystem("push_spell")
-- :translate(0, 0.5, 0)
playSoundAt("fireball_launch",party.level,x+dx,y+dy)
spawn("teleporter", party.level, x+dx,y+dy,dir, "push_teleport")
:setTeleportTarget(x+2*dx,y+2*dy, dir)
:setTriggeredByParty(false)
:setTriggeredByMonster(true)
:setTriggeredByItem(false)
:setChangeFacing(true)
:setInvisible(true)
:setSilent(true)
:setHideLight(true)
:setScreenFlash(false)
spawn("timer",party.level,x,y,dir,"push_timer")
:setTimerInterval(0.1)
:addConnector("activate", "pushback_spell_script", "pushDestroy")
:activate()
else
hudPrint("The spell fails because there is something in the way.")
end
else
hudPrint("The spell fails because there is no monster to push")
end
end
credits:
To test for a valid destination, I used a bit of Edsploration's code from this thread:
viewtopic.php?f=14&t=3631
Optional Particle Effect
To use the optional particle effect you will need to uncomment the 3 lines relating to spawn FX in the script above and add the following to a
particles.lua file
Code: Select all
defineParticleSystem{
name = "push_spell",
emitters = {
{
spawnBurst = true,
maxParticles = 40,
sprayAngle = {0,100},
velocity = {0.8,2},
objectSpace = false,
texture = "assets/textures/particles/smoke_01.tga",
lifetime = {0.3,1},
color0 = {0.8, 0.9, 1.8},
opacity = 0.3,
fadeIn = 0.1,
fadeOut = 0.3,
size = {0.4, 0.7},
gravity = {0,0,0},
airResistance = 2,
rotationSpeed = 2,
blendMode = "Translucent",
},
-- glow
{
spawnBurst = true,
emissionRate = 1,
emissionTime = 0,
maxParticles = 1,
boxMin = {0,0,-0.1},
boxMax = {0,0,-0.1},
sprayAngle = {0,30},
velocity = {0,0},
texture = "assets/textures/particles/glow.tga",
lifetime = {0.5, 0.5},
colorAnimation = false,
color0 = {1.0, 1.0, 1.8},
opacity = 0.5,
fadeIn = 0.01,
fadeOut = 0.5,
size = {1, 1},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 2,
blendMode = "Additive",
}
}
}
Make sure that you include an IMPORT for your particles.lua file in the
init.lua file