• 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.

Bounty System

Level 6
Joined
Apr 16, 2007
Messages
177
The Bounty System

Replaces the Blizzard bounty.
Features:
  1. Bounty can be changed during gameplay
  2. Players are able to give/recieve only a certain percentage of the original bounty
  3. You are able to react to the bounty event with some nice functions
  4. Absolutely efficient due to Hashtable implementation

Functions:
JASS:
// set a unittype's bounty to min-max
SetUnitTypeBounty( integer unittypeid, integer min, integer max )
// set a player's received and gived bounty to gain% and give%
 // 1 = 100%, 0.5 = 50% and 0 = 0%
SetPlayerBounty( integer playerid, real give, real gain )
// The trigger toregister will fire whenever a unit gives bounty:
TriggerRegisterBountyEvent( trigger toregister )
// Functions that can be used with the TriggerRegisterBountyEvent:
 // NOTE: They are not wait resistant!
// The unit that died and gave the bounty - unit
GetBountyUnit()
 // The amount of bounty, with player gain and give allready comuted - integer
 GetTriggerBounty()
// The player that got the bounty - player
GetBountyPlayer()
// The owner of BountyUnit - player
GetBountyGiver()

REQUIREMENTS:
JassPack NewGen
My Utilities Library
My Hashtable Library
My UnitAttacher Library

ToDo:
Upload my hashtable here, too :p

JASS:
// SPECIAL THANKS: Tom_Kazansky for his incredible wisdom concerning the creation of texttags ; )
/////// VER 00
globals
    // Set To false if you want to add bounty on your own way.
    constant boolean AUTO_ADD_BOUNTY = true
endglobals


 //! runtextmacro AddUnitValue( "BountyMax", "integer", "0" )
 //! runtextmacro AddUnitValue( "BountyMin", "integer", "0" )
 

