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: 481
  • scarab_mines.PNG
    scarab_mines.PNG
    457.2 KB · Views: 717

~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 The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top