- Joined
- May 4, 2007
- Messages
- 2,260
Hi guys. I have a problem about my penguin ability =(
Well, thing is, if I stop casting the ability everything goes fine ... however, if i kill my stupid penguin before the time, everything goes as planned... except for the part that the explosion effect is created in the wrong place !! I don't know why this happens ... please help !
know why this happens ?
Well, thing is, if I stop casting the ability everything goes fine ... however, if i kill my stupid penguin before the time, everything goes as planned... except for the part that the explosion effect is created in the wrong place !! I don't know why this happens ... please help !
JASS:
scope StupidPenguin initializer Init
//don't change
private struct Mystruct
unit caster
integer level
unit penguin
real currentScale
timer t
real grow
integer damage
trigger end
triggeraction endAction
triggercondition endCondition
static method create takes nothing returns Mystruct
local Mystruct this = Mystruct.allocate()
set .caster = GetTriggerUnit()
set .currentScale = 1
set .t = CreateTimer()
set .end = CreateTrigger()
return this
endmethod
endstruct
//!=========================================================================!\\
//!============================SETUP START==================================!\\
//!=========================================================================!\\
globals
private constant integer AID = 'A000' //ability ID
private constant integer UNITID = 'npng' //Created unit's Id
private constant string DEATH_EFFECT = "Objects\\Spawnmodels\\NightElf\\NEDeathMedium\\NEDeath.mdl" //effect shown when penguin dies
private constant string BLOOD_EFFECT = "Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl" //effect shown when units damge damage
private constant integer RED = 0 //the red RGB color for the text tag
private constant integer GREEN = 0 //the green RGB color for the text tag
private constant integer BLUE = 255 //the blue RGB color for the text tag
private constant boolean TEXT = true //if true, shows text saying damage abve units, if false, it doesn't
endglobals
private constant function GrowTime takes integer level returns integer time
return 1 + (level * 0) //time intervail between each time the unit grows (is a cicle)
endfunction
private constant function Growth takes integer level returns real grow
return 0.2 * level //How much the unit will grow. It grows 20% * level in this case
endfunction
private constant function Radius takes integer level returns integer radius
return 200 + (50 * (level - 1)) //the area of damage
endfunction
private function Damage takes integer level returns integer damage
return 5 * level //Damage increase per cicle
endfunction
private function Targets takes nothing returns boolean
//do not change this local
local Mystruct data = GetTriggerStructA(GetTriggeringTrigger())
//this tells you the units the explosion will affect, you can change this
//data.caster is the caster of the spell. Everytime you want to refer to the caster
//of the spell you must use data.caster, but ONLY on this function, in the SETUP
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(data.caster)) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false) and (GetWidgetLife(GetFilterUnit()) > 0.405)
endfunction
//!=========================================================================!\\
//!============================SETUP END====================================!\\
//!=========================================================================!\\
private function End_Conds takes nothing returns boolean
return (GetSpellAbilityId() == AID)
endfunction
//==========================================================================
private function End_Acts takes nothing returns nothing
//catches the trigger and runs this function
local Mystruct data = GetTriggerStructA(GetTriggeringTrigger())
local group g = CreateGroup()
local unit f
local boolexpr b = Condition(function Targets)
local effect deathPenguin = AddSpecialEffect(DEATH_EFFECT, GetUnitX(data.penguin), GetUnitY(data.penguin))
local effect blood
local texttag text
if(GetWidgetLife(data.penguin) > 0.405) then
call KillUnit(data.penguin)
else
call IssueImmediateOrder(data.caster, "stop" )
endif
call GroupEnumUnitsInRange(g, GetUnitX(data.penguin), GetUnitY(data.penguin), Radius(data.level), b)
loop
set f = FirstOfGroup(g)
exitwhen (f == null)
call GroupRemoveUnit(g, f)
set blood = AddSpecialEffect(BLOOD_EFFECT, GetUnitX(f), GetUnitY(f))
call UnitDamageTarget(data.penguin, f, data.damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
//sets the text tag if the flag is true
if(TEXT) then
set text = CreateTextTag()
call SetTextTagText(text, I2S(data.damage), .023 )
call SetTextTagPosUnit( text, f, 0 )
call SetTextTagColor( text, RED, GREEN, BLUE, 255 )
call SetTextTagPermanent(text, false)
call SetTextTagVelocity( text, 0, .0277 )
call SetTextTagLifespan(text, 2.0)
endif
call DestroyEffect(blood)
endloop
call DestroyEffect(deathPenguin)
call DestroyGroup(g)
call DestroyBoolExpr(b)
set b = null
set g = null
set deathPenguin = null
set blood = null
set text = null
call TriggerRemoveCondition(data.end,data.endCondition)
call TriggerRemoveAction(data.end,data.endAction)
call DestroyTrigger(data.end)
call ClearTriggerStructA(data.end)
//stops the repeator timer and ends the spell once and for all
call PauseTimer(data.t)
call DestroyTimer(data.t)
call ClearTimerStructA(data.t)
call data.destroy()
endfunction
//==========================================================================
private function Size takes nothing returns nothing
//catches the expired timer and runs this function
local Mystruct data = GetTimerStructA(GetExpiredTimer())
if(GetWidgetLife(data.penguin) > 0.405) then
call SetUnitScale(data.penguin, data.currentScale + data.grow, data.currentScale + data.grow, data.currentScale + data.grow)
set data.currentScale = data.currentScale + data.grow
set data.damage = data.damage + Damage(data.level)
else
call IssueImmediateOrder(data.caster, "stop" )
endif
endfunction
//==========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == AID
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local Mystruct data = Mystruct.create()
local location loc = GetSpellTargetLoc()
set data.grow = Growth(GetUnitAbilityLevel(data.caster, AID))
set data.penguin = CreateUnit(GetOwningPlayer(data.caster), UNITID, GetLocationX(loc), GetLocationY(loc), 0)
set data.level = GetUnitAbilityLevel(data.caster, AID)
set data.damage = Damage(data.level)
call SetUnitExploded(data.penguin, true)
call SetTimerStructA(data.t, data)
call TimerStart(data.t, GrowTime(GetUnitAbilityLevel(data.caster, AID)), true, function Size)
call RemoveLocation(loc)
set loc = null
//creates the trigger that will end the spell when the hero stops channeling
call SetTriggerStructA(data.end, data)
call TriggerRegisterAnyUnitEventBJ( data.end, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
set data.endCondition = TriggerAddCondition( data.end, Condition( function End_Conds ) )
set data.endAction = TriggerAddAction( data.end, function End_Acts )
endfunction
//===========================================================================
private function Init takes nothing returns nothing
set gg_trg_Stupid_Penguin = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Stupid_Penguin, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
call TriggerAddCondition( gg_trg_Stupid_Penguin, Condition( function Conditions ) )
call TriggerAddAction( gg_trg_Stupid_Penguin, function Actions )
endfunction
endscope
know why this happens ?
Attachments
Last edited: