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

[Solved] TimedExp

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well... with my great idea of giving heroes experience over time to give you a slightly better view on how much experience you gained, I wrote TimedExperience.

To my greatest surprise, it didn't have any errors when I saved it after completing the code, but it didn't really work as expected.

With a few BJDebugMsg()s, I managed to find out that there was nothing wrong with my system, but it is actually Warcraft III that is unable to give experience in such a short time.

JASS:
library TimedExperience uses TimerUtils
    //! runtextmacro CREATE_UNIQUE_ID("TimedExp")
    globals
        
        real            TIMEDEXP_INTERVAL   = 0.1
        integer         TIMEDEXP_STEPS      = 10
        
        unit array      timedExp_Hero
        integer array   timedExp_Steps
        integer array   timedExp_Exp_Total
        integer array   timedExp_Exp_Current
        boolean array   timedExp_EyeCandy
        
    endglobals
    
    function AddHeroXPTimed_Callback takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer id = GetTimerData(t)
        local integer newExp
        
        set timedExp_Steps[id] = timedExp_Steps[id] -1
        if timedExp_Steps[id] > 0 then
            set newExp = R2I(timedExp_Exp_Total[id] * (TIMEDEXP_STEPS-timedExp_Steps[id]) * TIMEDEXP_INTERVAL)
            call AddHeroXP(timedExp_Hero[id], newExp - timedExp_Exp_Current[id], timedExp_EyeCandy[id])
            call BJDebugMsg("EXP added: " + I2S(newExp - timedExp_Exp_Current[id]))
            set timedExp_Exp_Current[id] = newExp
            
        else
            call AddHeroXP(timedExp_Hero[id], timedExp_Exp_Total[id] - timedExp_Exp_Current[id], timedExp_EyeCandy[id])
            call BJDebugMsg("EXP added: " + I2S(timedExp_Exp_Total[id] - timedExp_Exp_Current[id]))
            set timedExp_Hero[id] = null
            set timedExp_Steps[id] = 0
            set timedExp_Exp_Total[id] = 0
            set timedExp_Exp_Current[id] = 0
            set timedExp_EyeCandy[id] = false
            call TimedExp_ReleaseId(id)
            call ReleaseTimer(t)
            
        endif
        
        set t = null
    endfunction
    function AddHeroXPTimed takes unit whichHero, integer xpToAdd, boolean showEyeCandy returns nothing
        local integer id = TimedExp_CreateId()
        local timer t = NewTimerEx(id)
        
        set timedExp_Hero[id] = whichHero
        set timedExp_Steps[id] = TIMEDEXP_STEPS
        set timedExp_Exp_Total[id] = xpToAdd
        set timedExp_Exp_Current[id] = 0
        set timedExp_EyeCandy[id] = showEyeCandy
        call TimerStart(t, TIMEDEXP_INTERVAL, true, function AddHeroXPTimed_Callback)
        
        set t = null
    endfunction
    
endlibrary

If there is anyone who can enlighten me about it, then please do.
 
Last edited by a moderator:
Level 3
Joined
Mar 3, 2011
Messages
58
I have noticed it too even with basic triggers
Every "x" seconds of game time
Give 1 xp every 1 second to "group x"

The XP bar wouldn't update every 1 point, sometimes it would be 2 or even 4 when hovering it
 
Level 3
Joined
Dec 14, 2014
Messages
16
The unit panel UI only updates when it wants to, so there's probably just a limit imposed to reduce the amount of redraws it needs.
 
The unit panel UI only updates when it wants to, so there's probably just a limit imposed to reduce the amount of redraws it needs.

If this is the case, then there might be some hope. There is a similar problem that happens when you level-up a spell through triggers. When you hover over the tooltip, it will remain as the old tooltip for a while until you change selection (or something like that).

However, you can force redraws through various methods. The easiest method is probably to add/remove an ability:
http://www.thehelper.net/threads/resettooltips.124830/

Funnily enough, I think the really really old tactic was to kill a unit. I think that also resets tooltips, heheh.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
Yea killing the unit worked perfectly!
Maybe I am missing something but how can killing the hero ever be a viable solution to this? I thought the point of this system was to give the hero experience, and not kill the hero.

Or are you saying that killing any unit globally (or just onscreen) refreshes the UI? In that case do be aware that units are expensive to create, you might want to have a resurrecting one which you can recycle.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Maybe I am missing something but how can killing the hero ever be a viable solution to this? I thought the point of this system was to give the hero experience, and not kill the hero.

I must say that I haven't tested it on different units than the hero but when I kill the hero, the UI instantly updates.
But the ResetTooltips library also works.
It adds and removes a custom ability to the unit that you want to update.
Maybe that specific ability is the least heavy but adding/removing an ability per 0.1 seconds should be fine at all.

I Got the cure! !!!

set the heroes level up and then set it back
But yea, I prefer the ability version.

you can hide the level up, it's an option

level up hero, hide/show level up graphics
Imagine me having a system that increases a hero's health/mana/damage/armor/str/int/agi/etc per level by a certain amount.
Then, everytime that I want to update the UI, that hero will gain bonus stats because he fires the "Hero gains a level" event which I use as events for that system.

Would be a pretty overpowered hero after a minute or two.
 
Status
Not open for further replies.
Top