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

~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
964
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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