• 🏆 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!

Level up hero using JASS

Status
Not open for further replies.
Level 13
Joined
Aug 4, 2012
Messages
1,022
JASS:
scope Level initializer Pick
    globals
        private constant player PLAYER = Player(0)
    endglobals
    private function Okay takes nothing returns nothing
        call SetHeroLevelBJ(GetEnumUnit(), (GetHeroLevel(GetEnumUnit()) +1), false)
    endfunction
    private function Pick takes nothing returns nothing
        call ForGroupBJ(GetUnitsOfPlayerAll(PLAYER), function Okay)
    endfunction
    private function Level takes nothing returns nothing
        local trigger THIS = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(THIS, PLAYER, "-lvl", true)
        call TriggerAddAction(THIS, function Pick)
    endfunction
endscope

I need a system that could level up selected hero by 1 level.
I did my code with little functions.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
Leaking references, BJ's, Bad naming conventions, ugh.

What's your point? Is this a resource or something -__-

I need help, need to make it something like that

Should be initializer Level.

Please always try to state a clear question, and point out what is not working.

I'm bad at english, I'm stupid.
if I initialize Level, it'll level up at 1 second :/ :/
I just want when player chat "-lvl" it'll level up by 1 level
 
Level 8
Joined
Jan 28, 2016
Messages
486
I'm not proficient in vJass so if someone with more experience can correct the following code, please don't hesitate to do so! Not sure if the local trigger needs to be nulled in vJass or if it takes care of itself. My Vanilla Jass version should run though; I fixed all the BJs except the unit group ones and cleaned up a few other things. It's not much of a system but it gets the job done.

JASS:
scope HeroLevelUp initializer Hero_Level
    private function Hero_Check takes nothing returns nothing
        call SetHeroLevel(GetEnumUnit(), (GetHeroLevel(GetEnumUnit())+1), false)
    endfunction

    private function Hero_Pick takes nothing returns boolean
        call ForGroup(GetUnitsOfPlayerAll(GetTriggerPlayer(), function Hero_Check)
        return false
    endfunction

    private function Hero_Level takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(t, Player(0), "-lvlup", true)
        call TriggerAddCondition(t, Condition(function Pick))
        set t = null
    endfunction
endscope
JASS:
function Hero_Check takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true
endfunction
                                          
function Hero_Up takes nothing returns nothing
    call SetHeroLevel( GetEnumUnit(), GetHeroLevel(GetEnumUnit())+1, false )
endfunction

function Hero_Pick takes nothing returns boolean
    local group heroes = GetUnitsOfPlayerMatching(GetTriggerPlayer(), Condition(function Hero_Check))
    call ForGroup(heroes, function Hero_Up)
    call DestroyGroup(heroes)
    set heroes = null
    return false
endfunction

//===========================================================================
function InitTrig_Hero_Level_Up takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-lvlup", true )
    call TriggerAddCondition( t, Condition(function Hero_Pick) )
    set t = null
endfunction
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
Why would it?
I recommend you to use GUI.

Sorry, can't.

I'm not proficient in vJass so if someone with more experience can correct the following code, please don't hesitate to do so! Not sure if the local trigger needs to be nulled in vJass or if it takes care of itself. My Vanilla Jass version should run though; I fixed all the BJs except the unit group ones and cleaned up a few other things. It's not much of a system but it gets the job done.

JASS:
scope HeroLevelUp initializer Hero_Level
    private function Hero_Check takes nothing returns nothing
        call SetHeroLevel(GetEnumUnit(), (GetHeroLevel(GetEnumUnit())+1), false)
    endfunction

    private function Hero_Pick takes nothing returns boolean
        call ForGroup(GetUnitsOfPlayerAll(GetTriggerPlayer(), function Hero_Check)
        return false
    endfunction

    private function Hero_Level takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(t, Player(0), "-lvlup", true)
        call TriggerAddCondition(t, Condition(function Pick))
        set t = null
    endfunction
endscope
JASS:
function Hero_Check takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true
endfunction
                                          
function Hero_Up takes nothing returns nothing
    call SetHeroLevel( GetEnumUnit(), GetHeroLevel(GetEnumUnit())+1, false )
endfunction

function Hero_Pick takes nothing returns boolean
    local group heroes = GetUnitsOfPlayerMatching(GetTriggerPlayer(), Condition(function Hero_Check))
    call ForGroup(heroes, function Hero_Up)
    call DestroyGroup(heroes)
    set heroes = null
    return false
endfunction

//===========================================================================
function InitTrig_Hero_Level_Up takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-lvlup", true )
    call TriggerAddCondition( t, Condition(function Hero_Pick) )
    set t = null
endfunction

Thanks, trying...
EDIT:

WOW, you did it!
thank you so much
+REP
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
If one lacks basic knowledge, then GUI is "cool" enough.

The vJASS version does leak and does not filter for hero typed units.

The JASS version is implemented better, but the implementation does not really differ much from plain GUI.

Here are some tutorials, if you insist to write code in JASS: http://www.hiveworkshop.com/forums/miscellaneous-tutorials-456/elemental-coder-guide-274346/

Thanks

GUI is awesome for some simple things and even complex things if you know to use custom script when needed. This is a simple thing. JASS should be reserved for times when it is too custom-script heavy or takes too long in GUI.

Alright then.
 
Level 8
Joined
Jan 28, 2016
Messages
486
If one lacks basic knowledge, then GUI is "cool" enough.

The vJASS version does leak and does not filter for hero typed units.

The JASS version is implemented better, but the implementation does not really differ much from plain GUI.

Here are some tutorials, if you insist to write code in JASS: http://www.hiveworkshop.com/forums/miscellaneous-tutorials-456/elemental-coder-guide-274346/

If I could just hijack this thread for a moment,
  • Yes, the Jass version is a slightly more efficient GUI equivalent.
  • Forgot about the Hero-type check in the vJass version.
  • In what way does that same trigger leak?
Cheers.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
vJASS is used for complex and often hypothetical situations when there is no hope, it's not for being "cool".

GUI is probably what you currently need; it's pretty fine for what you currently need.

I won't, I currently learning JASS / vJASS :D :D

If I could just hijack this thread for a moment,
  • Yes, the Jass version is a slightly more efficient GUI equivalent.
  • Forgot about the Hero-type check in the vJass version.
  • In what way does that same trigger leak?
Cheers.

Wow, can't believe I kept missing that! Thanks Bo! :D

Alright.
 

Wrda

Spell Reviewer
Level 25
Joined
Nov 18, 2012
Messages
1,870
Wait, didn't want the trigger to level up a selected hero? This one will level alll heroes of a player.

I won't, I currently learning JASS / vJASS :D :D
So you are learning GUI. GUI is JASS but JASS isn't GUI.
Seriously what makes me more annoyed is the fact that people try to code in vJASS because it is "cool" and makes people think they are the best while writing in a complex script. In fact, I hate it because if you take a look at some systems out there you will see many library requirements and those libraries require others which makes trigger editor a big mess. I would only use it as a last resort or if it doesn't require anything. Even with GUI people can make complex things than in vJASS, just take a look at bribe's DDS, that's splendid work. Not only GUI is faster to work with but also is easier to work with because you can do simple things faster.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
Wait, didn't want the trigger to level up a selected hero? This one will level alll heroes of a player.


So you are learning GUI. GUI is JASS but JASS isn't GUI.
Seriously what makes me more annoyed is the fact that people try to code in vJASS because it is "cool" and makes people think they are the best while writing in a complex script. In fact, I hate it because if you take a look at some systems out there you will see many library requirements and those libraries require others which makes trigger editor a big mess. I would only use it as a last resort or if it doesn't require anything. Even with GUI people can make complex things than in vJASS, just take a look at bribe's DDS, that's splendid work. Not only GUI is faster to work with but also is easier to work with because you can do simple things faster.

Well it's alright for me.
No, I want it to level up selected Hero (if you can)
All hero level up is an optional choice.
 
Level 8
Joined
Jan 28, 2016
Messages
486
Wait, didn't want the trigger to level up a selected hero? This one will level all heroes of a player.

I know. The codes I provided were MPI because I assumed that this was for an AoS-type map. Besides it wouldn't take much effort in adjusting the code to make it level up only the selected Hero.

Well it's alright for me.
No, I want it to level up selected Hero (if you can)
All hero level up is an optional choice.

If there is only 1 Hero per player, then the codes should be fine. Otherwise I could edit them so that they're MUI. I have to leave soon though, so if someone else wants to do it, then by all means go ahead. You could even try it yourself Frengers! :D
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
I know. The codes I provided were MPI because I assumed that this was for an AoS-type map. Besides it wouldn't take much effort in adjusting the code to make it level up only the selected Hero.



If there is only 1 Hero per player, then the codes should be fine. Otherwise I could edit them so that they're MUI. I have to leave soon though, so if someone else wants to do it, then by all means go ahead. You could even try it yourself Frengers! :D

It has more than one hero :D :D
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
  • LevelUp Command
    • Events
      • Player - Player 1 (Red) types a chat message containing /levelup as An exact match
      • Player - Player 2 (Blue) types a chat message containing /levelup as An exact match
      • Player - Player 3 (Teal) types a chat message containing /levelup as An exact match
      • Etc...
    • Conditions
    • Actions
      • Set TempGroups[0] = (Units currently selected by (Triggering player))
      • Unit Group - Pick every unit in TempGroups[0] and do (Actions)
        • Loop - Actions
          • Set TempUnits[0] = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (TempUnits[0] is A Hero) Equal to True
            • Then - Actions
              • Hero - Set TempUnits[0] Hero-level to ((Hero level of TempUnits[0]) + 1), Show level-up graphics
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroups[0])
This trigger will levelup all selected heroes.
You can add a check that the owner of the selected unit is equal to the triggering player, but that is merely optional.

There is no drawback from using GUI in this case except hyper-efficiency and the events (they can be made easily as generic player writes a string in JASS).
Maybe the reputation as scripter is at stake but I doubt that anyone except yourself cares.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
  • LevelUp Command
    • Events
      • Player - Player 1 (Red) types a chat message containing /levelup as An exact match
      • Player - Player 2 (Blue) types a chat message containing /levelup as An exact match
      • Player - Player 3 (Teal) types a chat message containing /levelup as An exact match
      • Etc...
    • Conditions
    • Actions
      • Set TempGroups[0] = (Units currently selected by (Triggering player))
      • Unit Group - Pick every unit in TempGroups[0] and do (Actions)
        • Loop - Actions
          • Set TempUnits[0] = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (TempUnits[0] is A Hero) Equal to True
            • Then - Actions
              • Hero - Set TempUnits[0] Hero-level to ((Hero level of TempUnits[0]) + 1), Show level-up graphics
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroups[0])
This trigger will levelup all selected heroes.
You can add a check that the owner of the selected unit is equal to the triggering player, but that is merely optional.

