- Joined
- Jan 29, 2007
- Messages
- 98
Hi !
Sorry about the title XD Couldn't come up wit ha decent name for it
Anyways, I've made this spell, which in the first place was a request in a thread on TheHelper.net, but I thought that it got quite complicated (According to me XD) so I am thinking about submitting it :S
What do you think ?
(After you've looked through the code below, of course )
Anyways, this is a spell which links 2 units together with a lightning effect, and whenever a unit crosses that line, it damages/heals ( Depending on wether the unit is ally or enemy ) that unit by an amount, and also heals the caster of the spell for that amount too.
Please, tell me if you would like to see more configurables, and give me suggestions and I'll try to implement them
I also have these two constants, FREEZE_OR_TERMINATE and MAX_DISTANCE, and with these I'd like to somehow make a max distance there can be between the two units with the link...
Anyone have any idea on how to do this ? :S
Ok, so my questions are:
Please, any comments and critzism is good !
Also, links to the requirements used are here:
And the link to the actual thread with the request is here:
http://www.thehelper.net/forums/showthread.php?t=142361
Sorry about the title XD Couldn't come up wit ha decent name for it
Anyways, I've made this spell, which in the first place was a request in a thread on TheHelper.net, but I thought that it got quite complicated (According to me XD) so I am thinking about submitting it :S
What do you think ?
(After you've looked through the code below, of course )
Anyways, this is a spell which links 2 units together with a lightning effect, and whenever a unit crosses that line, it damages/heals ( Depending on wether the unit is ally or enemy ) that unit by an amount, and also heals the caster of the spell for that amount too.
Please, tell me if you would like to see more configurables, and give me suggestions and I'll try to implement them
I also have these two constants, FREEZE_OR_TERMINATE and MAX_DISTANCE, and with these I'd like to somehow make a max distance there can be between the two units with the link...
Anyone have any idea on how to do this ? :S
Ok, so my questions are:
- Do you think there's any use of submitting this spell ?
- Are there any suggestions or comments on the code ?
- Is there any way I could make the code even more effective ?
- How would I go about adding a max distance to this spell ? :S
JASS:
scope SpiritLink // requires T32, LineSegment, TimerUtils, AIDS
globals
private constant integer SPELL_ID = 'SPIR' // This is the rawcode of the spell which is to be used !
private constant real RADIUS = 1.0 // How close they have to be to the lightning effect to be considered crossing it...
private constant real IMMUNITY_TIME = 2.0 // The time that, after a unit has been hit by this spell, it can be hit again...
private constant real MAX_DISTANCE = 0.0 // The maximum distance the linked units can be from eachother. Set to 0.0 for infinite range ;)
private constant boolean FREEZE_OR_TERMINATE = false // When the maximum distance is reached, what to do ? Set to false to terminate the spell,
// or to true to make the units unable to move further away ;)
private constant boolean ALLIES_ONLY = false // Wether this spell only can target allies... ( This can of course be changed in the Object Editor too ;) )
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL // The attack-type of the damage dealt !
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_UNKNOWN // The damage-type of the damage dealt !
private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS // The weapon-type of the damage dealt !
private constant string LIGHTNING_TYPE = "SPLK" // The rawcode of the lightning to be used !
private constant string EFFECT_DMG = "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" // The special-effect when units get damaged !
private constant string ATTACH_POINT_DMG = "origin" // The attachment point of the special-effect when units get damaged !
private constant string EFFECT_HEAL = "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" // The special-effect when units get healed !
private constant string ATTACH_POINT_HEAL = "origin" // The attachment point of the special-effect when units get healed !
private constant string EFFECT_FINISH = "Abilities\\Spells\\Undead\\ReplenishHealth\\ReplenishHealthCaster.mdl" // The special-effect when the spell is done !
private constant string ATTACH_POINT_FINISH = "origin"
// ================================================================================================================================================================================== \\
// PLEASE, DON'T TOUCH THESE GLOBALS ! THANK YOU ;)
private location Z = Location( 0.0, 0.0 )
private group new = CreateGroup()
private integer temp = 0
// PLEASE, DON'T TOUCH THESE GLOBALS ! THANK YOU ;)
// ==================================================================================================================================================================================
endglobals
// How long the whole spell will last !
private constant function Duration takes integer spellvl returns real
return 20.0
endfunction
// The damage which will be dealt when the units cross the lightning !
private constant function Damage takes integer spellvl returns real
return spellvl * 50.0
endfunction
// The damage which will be healed when the units cross the lightning !
private constant function Heal takes integer spellvl returns real
return spellvl * 50.0
endfunction
// The new native "discovered" by Azlier !
// Don't change ! XD (Don't know why you ever would, but still :P)
native UnitAlive takes unit id returns boolean
// There is a filter inside the struct below which you also can change freely :D
// It's called "Filters" and is the first method you'll see ;)
private struct Link extends array
// =========================================================== \\
// Since we're using AIDS...
//! runtextmacro AIDS()
// =========================================================== \\
// The filter for which units to be damaged/healed !
private static method Filters takes nothing returns boolean
local thistype this = temp
return UnitAlive( GetFilterUnit() ) and IsUnit( GetFilterUnit(), this.cast ) != true and /*
*/IsUnit( GetFilterUnit(), this.targ ) != true and IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE ) != true
endmethod
//// END OF CONFIGURATION \\\\
//// END OF CONFIGURATION \\\\
//// END OF CONFIGURATION \\\\
private group check // The group we use to check which units are to be damaged/healed
private integer tick // So we know how many times the periods should run ! ;)
private integer lvl // The level of the spell being cast
private lightning light // The lightning of the spell
// Don't mind these :P:P
private player owner // Owner of the caster
private unit cast // Caster, duh ! :P
private unit targ // Target ;P
private timer t // A timer which controlls how long you are "immune"
// to the spell after being damaged/healed by it :D
private boolean immune // An easy boolean check to know if you currently are immune !
// =========================================================== \\
private method AIDS_onCreate takes nothing returns nothing
set this.check = CreateGroup()
set this.immune = false
endmethod
private static method Immunity takes nothing returns nothing
// =========================================================== \\
local timer t = GetExpiredTimer()
// Locals to prevent leakage, and such ;)
local thistype this = GetTimerData( t )
// =========================================================== \\
call ReleaseTimer( t )
// Here we make the unit un-immune again ! :D
set this.immune = false
// =========================================================== \\
// Just some anti-leakage again ;)
set t = null
set this.t = null
endmethod
private static method CheckGroups takes nothing returns nothing
// =========================================================== \\
local unit u = GetEnumUnit()
// The usual, locals ! :D
local thistype this = temp
// =========================================================== \\
// Here we check if the new units aren't in the old group, meaning
// that they have crossed the lightning, and should be damaged/healed
if IsUnitInGroup( u, new ) != true and thistype[ u ].immune != true then
if IsUnitEnemy( u, this.owner ) then
// =========================================================== \\
call UnitDamageTarget( this.cast, u, Damage( this.lvl ), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE )
// If they aren't in the group, and is an enemy
// damage them !
call DestroyEffect( AddSpecialEffectTarget( EFFECT_DMG, u, ATTACH_POINT_DMG ) )
// =========================================================== \\
else
// =========================================================== \\
call SetWidgetLife( u, GetWidgetLife( u ) + Heal( this.lvl ) )
// If they aren't in the group, and is an ally
// heal them !
call DestroyEffect( AddSpecialEffectTarget( EFFECT_HEAL, u, ATTACH_POINT_HEAL ) )
// =========================================================== \\
endif
// =========================================================== \\
// Heal the caster too ;)
call SetWidgetLife( this.cast, GetWidgetLife( this.cast ) + Heal( this.lvl ) )
// =========================================================== \\
set thistype[ u ].immune = true
set thistype[ u ].t = NewTimer()
// For the immunity part ! ;)
call SetTimerData( thistype[ u ].t, thistype[ u ] )
call TimerStart( thistype[ u ].t, IMMUNITY_TIME, false, function thistype.Immunity )
// =========================================================== \\
endif
// Small leak-cleaning here ! ;)
set u = null
endmethod
private static method ChangeGroups takes nothing returns nothing
local thistype this = temp
local unit u = GetEnumUnit()
call GroupRemoveUnit( new, u )
call GroupAddUnit( this.check, u )
set temp = this
set u = null
endmethod
private method periodic takes nothing returns nothing
// =========================================================== \\
local real x1 = GetUnitX( this.cast )
local real x2 = GetUnitX( this.targ )
local real y1 = GetUnitY( this.cast )
// Same as before... Locals for JASS usage/storage ! ;)
local real y2 = GetUnitY( this.targ )
local real z1
local real z2
// =========================================================== \\
set this.tick = this.tick - 1 // This will count how many times the period has run.
// And when it's 0, then it's time to stop the lighting !
if this.tick >= 0 then
// =========================================================== \\
call MoveLocation( Z, x1, y1 )
set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( cast )
// Here we take count for the height of both the terrain and
// when we move the lightning ;)
call MoveLocation( Z, x2, y2 )
set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( targ )
// Here we move the lighting to the new coordinates !
call MoveLightningEx( this.light, true, x1, y1, z1, x2, y2, z2 )
// =========================================================== \\
set temp = this
// First we use a globals to be able to use the struct members
// in the static method "CheckGroups" is...
// Then we group the units in a line from the caster to the target
// (Yet again), and then check which to damage and which to heal !
call GroupEnumUnitsInRangeOfSegment( new, x1, y1, x2, y2, RADIUS, Filter( function thistype.Filters ) )
call ForGroup( this.check, function thistype.CheckGroups )
call GroupClear( this.check )
set temp = this
call ForGroup( new, function thistype.ChangeGroups )
// =========================================================== \\
else
// =========================================================== \\
call DestroyEffect( AddSpecialEffectTarget( EFFECT_FINISH, this.cast, ATTACH_POINT_FINISH ) )
// Just some eye-candy so you know when the spell is done ;)
call DestroyEffect( AddSpecialEffectTarget( EFFECT_FINISH, this.targ, ATTACH_POINT_FINISH ) )
// =========================================================== \\
call DestroyLightning( this.light )
call this.stopPeriodic()
// Though, if this.tick has become 0, that means the spell is done
// and we need to clean some stuff up, like destroying the lightning
// and stopping the periodic stuff from running ;)
set this.cast = null
set this.targ = null
set this.owner = null
set this.light = null
// =========================================================== \\
endif
endmethod
implement T32xs
private static method StartPeriod takes nothing returns boolean
// =========================================================== \\
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
local player p = GetOwningPlayer( caster )
local thistype this = thistype[ caster ]
local real x1 = GetUnitX( caster )
// Just the locals we "need" when using JASS ! :D
local real x2 = GetUnitX( target )
local real y1 = GetUnitY( caster )
local real y2 = GetUnitY( target )
local real z1
local real z2
// =========================================================== \\
if ALLIES_ONLY and IsUnitAlly( target, p ) != true then
return false
endif
// =========================================================== \\
if GetSpellAbilityId() == SPELL_ID then
// =========================================================== \\
call MoveLocation( Z, x1, y1 )
set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( caster )
// Here we take count for the height of both the terrain and
// when we move the lightning ;)
call MoveLocation( Z, x2, y2 )
set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( target )
// =========================================================== \\
set this.cast = caster
set this.targ = target
set this.light = AddLightningEx( LIGHTNING_TYPE, false, x1, y1, z1, x2, y2, z2 )
// Here we set stuff necessary for future struct usage :D
set this.owner = p
set this.lvl = GetUnitAbilityLevel( caster, SPELL_ID )
set this.tick = R2I( Duration( GetUnitAbilityLevel( caster, SPELL_ID ) ) / T32_PERIOD )
set temp = this
// =========================================================== \\
call GroupEnumUnitsInRangeOfSegment( this.check, x1, y1, x2, y2, RADIUS, Filter( function thistype.Filters ) )
// Here we group all units in a line from the caster to the
// target, which will be used to damage the units later :D
// We also start the periodic check to check which units to damage ! ;)
call this.startPeriodic()
// =========================================================== \\
endif
// Just some leak-cleaning here ! :D
set caster = null
set target = null
set p = null
return false
endmethod
private static method AIDS_onInit takes nothing returns nothing
local trigger t = CreateTrigger() // Here we're creating the trigger ;)
local integer i = 0 // This will be used for looping through the players
loop
call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) // And here the looping goes.
// And also, registering the events to the previusly created trigger
set i = i + 1
exitwhen i >= 12
endloop
call TriggerAddCondition( t, Condition( function thistype.StartPeriod ) ) // And here we're adding the condition/action to the trigger
endmethod
endstruct
endscope
Please, any comments and critzism is good !
Also, links to the requirements used are here:
- AIDS and Timer32, by Jesus4Lyf (At TheHelper.net)
- TimerUtils, by Vexorian (At Wc3C.net)
- LineSegment, by Ammorth (At Wc3C.net)
And the link to the actual thread with the request is here:
http://www.thehelper.net/forums/showthread.php?t=142361
Last edited: