Custom Hero Bounty Problem

roaaaarrrr

New Member
Reaction score
33
I'm trying to add a custom hero bounty to my map so that you get a different amount of gold depending on the level of the killed hero. I wanted to create an array so that the values can be completely customizable and don't have to follow a specific equation.

This is the basic idea of what I want to do, but I know I am doing it wrong...

JASS:
globals
    integer array HeroBounty
endglobals

function GetBountyAmount takes nothing returns nothing
   set HeroBounty[1]=100
   set HeroBounty[2]=125
   set HeroBounty[3]=150
   set HeroBounty[4]=175
   set HeroBounty[5]=200
   set HeroBounty[6]=225
   set HeroBounty[7]=250
   set HeroBounty[8]=275
   set HeroBounty[9]=300
   set HeroBounty[10]=325
   set HeroBounty[11]=350
   set HeroBounty[12]=375
   set HeroBounty[13]=400
   set HeroBounty[14]=425
   set HeroBounty[15]=450
   set HeroBounty[16]=500
   set HeroBounty[17]=500
   set HeroBounty[18]=500
endfunction

function Trig_Hero_Bounty_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction  
 

function Trig_Hero_Bounty_Actions takes nothing returns nothing
    local integer L 
    set L = GetHeroLevel(GetDyingUnit())
    call AdjustPlayerStateBJ( GetBountyAmount(L)), GetOwningPlayer(GetKillingUnitBJ()), PLAYER_STATE_RESOURCE_GOLD )
endfunction

//===========================================================================
function InitTrig_Hero_Bounty takes nothing returns nothing
    set gg_trg_Hero_Bounty = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Bounty, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hero_Bounty, Condition( function Trig_Hero_Bounty_Conditions ) )
    call TriggerAddAction( gg_trg_Hero_Bounty, function Trig_Hero_Bounty_Actions )
endfunction
 

Ice Snake

Cool Member
Reaction score
3
Yes, i think your map is Footy Frenzy, I love FF! <3

But you should put your code to JASS tag... :)
 

Embrace_It

New Member
Reaction score
9
Change your conditions to:

JASS:

function Trig_Hero_Bounty_Conditions takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction


Also, you can just set your element values in the InitTrig_Hero_Bounty function.

This is probably what you want in the actions:

JASS:

function GetBountyAmount takes nothing returns nothing
    local unit source = GetTriggerUnit()
    local player owner = GetOwningPlayer(GetKillingUnit())

    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD) + HeroBounty[GetHeroLevel(source) - 1])

    set source = null
    set owner = null
endfunction


Array elements start at index 0, not 1(that is why I subtract 1 from the killed hero's level in the actions) so change your array to:

JASS:

   set HeroBounty[0]=100
   set HeroBounty[1]=125
   set HeroBounty[2]=150
   set HeroBounty[3]=175
   set HeroBounty[4]=200
   set HeroBounty[5]=225
   set HeroBounty[6]=250
   set HeroBounty[7]=275
   set HeroBounty[8]=300
   set HeroBounty[9]=325
   set HeroBounty[10]=350
   set HeroBounty[11]=375
   set HeroBounty[12]=400
   set HeroBounty[13]=425
   set HeroBounty[14]=450
   set HeroBounty[15]=500
   set HeroBounty[16]=500
   set HeroBounty[17]=500


I dont have WC3 in front of me atm, so everything might not compile properly cos I cant remember the native calls :p Anyways, hope this helps.

PS: You could have this equation instead of the array (I know you want an array, I'm just saying :)):

JASS:

function GetHeroGoldBounty takes integer lvl returns real
    if lvl &gt; 16 then
        return 500.
    else
        return (lvl - 1) * BOUNTY_PER_LEVEL + STARTING_BOUNTY
    endif
endfunction


BOUNTY_PER_LEVEL = 25.
STARTING_BOUNTY = 125.
 

roaaaarrrr

New Member
Reaction score
33
Thanks for the help. I am no longer getting any compile errors, but for some reason it still isnt working. I kill the hero but still get the base hero amount (266 gold - the number from the object editor). Any ideas?

Here's the code (I added text-tags from Cohadar's tag system)

JASS:
globals
    integer array HeroBounty
endglobals

function GetBountyAmount takes nothing returns nothing
    set HeroBounty[0]=100
   set HeroBounty[1]=125
   set HeroBounty[2]=150
   set HeroBounty[3]=175
   set HeroBounty[4]=200
   set HeroBounty[5]=225
   set HeroBounty[6]=250
   set HeroBounty[7]=275
   set HeroBounty[8]=300
   set HeroBounty[9]=325
   set HeroBounty[10]=350
   set HeroBounty[11]=375
   set HeroBounty[12]=400
   set HeroBounty[13]=425
   set HeroBounty[14]=450
   set HeroBounty[15]=500
   set HeroBounty[16]=500
   set HeroBounty[17]=500
   set HeroBounty[18]=500
   set HeroBounty[19]=500
   set HeroBounty[20]=500
endfunction

function Trig_Hero_Bounty_Conditions takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction
 

function Trig_Hero_Bounty_Actions takes nothing returns nothing
    local unit source = GetTriggerUnit()
    local player owner = GetOwningPlayer(GetKillingUnit())

    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD) + HeroBounty[GetHeroLevel(source) - 1])
    call TextTag_GoldBounty(source,&quot;+&quot;+I2S(R2I(HeroBounty[GetHeroLevel(source) - 1])) ,owner)
    set source = null
    set owner = null
