• 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] Decrease Hero Exp?

Status
Not open for further replies.
Level 3
Joined
Mar 3, 2011
Messages
33
Hey there,
topic describes my problem!

I desperately want to use the xp bar of the hero as a life bar, but so far i can't figure out how and if at all i can REDUCE the xp of a hero. Adding xp is not a problem (why is there even a 'set xp' trigger then?), which makes me wonder. Is there a way to jass or custom script a workaround somehow? I'm a noob when it comes to jass btw...

Thanks in advance :grin:

EDIT: Well it kinda works if i use add xp with a negative int, so i will stick with that. If anyone got a smarter idea, let me know!
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
Thats basically how you do it, xp with a negative integer. You can also set the level of the hero to the level of the hero and it will wipe all exp gained to the next level
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Hey there,
topic describes my problem!

I desperately want to use the xp bar of the hero as a life bar, but so far i can't figure out how and if at all i can REDUCE the xp of a hero. Adding xp is not a problem (why is there even a 'set xp' trigger then?), which makes me wonder. Is there a way to jass or custom script a workaround somehow? I'm a noob when it comes to jass btw...

Thanks in advance :grin:

EDIT: Well it kinda works if i use add xp with a negative int, so i will stick with that. If anyone got a smarter idea, let me know!

thx to u, i got a ideea, about exp reduction

JASS:
function GetLvExp takes unit u returns integer
    local integer exp
    local integer lv = GetHeroLevel(u)
    local integer ConstFactor = 100
    local integer StartExp = 200
    if lv > 1 then
        set exp = StartExp + ConstFactor * (lv - 3) * (lv + 2) / 2 + lv * ConstFactor
    else
        set exp = 0
    endif
    return exp
endfunction

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local unit u = GetDyingUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local integer LevelExp = GetLvExp(u)
    local integer CurrentExp = GetHeroXP(u)
    local integer ExpReduction = 25
    local integer NewExp = (( - 1 * ( CurrentExp - LevelExp )) * (100 - ExpReduction)) / 100
if IsUnitType (u,UNIT_TYPE_HERO) then
    if CurrentExp > LevelExp then
        call AddHeroXP( u, NewExp, false )
    endif
    call DisplayTextToForce( GetPlayersAll(), "Current Experience: " + I2S(CurrentExp) )
    call DisplayTextToForce( GetPlayersAll(), "Previous Level Up Experience: " + I2S(LevelExp) )
    call DisplayTextToForce( GetPlayersAll(), "Lost Experince Reduction: " + I2S(ExpReduction) + "%" )
    call DisplayTextToForce( GetPlayersAll(), "New Experience:" + I2S(NewExp) )
    call ReviveHero( u, x , y, false )
    if GetOwningPlayer(u) == GetLocalPlayer() then
        call SelectUnit(u, true)
        call PanCameraTo( x, y )
    endif

endif
    set u = null
endfunction

//===========================================================================
function InitTrig_Hero_Exp_Reduction takes nothing returns nothing
    set gg_trg_Hero_Exp_Reduction = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Exp_Reduction, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Hero_Exp_Reduction, function Trig_Untitled_Trigger_001_Actions )
endfunction

+rep
 
Level 5
Joined
Sep 19, 2006
Messages
152
Silly question: why do you use local variables in place of static numbers?

JASS:
    local integer ConstFactor = 100
    local integer StartExp = 200
    if lv > 1 then
        set exp = StartExp + ConstFactor * (lv - 3) * (lv + 2) / 2 + lv * ConstFactor
    else
        set exp = 0
    endif

Why not just write the following?
JASS:
    if lv > 1 then
        set exp = 200 + 100 * (lv - 3) * (lv + 2) / 2 + lv * 100
    else
        set exp = 0
    endif
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Silly question: why do you use local variables in place of static numbers?

JASS:
    local integer ConstFactor = 100
    local integer StartExp = 200
    if lv > 1 then
        set exp = StartExp + ConstFactor * (lv - 3) * (lv + 2) / 2 + lv * ConstFactor
    else
        set exp = 0
    endif

Why not just write the following?
JASS:
    if lv > 1 then
        set exp = 200 + 100 * (lv - 3) * (lv + 2) / 2 + lv * 100
    else
        set exp = 0
    endif

only for who dont know the formula then from names he can read it, and understand better than alot number, also if somebody changed the gameplay constants then can change it easier and dont need to check what number is what :)
 
Status
Not open for further replies.
Top