1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. The 15th Mini-Mapping Contest came to an end. The Secrets of Warcraft 3 are soon to be revealed! Come and vote in the public poll for your favorite maps.
    Dismiss Notice
  3. The 12th incarnation of the Music Contest is LIVE! The theme is Synthwave. Knight Rider needs a song to listen to on his journey. You should definitely have some fun with this theme!
    Dismiss Notice
  4. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Multi unit kill counter

Discussion in 'Triggers & Scripts' started by Hevusrul, Dec 3, 2018.

  1. Hevusrul

    Hevusrul

    Joined:
    Dec 3, 2018
    Messages:
    2
    Resources:
    0
    Resources:
    0
    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.
     
  2. Michael Peppers

    Michael Peppers

    Joined:
    Jun 23, 2009
    Messages:
    148
    Resources:
    1
    Models:
    1
    Resources:
    1
    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.

    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:

    Code (vJASS):
    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: Dec 3, 2018
  3. Hevusrul

    Hevusrul

    Joined:
    Dec 3, 2018
    Messages:
    2
    Resources:
    0
    Resources:
    0
    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,
     
  4. Michael Peppers

    Michael Peppers

    Joined:
    Jun 23, 2009
    Messages:
    148
    Resources:
    1
    Models:
    1
    Resources:
    1
    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: Dec 3, 2018
  5. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,573
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    Could be done a lot cleaner actually.

    Especially with vjass (the current proposal is standard jass) or hashtables.

    There are natives for adding armor and damage in 1.30, the ability workaround is not ideal as well.
     
  6. Michael Peppers

    Michael Peppers

    Joined:
    Jun 23, 2009
    Messages:
    148
    Resources:
    1
    Models:
    1
    Resources:
    1
    Is there a list of added natives somewhere?
     
  7. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,573
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    1.29 and 1.30 patch notes ;P
     
  8. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,186
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    Checkout "documents\warcraft III\jasshelper\common.j" at the end of the file the new natives are placed all of them are starting with "Blz".