library BountySystem initializer InitBountySystem needs Hash, Utilities, BountyMinAttacherUnit, BountyMaxAttacherUnit
 globals
      private constant real          DefaultGainValue = 1.0    // 1 = 100%; 0.5 = 50%
      private constant real          DefaultGiveValue = 1.0
            
      private          real    array PlayerBountyGive
      private          real    array PlayerBountyGain
      
      private          integer       Bounty             = 0
      private          unit          BountyGiver        = null
      private          player        BountyGetter       = null
      private          player        BountyGiverOwner   = null
      private constant trigger       BountyTrigger      = CreateTrigger()
      
      private          trigger array AttachedTrigger
      private          integer       AttachedTriggerNum = -1 
      private constant trigger       TriggerHandler     = CreateTrigger()
              constant integer       PLAYER_BOUNTY_GIVE = -1
              constant integer       PLAYER_BOUNTY_GAIN = 1
 endglobals


 function GetBountyUnit takes nothing returns unit
     return BountyGiver
 endfunction
 
 function GetTriggerBounty takes nothing returns integer
     return Bounty
 endfunction

 function GetBountyPlayer takes nothing returns player
     return BountyGetter
 endfunction
 
 function GetBountyGiver takes nothing returns player
     return BountyGiver
 endfunction
 
 function TriggerRegisterBountyEvent takes trigger toregister returns nothing
     set AttachedTriggerNum = AttachedTriggerNum + 1
     set AttachedTrigger    [ AttachedTriggerNum ] = toregister
 endfunction
 
 function SetPlayerBounty takes integer playerid, real give, real gain returns nothing
     set PlayerBountyGive[ playerid ] = give
     set PlayerBountyGain[ playerid ] = gain  
 endfunction
 
 function GetPlayerBounty takes integer playerid, integer bountytype returns real
     if bountytype == PLAYER_BOUNTY_GIVE then
         return PlayerBountyGive[ playerid ]
     elseif bountytype == PLAYER_BOUNTY_GAIN then
         return PlayerBountyGain[ playerid ]
     endif
     return 0.0
 endfunction             
 
 private function GetUnitTypeBounty takes integer unittypeid returns integer
     return GetRandomInt( GetUnitTypeBountyMin( unittypeid ), GetUnitTypeBountyMax( unittypeid ) )
 endfunction
 
 function SetUnitTypeBounty takes integer unittypeid, integer min, integer max returns nothing
     call SetUnitTypeBountyMin( unittypeid, min )
     call SetUnitTypeBountyMax( unittypeid, max )
 endfunction

 private function TriggerHandler_Actions takes nothing returns nothing
             local integer loopIndicator = 0
             local unit    trigUnit      = GetTriggerUnit   (                  )
             local integer trigUnitID    = GetUnitTypeId    ( trigUnit         )
             local integer bounty        = GetUnitTypeBounty( trigUnitID       )
             local player  bountyPlayer  = GetOwningPlayer  ( GetKillingUnit() )
             local player  bountyGiver   = GetOwningPlayer  ( trigUnit         )
             
             set Bounty       = bounty
             set BountyGetter = bountyPlayer
             set BountyGiver  = trigUnit
             set BountyGiverOwner = bountyGiver

             if IsPlayerEnemy( BountyGiverOwner, BountyGetter ) then
                 loop
                     exitwhen loopIndicator > AttachedTriggerNum
                     if TriggerEvaluate( AttachedTrigger[ loopIndicator ] ) then
                        call TriggerExecute( AttachedTrigger[ loopIndicator ] )
                     endif
                     set loopIndicator = loopIndicator + 1
                 endloop
    
            endif
            set trigUnit = null
         endfunction




 
     
     
 private function BountyTrigger_Actions takes nothing returns nothing
             local integer bountyAmount = GetTriggerBounty(            )
             local unit    bountyUnit   = GetBountyUnit   (            )
             local player  bountyPlayer = GetBountyPlayer (            )
             

             local player  bountyGiver    = BountyGiverOwner
             local integer bountyPlayerId = GetPlayerId    ( bountyPlayer )
             local integer bountyGiverId  = GetPlayerId    ( bountyGiver  )
             
             
                            
             set  bountyAmount = R2I( bountyAmount * PlayerBountyGive[ bountyGiverId ] * PlayerBountyGain[ bountyPlayerId ] )

             call CreateBountyText( bountyAmount, bountyUnit, bountyPlayer )
             

             call SetPlayerState     ( bountyPlayer, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( bountyPlayer, PLAYER_STATE_RESOURCE_GOLD ) + bountyAmount )
             call SetPlayerState     ( bountyPlayer, PLAYER_STATE_GOLD_GATHERED, GetPlayerState( bountyPlayer, PLAYER_STATE_GOLD_GATHERED ) + bountyAmount )

                 
             set bountyUnit = null    
         endfunction

 private function InitBountySystem takes nothing returns nothing
             local integer playerIndex = 0
             call TriggerRegisterAnyUnitEventBJ( TriggerHandler, EVENT_PLAYER_UNIT_DEATH         )
             call TriggerAddAction             ( TriggerHandler, function TriggerHandler_Actions )
                          
             loop
                 exitwhen playerIndex > NUMPLAYERS
                 set PlayerBountyGive[ playerIndex ] = DefaultGiveValue
                 set PlayerBountyGain[ playerIndex ] = DefaultGainValue
                 set playerIndex = playerIndex + 1
             endloop
             
             // Please outcomment the following two lines if you do not want to distribute bounty as usually!
             if AUTO_ADD_BOUNTY then
                call TriggerRegisterBountyEvent   ( BountyTrigger )
                call TriggerAddAction             ( BountyTrigger, function BountyTrigger_Actions )
             endif
            
         endfunction
endlibrary
 
Last edited:
Level 6
Joined
Apr 16, 2007
Messages
177
any example map?

Here:
With -toggle, you can toggle how the bounty for heroes will be computed:
Either 100, or 100 + 20 * Herolevel.
( AUTO_ADD_BOUNTY has been set to false for this purpose. If you set it to true, it will automatically compute and add bounty, which might end in adding bounty twice. )

This is just to show what the system can do. If you just want to use the normal system, only 1 line is needed per unit you want to spawn bounty.

Greetings, Davey
 

Attachments

  • TEstmap.w3x
    42.8 KB · Views: 81
Top