Spell Scarab Mines

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.

JASS:
//===========================================================================
//  This one creates scarab, attaches trigger to it and orders him to burow
//===========================================================================

scope ScarabMines

globals
    constant integer UID_EXPLODING_SCARAB = 'u001'
    constant integer UID_EXPLODING_SCARAB_BURROWED = 'u002'

    constant integer AID_SCARAB_MINES = 'A000'
    constant integer AID_SCARAB_BURROW = 'A001'    
    constant integer AID_SCARAB_EXPLOSION = 'A002'
    
    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(&quot;|c00FF0000 ERROR: Null ScarabData!&quot;)
    debug endif
    
    if GetUnitTypeId(scarab) == UID_EXPLODING_SCARAB then
        //call BJDebugMsg(&quot;burrow&quot;)
        call EnableTrigger(data.proximity_trig)
    elseif GetUnitTypeId(scarab) == UID_EXPLODING_SCARAB_BURROWED then
        //call BJDebugMsg(&quot;unburrow&quot;)
        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 = &quot;Abilities\\Spells\\Human\\FlameStrike\\FlameStrike2.mdl&quot;
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(&quot;|c00FF0000 ERROR: Null ScarabData!&quot;)
    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...
 

Attachments

  • Scarab Mines.w3x
    46.5 KB · Views: 482
  • scarab_mines.PNG
    scarab_mines.PNG
    457.2 KB · Views: 719

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
My hero died at the same moment as the enemy die. NO!

And, 3 triggers of 1 spell?
You can't do it in 1 trigger?
 

Cohadar

master of fugue
Reaction score
209
No I can't, it's that kind of spell.

I could put all 3 trigger codes inside one trigger but it would be impossible to understand, and this is after all a show-how spell.

If I just wanted to make standard goblin mines that explode when you step on them it would take one trigger, but this is a little more complicated.

Well I hope you had fun killing yourself with your own mines :D
 

Chjoodge

New Member
Reaction score
14
I would prefer the spell to create the scarab unborrowed, because most of the time I like to spawn a scarab and then move him somewhere immediately.

The scarab could be a lot smaller, now it's kind of a megascarab, being twice as large as a grunt :) But anyone can tweak that on their own.

The exploding ability would benefit from the targeting image, so you can see which units are gonna get boomed. You should also add a hotkey to the explode, so I can run with the scarab, finger ready on the hotkey, and then press the button at the right moment. But I missed the point of the explode ability being able to be set on autocast? What does that do?

And just a thing - you forgot to disable the "Index #X successfully recycled" messages. But I guess anyone can turn them off by himself.

Anyways, moving mines are nice :)
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>you forgot to disable the "Index #X successfully recycled" messages.
Is it a debug message? You could simply turn off debug mode to not let the message to show out.
 

saw792

Is known to say things. That is all.
Reaction score
280
Spell is outdated as it uses return bug-abusing H2I, won't work in current patch without system update of ABC and PUI. Problem is only really in the test map though, as latest system versions should fix it.
 

Romek

Super Moderator
Reaction score
963
This is fine. The spell code itself works for all versions, only the systems used need updates.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top