There is no drawback from using GUI in this case except hyper-efficiency and the events (they can be made easily as generic player writes a string in JASS).
Maybe the reputation as scripter is at stake but I doubt that anyone except yourself cares.

It's been solved, but is my code above optimal??
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well... first of all, that is definately not what this thread was about.
Secondly, you leak a unit group of all units on the map per 0.1 interval... which is horrible to even think about.
And next to that, I assume that you are spamming creep respawns as soon as someone dies... I assume that that is not how it is supposed to be in every single way that I can see your code.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
Well... first of all, that is definately not what this thread was about.
Secondly, you leak a unit group of all units on the map per 0.1 interval... which is horrible to even think about.
And next to that, I assume that you are spamming creep respawns as soon as someone dies... I assume that that is not how it is supposed to be in every single way that I can see your code.

haha yeah, wrong topic. Sorry.
I was not focus, I think you were commenting on those thread, but it's not haha.
lol

Now, how about this??
This works, but I dunno if there's any lacking :/ :/
JASS:
call TriggerRegisterAnyUnitEventBJ(THIS, EVENT_PLAYER_UNIT_DEATH)
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
I dont know how the system should be used but I assume that you shouldnt group all units in the entire map.

Just do the Go function as action of the trigger and use the death event indeed.

At least that is my guess.

Alright, that makes sense now.
I used those current code and I got this result: sometimes the hero won't revive.
 
Status
Not open for further replies.
Top