endfunction

//===========================================================================
function InitTrig_Hero_Bounty takes nothing returns nothing
    set gg_trg_Hero_Bounty = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Hero_Bounty, function Trig_Hero_Bounty_Actions )
endfunction
 

saw792

Is known to say things. That is all.
Reaction score
280
You have no event any more. You need that TriggerRegisterAnyUnitEventBJ(...) line for the actions to run.
 

roaaaarrrr

New Member
Reaction score
33
lol oops. Not sure how that got deleted. Now its working, except it gives me 0 gold and Im not sure why.
 

Embrace_It

New Member
Reaction score
9
Quoting myself...

Also, you can just set your element values in the InitTrig_Hero_Bounty function.

The function GetBountyAmount is never called, and thus your array does not contain the proper values (apart for some trash prolly). Set the array values in the InitTrig_Hero_Bounty, and change GetBountyAmount to:

JASS:

function GetBountyAmount takes integer lvl returns integer
   return HeroBounty[lvl]
endfunction


and the gold giving + texttag to:

JASS:

call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD) + GetBountyAmount(GetHeroLevel(source) - 1))
    call TextTag_GoldBounty(source,&quot;+&quot;+I2S(R2I(GetBountyAmount(GetHeroLevel(source) - 1)) ,owner)
 

millz-

New Member
Reaction score
25
JASS:

function Trig_Hero_Bounty_Actions takes nothing returns nothing
    local unit source = GetTriggerUnit()
    local player owner = GetOwningPlayer(GetKillingUnit())

    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD) + HeroBounty[GetHeroLevel(source) - 1])
    call TextTag_GoldBounty(source,&quot;+&quot;+I2S(R2I(HeroBounty[GetHeroLevel(source) - 1])) ,owner)
    set source = null
    set owner = null
endfunction
to
JASS:

function Trig_Hero_Bounty_Actions takes nothing returns nothing
    local unit source = GetTriggerUnit()
    local player owner = GetOwningPlayer(GetKillingUnit())
    local integer Bounty = (GetHeroLevel(source)-1) * 25 + 100

    if Bounty &gt; 500 then
        set Bounty = 500
    endif

    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD) + Bounty)
    call TextTag_GoldBounty(source,&quot;+&quot;+I2S(Bounty),owner)
    set source = null
    set owner = null
endfunction


And you wouldn't need that wall of variables.
 

roaaaarrrr

New Member
Reaction score
33
Yeah, those numbers are just examples. I wanted an array so I can customize each value independently.
 

millz-

New Member
Reaction score
25
There is definitely a way to set the equation. Unless your bounty amount are all jumbled up e.g.: lvl 1 100 gold lvl 2 300 gold lvl 3 50 gold, which doesn't really makes sense?
It's just a suggestion, but I think your trigger is already working the way you want it, so ignore this.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top