Cohadar
master of fugue
- Reaction score
- 209
Example spell for ABC trigger attachment and PUI unit attachment.
vJass, MUI, no leaks ... blah blah blah...
Basically a version of Vulture spider mines from starcraft.
Fell free to ask...
vJass, MUI, no leaks ... blah blah blah...
Basically a version of Vulture spider mines from starcraft.
JASS:
//===========================================================================
// This one creates scarab, attaches trigger to it and orders him to burow
//===========================================================================
scope ScarabMines
globals
constant integer UID_EXPLODING_SCARAB = 039;u001039;
constant integer UID_EXPLODING_SCARAB_BURROWED = 039;u002039;
constant integer AID_SCARAB_MINES = 039;A000039;
constant integer AID_SCARAB_BURROW = 039;A001039;
constant integer AID_SCARAB_EXPLOSION = 039;A002039;
constant integer OID_burrow = 852533
constant integer OID_unburrow = 852534
constant integer OID_selfdestruct = 852040
private constant real distance = -200 // 200 points BEHIND Crypt Lord
endglobals
//===========================================================================
private function ProximityAOE takes integer level returns real
return level*200.
endfunction
//===========================================================================
struct ScarabData
unit scarab
trigger proximity_trig
triggeraction action // used for cleaning up later
unit target = null
static ScarabData array PUI // <-------- Pay close attention
//===========================================================================
// When enemy unit comes close to burrowed scarab it is time for action
//===========================================================================
private static method ProximityAlert takes nothing returns boolean
local ScarabData data = GetTriggerStructA(GetTriggeringTrigger()) // ABC
if IsUnitEnemy(data.scarab, GetOwningPlayer(GetEnteringUnit())) then
return true
else
return false
endif
endmethod
//===========================================================================
private static method ProximityActions takes nothing returns nothing
local trigger proximity_trig = GetTriggeringTrigger()
local ScarabData data = GetTriggerStructA(proximity_trig) // ABC
// unburrow and get ready for action
set data.target = GetEnteringUnit()
call IssueImmediateOrderById(data.scarab, OID_unburrow)
// booooring
set proximity_trig = null
endmethod
//===========================================================================
static method create takes unit scarab, integer level returns ScarabData
local ScarabData data = ScarabData.allocate()
// lets connect stuff unit,trigger,Data
set ScarabData.PUI[GetUnitIndex(scarab)] = data // PUI unit->data
set data.proximity_trig = CreateTrigger()
set data.scarab = scarab
set data.action = TriggerAddAction(data.proximity_trig, function ScarabData.ProximityActions)
call SetTriggerStructA(data.proximity_trig, data) // ABC trigger->data
call TriggerAddCondition(data.proximity_trig, Condition( function ScarabData.ProximityAlert ) )
call DisableTrigger(data.proximity_trig) // it will be enabled by burrow
call TriggerRegisterUnitInRange(data.proximity_trig, scarab, ProximityAOE(level), null)
return data
endmethod
//===========================================================================
method onDestroy takes nothing returns nothing
// lets break connections
call DisableTrigger(this.proximity_trig)
set ScarabData.PUI[GetUnitIndex(this.scarab)] = 0 // PUI
call TriggerRemoveAction(this.proximity_trig, this.action)
call ClearTriggerStructA(this.proximity_trig) // ABC
call DestroyTrigger(this.proximity_trig)
endmethod
endstruct
//===========================================================================
// We "drop" scarab behind Cryot Lord, order him to burrow.
// Burrowing will trigger ScarabBurrow trigger.
// I separated this triggers because I wanted to be able to move scarabs.
//===========================================================================
private function Actions takes nothing returns nothing
local unit hero = GetTriggerUnit()
local real facing = GetUnitFacing(hero)
local ScarabData data
// calculations for drop position
local real x = GetUnitX(hero) + distance*Cos(facing*bj_DEGTORAD)
local real y = GetUnitY(hero) + distance*Sin(facing*bj_DEGTORAD)
local integer level = GetUnitAbilityLevel(GetTriggerUnit(), AID_SCARAB_MINES)
local unit scarab = CreateUnit(GetOwningPlayer(hero),UID_EXPLODING_SCARAB, x, y, facing)
call SetUnitAbilityLevel(scarab, AID_SCARAB_EXPLOSION, level)
call ScarabData.create(scarab, level) // <--- Hard Rock
call IssueImmediateOrderById(scarab, OID_burrow)
set hero = null
set scarab = null
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == AID_SCARAB_MINES
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
endscope
JASS:
//===========================================================================
// When scarab burrows it will turn on proximity trigger,
// When it unburrows it will turn it off.
// When unit passes near burrowed scarab it will get in trouble <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" />
//===========================================================================
scope ScarabBurrow
//===========================================================================
// When Scarab burrow we register unit area trigger for him,
// To that trigger we attach needed data
//===========================================================================
private function Actions takes nothing returns nothing
local unit scarab = GetTriggerUnit()
local ScarabData data = ScarabData.PUI[GetUnitIndex(scarab)]
// should never happen
debug if data == 0 then
debug call BJDebugMsg("|c00FF0000 ERROR: Null ScarabData!")
debug endif
if GetUnitTypeId(scarab) == UID_EXPLODING_SCARAB then
//call BJDebugMsg("burrow")
call EnableTrigger(data.proximity_trig)
elseif GetUnitTypeId(scarab) == UID_EXPLODING_SCARAB_BURROWED then
//call BJDebugMsg("unburrow")
call DisableTrigger(data.proximity_trig)
call TriggerSleepAction(1.0) // Give scarab some time to unburrow
if data.target != null then
call IssueTargetOrderById(data.scarab, OID_selfdestruct, data.target)
endif
endif
set scarab = null
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == AID_SCARAB_BURROW
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
endscope
JASS:
//===========================================================================
// This one adds special effects at the end and removes attached trigger
//===========================================================================
scope ScarabDeath
globals
private constant string FX_SCARAB_EXPLOSION = "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike2.mdl"
endglobals
//===========================================================================
private function Conditions takes nothing returns boolean
if (GetUnitTypeId(GetTriggerUnit()) == UID_EXPLODING_SCARAB) then
return true
endif
if (GetUnitTypeId(GetTriggerUnit()) == UID_EXPLODING_SCARAB_BURROWED) then
return true
endif
return false
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local effect eff
local unit scarab = GetTriggerUnit()
local ScarabData data = ScarabData.PUI[GetUnitIndex(scarab)]
// should never happen
debug if data == 0 then
debug call BJDebugMsg("|c00FF0000 ERROR: Null ScarabData!")
debug endif
// destroy does all cleanup for us.
call data.destroy()
set eff = AddSpecialEffect(FX_SCARAB_EXPLOSION, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()))
call TriggerSleepAction(3.0)
call DestroyEffect(eff)
set eff = null
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
endscope
Fell free to ask...