GetBounty
v1.2
Requires VJASS
What is GetBounty?
GetBounty enables you to get the bounty value of a specific unit
Why did i make this?
I made this because I badly needed a GetBounty script for my Vampirism Speed map, and i could not find one anywhere at all.
I needed it to display the amount of gold that was fed to the opposing team.
And furthermore, all the bounty value in my map does not have dices.
Alternative 1 (Best):
Requires: Damage
Credits: Jesus4Lyf
Example use:
Alternative 2:
Requires: Damage
Credits: Jesus4Lyf
Alternative 3:
Requires no other system
Example usage:
Trigger:
v1.2
Requires VJASS
What is GetBounty?
GetBounty enables you to get the bounty value of a specific unit
Why did i make this?
I made this because I badly needed a GetBounty script for my Vampirism Speed map, and i could not find one anywhere at all.
I needed it to display the amount of gold that was fed to the opposing team.
And furthermore, all the bounty value in my map does not have dices.
Alternative 1 (Best):
Requires: Damage
Credits: Jesus4Lyf
JASS:
library DyingBounty initializer OnInit uses Damage
globals
private integer array LastGold
private player TempPlayer
endglobals
private function OnDamage takes nothing returns boolean
set TempPlayer=GetOwningPlayer(GetEventDamageSource())
set LastGold[GetPlayerId(TempPlayer)]=GetPlayerState(TempPlayer,PLAYER_STATE_RESOURCE_GOLD)
return false
endfunction
private function OnInit takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerAddCondition(t,Filter(function OnDamage))
call Damage_RegisterEvent(t)
endfunction
function GetDyingBounty takes nothing returns integer
set TempPlayer=GetOwningPlayer(GetKillingUnit())
return GetPlayerState(TempPlayer,PLAYER_STATE_RESOURCE_GOLD)-LastGold[GetPlayerId(TempPlayer)]
endfunction
endlibrary
Example use:
Trigger:
- Untitled Trigger 002
- Events
- Unit - A unit Dies
- Conditions
- Actions
- Custom script: call BJDebugMsg("Bounty on death: "+I2S(GetDyingBounty()))
- Events
Alternative 2:
Requires: Damage
Credits: Jesus4Lyf
JASS:
library DyingBounty initializer OnInit uses Damage, AIDS
private struct GoldStore extends array
integer gold
static method init takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerAddCondition(t,Filter(function thistype.onDamage))
call Damage_RegisterEvent(t)
set t=null // Personal habit. Aaand a good one.
endmethod
//! runtextmacro AIDS()
private static method onDamage takes nothing returns boolean
set GoldStore[GetTriggerUnit()].gold=GetPlayerState(GetOwningPlayer(GetEventDamageSource()),PLAYER_STATE_RESOURCE_GOLD)
return false
endmethod
endstruct
private function OnInit takes nothing returns nothing
// Because those init functions on structs fire way too early.
call GoldStore.init()
endfunction
globals
private unit TempUnit
endglobals
function GetDyingBounty takes nothing returns integer
set TempUnit=GetKillingUnit()
if TempUnit==null then
// Killed with triggers or whatever.
return 0
endif
return GetPlayerState(GetOwningPlayer(TempUnit),PLAYER_STATE_RESOURCE_GOLD)-GoldStore[GetDyingUnit()].gold
endfunction
endlibrary
Alternative 3:
Requires no other system
Example usage:
JASS:
call DisplayTimedTextToPlayer(player, 0. , 0., 5. , "The bounty of the last killed unit is " + I2S(GetBounty(GetUnitTypeId(GetDyingUnit() ))) )
Trigger:
JASS:
//////////////////////Get BOUNTY v2///////////////////////////////////////////////////////////////////////////////////
// How to use:
// 1. Copy and paste this trigger into your map
// 2. set the integer variable DUMMY_ID to a dummy unit ID in your map
// 3. (Optional) Set real X and Y to the coordinates that you desire
//// For real X and Y, they determined where the dummy units will be created, this does not really matters because the dummy units cannot be seen in game.
// 4. (Optional) Set BOUNTY_ACCURACY to an integer number that you desire.
//// For BOUNTY_ACCURACY, a higher number will produce a more accurate average result but will be slower, vice versa.
//// For BOUNTY_ACCURACY, you can set it to 1 if your map uses non-diced bounty.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Pros:
// 1. Does not leak, as far as i can tell
// 2. Easy implementation
// 3. Does NOT mess up the alliance between neutral hostile and victim
// 4. Does NOT mess up the gold of neutral hostile
// 5. The entire operation of the script is -Hidden- in game, the players in game will NOT see anything being created at all.
// 6. 100% accurate for non-diced bounty
// 7. You can set the BOUNTY_ACCURACY, so that it will give a rough average of diced bounty in your map.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Cons:
// 1. Inaccurate for diced bounty
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
library GetBounty
/////////////////////////////////////////////////////////
//You may edit the values below//////////////////////////
globals
private constant integer DUMMY_ID = 039;n000039;
private constant real X = 0.
private constant real Y = 0.
private constant integer BOUNTY_ACCURACY = 3
endglobals
//////////////////////////////////////////////////////////
//Editing of options ends here, all that is below here is the script
/////////////////////////////////////////////////////////
function GetBounty takes integer unit_id returns integer
local integer loops = 0
local integer bounty = 0
local integer originalgold = GetPlayerState(Player(PLAYER_NEUTRAL_AGGRESSIVE), PLAYER_STATE_RESOURCE_GOLD)
local unit dummyattacker = CreateUnit( Player(PLAYER_NEUTRAL_AGGRESSIVE) , DUMMY_ID, X, Y , 0. )
local unit dummyattacked
call SetPlayerState(Player(bj_PLAYER_NEUTRAL_VICTIM) , PLAYER_STATE_GIVES_BOUNTY , 1)
call SetPlayerAllianceStateBJ( Player(PLAYER_NEUTRAL_AGGRESSIVE), Player(bj_PLAYER_NEUTRAL_VICTIM), bj_ALLIANCE_UNALLIED )
loop
exitwhen loops == BOUNTY_ACCURACY
set dummyattacked = CreateUnit( Player(bj_PLAYER_NEUTRAL_VICTIM) , unit_id , X, Y , 0. )
call ShowUnit(dummyattacked, false)
call UnitDamageTarget(dummyattacker,dummyattacked,1000000000.,false,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_ENHANCED,null)
call RemoveUnit(dummyattacked)
set bounty = bounty + GetPlayerState(Player(PLAYER_NEUTRAL_AGGRESSIVE), PLAYER_STATE_RESOURCE_GOLD) - originalgold
call SetPlayerState( Player(PLAYER_NEUTRAL_AGGRESSIVE), PLAYER_STATE_RESOURCE_GOLD, originalgold )
set loops = loops + 1
endloop
call SetPlayerAllianceStateBJ( Player(PLAYER_NEUTRAL_AGGRESSIVE), Player(bj_PLAYER_NEUTRAL_VICTIM), bj_ALLIANCE_ALLIED )
call SetPlayerState(Player(bj_PLAYER_NEUTRAL_VICTIM) , PLAYER_STATE_GIVES_BOUNTY , 0)
call RemoveUnit(dummyattacker)
set dummyattacker = null
set dummyattacked = null
set bounty = bounty / BOUNTY_ACCURACY
return bounty
endfunction
endlibrary
Changelog:
v1.2
1. No longer shows gold coin animation
2. Options to easily set for users
3. Average diced bounty
4. Neutral hostile gold no longer need to be at a constant 0
5. Neutral hostile and neutral victim does not need to be permanent enemies