[SCRIPT] Goromorg Shield (v1.1 update)
Posted: Thu Nov 29, 2012 8:58 pm
Hi everyone!
I've managed to recreate the goromorg shield functionality, it is updated now in the first post with visual effects and sound!)
Version 1.1 Update with moving shield!
- The shield effect now follows the monster if the monster is moving while hit.
- Sounds plays correctly at monster location
- Now works with monsters with no immunites (you just don't get the "0" text, just the shield visual)
- Script includes readme to help setup
- Optimized code
Here's the updated damageTracker script entity:
Usage:
VAlign, Size and moveSpeed have been tailored for a Goromorg, but can be adjusted for something else.
Setup:
add the following hooks to your monsters:
add this to materials.lua or anywhere else you store your particles:
And here's the texture file (properly trimmed + added alpha) that should go in mod_assets\textures\particles\:
https://docs.google.com/open?id=0B-rVma ... Vc2MTVpYTA
I've managed to recreate the goromorg shield functionality, it is updated now in the first post with visual effects and sound!)
Version 1.1 Update with moving shield!
- The shield effect now follows the monster if the monster is moving while hit.
- Sounds plays correctly at monster location
- Now works with monsters with no immunites (you just don't get the "0" text, just the shield visual)
- Script includes readme to help setup
- Optimized code
Here's the updated damageTracker script entity:
SpoilerShow
Code: Select all
--[[
Diarmuid's Goromorg Shield script, Version 1.1
Changelog:
1.1 Shield visual effect now moves along if monster moves
Shield sound effect is now played at monster's location
Simplified monster properties table
1.0 Initial release
Readme:
Add the following hooks to your monster(s):
onDamage = function(self,damage,type)
return damageTracker.shield(self,damage)
end,
onMove = function(self, direction)
return damageTracker.createMoveTimer(self, direction)
end,
onDie = function(self)
return damageTracker.clear(self)
end,
Then define the monster(s) in monstersTable below using the following properties:
shield: sets how much damage the shield can take before breaking
immunity: "fire", "frost", "poison", "shock" or "none"
(If elemental, you will get a "0" over the monster, if "none", just the shield visual)
shieldVAlign: adjusts the shield effect vertical alignment. Positive values go upwards.
shieldSize: adjusts the size of the shield effect. Values below 1 = smaller, above 1 = larger.
moveSpeed: adjusts the speed at which the shield moves with monster. Values below 1 = slower, above 1 = faster.
]]
damageTable = {}
timersTable = {}
monstersTable = {
white_goromorg = {
shield = 300,
immunity = "cold",
shieldVAlign = 0,
shieldSize = 1,
moveSpeed = 1,
},
}
function shield(monster, damage)
if damage > 0 then
local shieldActive = false
if damageTable[monster.id] == nil then
damageTable[monster.id] = damage
shieldActive = true
elseif damageTable[monster.id] < monstersTable[monster.name].shield then
damageTable[monster.id] = damageTable[monster.id] + damage
shieldActive = true
end
if shieldActive == true then
if monstersTable[monster.name].immunity ~= 'none' then
damageTile(monster.level, monster.x, monster.y, monster.facing, 0, monstersTable[monster.name].immunity,0)
end
local fxId = monster.id..".shield"
if findEntity(fxId) ~= nil then
findEntity(fxId):destroy()
end
spawn("fx", monster.level, monster.x, monster.y, monster.facing,fxId)
findEntity(fxId):setParticleSystem("shield_glow")
local dx,dy = getForward(party.facing)
local shieldSize = monstersTable[monster.name].shieldSize
local shieldVAlign = monstersTable[monster.name].shieldVAlign
findEntity(fxId):translate(-dx*0.6*shieldSize,shieldVAlign,dy*0.6*shieldSize)
local timerId = monster.id..'.moveTimer'
if findEntity(timerId) ~= nil then
local mx, my = getForward(timersTable[timerId].direction)
local moveSpeed = monstersTable[monster.name].moveSpeed
local x, y = unpack(timersTable[timerId].position)
findEntity(fxId):translate(mx*0.2*timersTable[timerId].tick*moveSpeed,0,-my*0.2*timersTable[timerId].tick*moveSpeed)
if x ~= monster.x or y ~= monster.y then
print("Translated")
findEntity(fxId):translate(-mx*3,0,my*3)
end
end
if damageTable[monster.id] < monstersTable[monster.name].shield then
playSoundAt("goromorg_shield_hit", monster.level, monster.x, monster.y)
else
playSoundAt("goromorg_shield_break", monster.level, monster.x, monster.y)
end
return false
end
return damage
end
end
function clear(monster)
damageTable[monster.id] = 0
local fxId = monster.id..".shield"
if findEntity(fxId) ~= nil then
findEntity(fxId):destroy()
end
end
function createMoveTimer(monster, direction)
local level, x, y = monster.level, monster.x, monster.y
local timerId = monster.id..'.moveTimer'
if findEntity(timerId) ~= nil then
findEntity(timerId):destroy()
end
local moveTimer = spawn('timer', level, x, y, 0, timerId)
moveTimer:addConnector('activate', 'damageTracker', 'moveTimer')
moveTimer:setTimerInterval(0.05)
moveTimer:activate()
timersTable[timerId] = {}
timersTable[timerId].id = monster.id
timersTable[timerId].direction = direction
timersTable[timerId].position = {x, y}
end
function moveTimer(self)
timerId = self.id
if timersTable[timerId].tick == nil then
timersTable[timerId].tick = 0
end
timersTable[timerId].tick = timersTable[timerId].tick + 1
fxId = timersTable[timerId].id..'.shield'
if findEntity(fxId) ~= nil then
local dx, dy = getForward(timersTable[timerId].direction)
local monster = findEntity(timersTable[timerId].id)
local moveSpeed = monstersTable[monster.name].moveSpeed
findEntity(fxId):translate(dx*0.2*moveSpeed,0,-dy*0.2*moveSpeed)
end
if timersTable[timerId].tick == 15 then
timersTable[timerId].tick = 0
self:destroy()
end
end
- shieldTable sets how much damage the shield can take before breaking
damageType sets the type of elemental damage the monster is immune to (monster must have an immunity)
shieldVAlign adjusts the shield effect vertical alignment. Positive values go upwards
shieldSize adjusts the size of the shield effect. Values below 1 = smaller, above 1 = larger.
VAlign, Size and moveSpeed have been tailored for a Goromorg, but can be adjusted for something else.
Setup:
add the following hooks to your monsters:
SpoilerShow
Code: Select all
onDamage = function(self,damage,type)
return damageTracker.shield(self,damage)
end,
onMove = function(self, direction)
return damageTracker.createMoveTimer(self, direction)
end,
onDie = function(self)
return damageTracker.clear(self)
end,
SpoilerShow
Code: Select all
defineParticleSystem{
name = "shield_glow",
emitters = {
-- outer glow
{
spawnBurst = true,
emissionRate = 1,
emissionTime = 0,
maxParticles = 1,
boxMin = {0,1.1,0},
boxMax = {0,1.1,0},
sprayAngle = {0,0},
velocity = {0,0},
texture = "mod_assets/textures/particles/goromorg_shield_particle.tga",
lifetime = {0.7, 0.7},
colorAnimation = false,
color0 = {2, 2, 2},
opacity = 0.5,
fadeIn = 0.1,
fadeOut = 0.1,
size = {2.6, 2.6},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 0,
blendMode = "Additive",
depthBias = -0.0005,
objectSpace = true,
}
}
}
https://docs.google.com/open?id=0B-rVma ... Vc2MTVpYTA