• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Spell] Carrion Beetle ability using a unit with Reincarnation as the summon

Status
Not open for further replies.
Level 2
Joined
Apr 25, 2018
Messages
13
Hello HIVE folks, I'm working on a custom ability for a Necromancer unit (not Hero ability even tho it's based on one) which creates a single permanent undead unit until slain, the thing is it has a Reincarnation ability, and with it, I can create an unlimited amount of these Undead units from corpses 'cause they revive once killed by the Carrion Beetle's effect.

I've limited it to a number of 4 units max that can be created, and of course, they don't waste the Food resource because they're summons. Also they're supposed to have a Reincarnation ability to give them a "undead-can't-die" kind of feel. Of course, they're supposed to actually die once the Reincarnation ability has been triggered already and it's on cooldown.

Carrion Beetle doesn't create more than the max number of generated units that it is allowed to create, but as I stated before, if the unit has the Reincarnation ability, it BREAKS the limit.

So, what should I do here?

What Triggers should I use for this?

Should I base it on Raise Dead instead? :con:
 
Level 8
Joined
May 21, 2019
Messages
435
It kinda sounds like an inherent limitation stemming from how Reincarnation works vs. how Carrion Beetle keeps track of the amount of units it has summoned.

The only surefire way to fix this, is to use triggers.

You'd need to keep track of the carrion beetles each player has in play, probably using a combination of unit groups and a unit indexer, and then uphold the limitation yourself, by killing the oldest unit as is the default behavior.

Say that you have an array of unit groups and an array of units for each player that can use this ability.
Then, when a beetle is summoned, you'd add it to the unit group using the player number as index.
You then check if the group contains more than 4 units, and if that's the case, you kill the unit at index 0 (remember to remove reincarnation from it first), and shift all other units down 1 index number, then add the new unit on index 3 as the new (4th oldest unit). You'd need to maintain the index by removing units and shifting other units down, whenever one of them dies of natural causes.

You could also make this MUI for each individual player, by instead indexing the beetles using the casting unit as key in a hashtable. This would be more tedious to develop, but would work for multiple casters on one player, instead of limiting itself to 4 beetles per player.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
Here's something I threw together real quick. It's not perfect but it works. It uses Bribe's Unit Indexer so you'll need to import that to your map if you want to make use of it. This means that if you have any triggers using Custom Value then there will probably be some conflicts.

I never really learned how to use JASS properly so hopefully it doesn't leak. Here's the code, I use it in combination with some GUI to make things easy:
vJASS:
library UncleSpawn

function SpawnSummon takes nothing returns nothing
    local unit Summon = GetSummonedUnit()
    local unit Summoner = GetSummoningUnit()
    local unit KillSummon
    local integer SummonerIndex = GetUnitUserData(Summoner)
    local integer SummonIndex = GetUnitUserData(Summon)
    set udg_SummonOwner[SummonIndex] = SummonerIndex

    if udg_SummonCount[SummonerIndex] >= udg_SummonLimit then
        set KillSummon = GroupPickRandomUnit(udg_SummonGroup[SummonerIndex])
        call UnitRemoveAbility(KillSummon, udg_SummonReincarnate)
        set udg_SummonCount[SummonerIndex] = udg_SummonCount[SummonerIndex] - 1
        call GroupRemoveUnit(udg_SummonGroup[SummonerIndex], KillSummon)

        set udg_SummonPrevent = true
        if IsUnitType(KillSummon, UNIT_TYPE_DEAD) == true then
            call RemoveUnit(KillSummon)
        else
            call KillUnit(KillSummon)
        endif
        set udg_SummonPrevent = false
    endif

    set udg_SummonCount[SummonerIndex] = udg_SummonCount[SummonerIndex] + 1
    call GroupAddUnit(udg_SummonGroup[SummonerIndex], Summon)

    set Summon = null
    set Summoner = null
    set KillSummon = null
endfunction

function SpawnDies takes nothing returns nothing
    local unit Summon = GetTriggerUnit()
    local integer SummonIndex = GetUnitUserData(Summon)
    local integer SummonerIndex = udg_SummonOwner[SummonIndex]

    if udg_SummonPrevent == false then
        set udg_SummonCount[SummonerIndex] = udg_SummonCount[SummonerIndex] - 1
        call GroupRemoveUnit(udg_SummonGroup[SummonerIndex], Summon)
    endif

    set Summon = null
endfunction

endlibrary

You'll have to set the Reincarnation ability in the Summon Configure trigger and also change the conditions in the Summon Spawn and Summon Dies triggers to look for your summoned units.
 

Attachments

  • Summon JASS.w3x
    35.7 KB · Views: 34
Last edited:
Level 2
Joined
Apr 25, 2018
Messages
13
Wow, it's amazing! It works just as intended! Thanks so much for the code really.

About the map, I'm editing vanilla RoC/TFT maps (Hellfire currently, 116x84) to Altered Melee maps.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
No problem.

I tried fixing the visual issue but it didn't work. The Reincarnation effect doesn't move even if I move the reincarnating unit. I suppose I could trigger the Reincarnation Special Effects instead of relying on the ability in the Object Editor. Are you planning on using the Effects in the first place? And by that I mean the Grave/Beam of light effect that appear while the unit is reincarnating.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
Ah, but do you care if the effect doesn't disappear right away? That's if you even have that problem with the custom art you're using.

Also, I edited the code slightly in my post above (and re-uploaded the map). You can copy the code and paste it over the existing code you already have. I just changed one line, lol.
 
Level 3
Joined
Apr 3, 2019
Messages
48
Wouldn't the easiest solution just be to disable the ability after a certain number of units belonging to player of type are spawned? Or if you want it to work like the carrion beetle, where you can force create another 1 after reaching the cap, and the game will just kill off one of the 5 already in existence... essentially you could do just that? Maybe turn off auto cast after say 5 or whatever, and if player tries to force a 6th then randomly kill one from the unit group?
 
Status
Not open for further replies.
Top