- Joined
- May 4, 2007
- Messages
- 2,260
Hi guys, well, some of you may already know my spell Apocalypse that is in the spells section. I am sure it will be approved soon or later, as it has no bugs and it very cool.
But purgeandfire gave me a suggestion.
But i don't know how to do a spell like he says ... can some1 please teach me how to use global privates in order to make a spell easy to import, and yet MUI, bug free and leak free ?
Here is the open source code:
Please i need a teacher!
But purgeandfire gave me a suggestion.
Anywho, the spell is fine and works. It gets the job done. The only thing is, is that you need to add global constants for your spell, otherwise your spell is hideously unconfigurable.
Other than that, I guess it is fine!
But i don't know how to do a spell like he says ... can some1 please teach me how to use global privates in order to make a spell easy to import, and yet MUI, bug free and leak free ?
Here is the open source code:
JASS:
//===========================================================================
//A spell that makes meteors fall randomly in the map, damaging enemy units
//and summoning powerfull infernals
//
//@author Flame_Phoenix
//@version 1.4
//===========================================================================
struct Mystruct
unit caster = GetTriggerUnit()
timer repeator = CreateTimer()
timer expirer = CreateTimer()
trigger end = CreateTrigger()
triggeraction endAction
triggercondition endCondition
endstruct
//==========================================================================
function endConds takes nothing returns boolean
local Mystruct data = GetTriggerStructB(GetTriggeringTrigger())
if GetTriggerEventId() == EVENT_GAME_TIMER_EXPIRED then
return true
else
return GetTriggerUnit() == data.caster
endif
endfunction
//==========================================================================
function endActs takes nothing returns nothing
//catches the trigger and runs this function
local Mystruct data = GetTriggerStructB(GetTriggeringTrigger())
//removes the created trigger in the Code_acts function
call TriggerRemoveCondition(data.end,data.endCondition)
call TriggerRemoveAction(data.end,data.endAction)
call DestroyTrigger(data.end)
call ClearTriggerStructB(data.end)
//stops the repeator timer and ends the spell once and for all
call PauseTimer(data.repeator)
call DestroyTimer(data.repeator)
call ClearTimerStructA(data.repeator)
call ClearTimerStructB(data.expirer)
endfunction
//==========================================================================
function Apoca takes nothing returns nothing
//catches the expired timer and runs this function
local Mystruct data = GetTimerStructA(GetExpiredTimer())
//local variables
local integer infernal = GetRandomInt(0, 100)
local unit array dummy[]
//This uses polar projection. Formula: Center + r * trigfunction(angle teta);
//where Center is the center coordinate X or Y
//r is the distance (in the case rabdom between 300 and 600)
//trigfunction is Sin if using Y and Cos if using X
//angle teta is the angle formed between r and the axis (in this case random, can be all circle)
local real randomX = GetUnitX(data.caster) + GetRandomReal(300.00, 600.00) * Cos(GetRandomReal(0.0, 360.0) * bj_DEGTORAD)
local real randomY = GetUnitY(data.caster) + GetRandomReal(300.00, 600.00) * Sin(GetRandomReal(0.0, 360.0) * bj_DEGTORAD)
if (infernal <= 3 * GetUnitAbilityLevel(data.caster, 'A000') + 1) then
set dummy[0] = CreateUnit(GetOwningPlayer(data.caster), 'h000', GetUnitX(data.caster), GetUnitY(data.caster), 0)
call UnitAddAbility(dummy[0], 'A002')
call SetUnitAbilityLevel(dummy[0], 'A002', GetUnitAbilityLevel(data.caster, 'A000'))
call IssuePointOrder(dummy[0], "dreadlordinferno", randomX, randomY)
call UnitApplyTimedLife(dummy[0], 'BTLF', 3)
set dummy[1] = CreateUnit(GetOwningPlayer(data.caster), 'h000', GetUnitX(data.caster), GetUnitY(data.caster), 0)
call UnitAddAbility(dummy[1], 'A003')
call SetUnitAbilityLevel(dummy[1], 'A003', GetUnitAbilityLevel(data.caster, 'A000'))
call IssuePointOrder(dummy[1], "flamestrike", randomX, randomY)
call UnitApplyTimedLife(dummy[1], 'BTLF', 3)
else
set dummy[0] = CreateUnit(GetOwningPlayer(data.caster), 'h000', GetUnitX(data.caster), GetUnitY(data.caster), 0)
call UnitAddAbility(dummy[0], 'A001')
call SetUnitAbilityLevel(dummy[0], 'A001', GetUnitAbilityLevel(data.caster, 'A000'))
call IssuePointOrder(dummy[0], "flamestrike", randomX, randomY)
call UnitApplyTimedLife(dummy[0], 'BTLF', 3)
endif
set dummy[0] = null
set dummy[1] = null
endfunction
//==========================================================================
function Code_conds takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
//==========================================================================
function Code_acts takes nothing returns nothing
local Mystruct data = Mystruct.create()
//starts the effect of the spell, meteors start falling from sky
call SetTimerStructA(data.repeator, data)
call TimerStart(data.repeator, 6 / GetUnitAbilityLevel(data.caster, 'A000'), true, function Apoca)
//creates the timer that ends the spell when expired
call SetTimerStructB(data.expirer, data)
call TimerStart(data.expirer, 5 * GetUnitAbilityLevel(data.caster, 'A000') + 15, false, null)
//creates the trigger that will end the spell when the timer expires or the hero dies
call SetTriggerStructB(data.end, data)
call TriggerRegisterTimerExpireEvent( data.end, data.expirer )
call TriggerRegisterAnyUnitEventBJ(data.end, EVENT_PLAYER_UNIT_DEATH )
set data.endCondition = TriggerAddCondition( data.end, Condition( function endConds ) )
set data.endAction = TriggerAddAction( data.end, function endActs )
endfunction
//===========================================================================
function InitTrig_Apocalypse takes nothing returns nothing
set gg_trg_Apocalypse = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Apocalypse, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Apocalypse, Condition( function Code_conds ) )
call TriggerAddAction( gg_trg_Apocalypse, function Code_acts )
endfunction
Please i need a teacher!