• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Multi unit kill counter

Status
Not open for further replies.
Level 1
Joined
Dec 3, 2018
Messages
2
Hello, I am new to this site, please bare with me.

You know how in Starcraft you can see each individual units killing blows? Each unit in the game keeps track of their own personal kills.

I would like to create a system that would replicate this and take it a step further in Warcraft 3.

When a unit reaches a specified kill count they could gain abilities or stats. Such as, gaining 1 armor and 3 damage at 5 kills.


The idea I had in my head is; each unit I want to keep track of could have a custom ability. Adopting the military rank system, it would be called "Private" and it would represent 0 kills. Once they reach 5 kills, this ability in their command card would be replaced with "Sergeant" and they would gain some stats or an ability. This would be accomplished by using the spellbook ability for each rank and inside the spellbook would be the actual stats or abilities so it doesn't clutter each units command card.

I found a similar thread here, however I will need to do some heavy modifications. Some of the modifications I'm not sure about are the following:

In my map I'm going to have 200~ish units up at a time. I'm going to be excluding a good portion of those since they will be under AI control, however when a unit dies I wondered if I need to remove them from the hashtable. Surely the hashtable can only store so much data without slowing down. It'll reach a thousand by the end of the game I'm sure. I'm not positive on how to code this or if its even necessary. I've never done work with custom script before and my experience with hashtables is small. Additionally, i'm not really sure how to clear leaks. The unit group command in the map from that thread won't be executed since no units will be up at map initialization. Should I keep bj_wantDestroygroup=True? I was wondering if someone more experienced could help me polish these triggers since I'm a little out of my league.

As for conditions (such as excluding the AI) and implementing those same triggers with modifications-- i'm confident I'll have no issues minus the things stated above. I'd appreciate it if you could humor a noob and help out his first project.
 
Level 13
Joined
Jun 23, 2009
Messages
299
I'm not sure if the hashtable unit value can leak but I'd still null it after death just in case. I'd expand the "SKTS Event" (if you're using that) to make it check if the dying unit has your custom ability and remove it from the hashtable.

Should I keep bj_wantDestroygroup=True?

If those units are never ever gonna be in the map at initialization you can just skip the whole thing (outside of getting the hashtable set up) and check for your units as they're trained to put them in the hashtable. That event trigger is also pretty bad in your case, a check to exclude most units from going through all that code is in order. Excluding the AI is also an easy condition to add around, don't know it in GUI tho.

I did something similar by giving an ability to my units and then rank up (change into another unit) at level 3. As long as you don't care about what happens at 20+ kills it's probably the easiest approach to your problem, that's how I did it:

JASS:
function SwordsmanRank__Main takes nothing returns boolean
//if the killing unit has the right ID and the Player has a certain upgrade
if GetUnitTypeId(GetKillingUnit()) == 'beu9' and GetPlayerTechCount(GetOwningPlayer(GetKillingUnit()), 'Berb', true) != 0 then
    if GetUnitAbilityLevel(GetKillingUnit(), 'Beak') == 3 then //if enough kills are reached
        call UnitRemoveBuffs(GetKillingUnit(), true, true) //remove buffs, required
        call UnitAddAbility(GetKillingUnit(), 'Beal') //adds an ability that can change a unit into another
    else
        call IncUnitAbilityLevel(GetKillingUnit(), 'Beak') //the ability level/kill count increases
    endif
endif
return false
endfunction

//===========================================================================
function SwordsmanRank__Init takes nothing returns nothing
local trigger t= CreateTrigger()
  
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH) //A unit dies
    call TriggerAddCondition(t, Condition(function SwordsmanRank__Main)) //A condition is executed

endfunction

Adding whatever buffs to the unit should be simple, could easily be added to ^.
 
Last edited:
Level 1
Joined
Dec 3, 2018
Messages
2
Thank you for the help. I can't help but appreciate how amazing vjass is. You got about a dozen lines there and it accomplishes so much. Perhaps I should stop my project and learn to write everything in jass,
 
Level 13
Joined
Jun 23, 2009
Messages
299
Thank you for the help. I can't help but appreciate how amazing vjass is. You got about a dozen lines there and it accomplishes so much. Perhaps I should stop my project and learn to write everything in jass,
If you don't do crazy stuff, normal Jass is fine, it's fast to both write and edit. Check some tutorials out there about it, there are some good ones. The same thing can easily be done in GUI, btw, but takes way more time. Most of the setup is in the Abilities themselves, which is not a lot of work, but it's something to consider.
You add vJass in the form of systems other people already coded when you need them. Or when you wanna use it, it's not that different anyway.
 
Last edited:
Status
Not open for further replies.
Top