Name | Type | is_array | initial_value |
Bounties | hashtable | No | |
Bounty | integer | No | |
Bounty__ByKill | boolean | Yes | |
Bounty__Cleared | boolean | Yes | |
Bounty__ForceEnum | force | No | |
Bounty__Recursion | integer | No | |
Bounty__Used | boolean | No | |
BountyAge | real | No | |
BountyAllowFriendFire | boolean | No | |
BountyBase | integer | No | |
BountyClear | trigger | No | |
BountyColor | string | No | |
BountyData | integer | No | |
BountyDeadEvent | real | No | |
BountyDice | integer | No | |
BountyDirection | real | No | |
BountyDyingUnit | unit | No | |
BountyEffect | string | No | |
BountyEvent | real | No | |
BountyFadePoint | real | No | |
BountyGet | trigger | No | |
BountyGetBase | trigger | No | |
BountyGetDice | trigger | No | |
BountyGetSides | trigger | No | |
BountyHeight | real | No | |
BountyHold | trigger | No | |
BountyKillingUnit | unit | No | |
BountyLifeSpan | real | No | |
BountyLocPos | location | No | |
BountyNotClear | boolean | No | |
BountyPermanent | boolean | No | |
BountyPlayer | player | No | |
BountyPlayerState | string | No | |
BountyPosX | real | No | |
BountyPosY | real | No | |
BountyRelease | trigger | No | |
BountySet | trigger | No | |
BountySetBase | trigger | No | |
BountySetDice | trigger | No | |
BountySetSides | trigger | No | |
BountyShow | boolean | No | |
BountyShowEffect | boolean | No | |
BountyShowNothing | boolean | No | |
BountySides | integer | No | |
BountySize | real | No | |
BountySpeed | real | No | |
BountyText | trigger | No | |
BountyTextTag | texttag | No | |
BountyUnitID | unitcode | No | |
BountyUnitPos | unit | No | |
BountyWhoSee | force | No | |
DEF_AGE | real | No | |
DEF_ALLOW_FRIEND_FIRE | boolean | No | |
DEF_COLOR_GOLD | string | No | |
DEF_COLOR_LUMBER | string | No | |
DEF_DIRECTION | real | No | |
DEF_EFFECT | string | No | |
DEF_FADE_POINT | real | No | |
DEF_HEIGHT | real | No | |
DEF_LIFE_SPAN | real | No | |
DEF_PERMANENT | boolean | No | |
DEF_SHOW | boolean | No | |
DEF_SHOW_EFFECT | boolean | No | |
DEF_SHOW_NOTHING | boolean | No | |
DEF_SIZE | integer | No | |
DEF_SPEED | real | No | |
DEF_STATE | string | No | |
LastCreatedTextTag | texttag | No | |
LIMIT_RECURSION | integer | No | |
LocalPlayer | player | No | |
TempX | real | No | |
TempY | real | No | |
TempZ | real | No |
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
One map, one hashtable. Welcome to NewTable 4.1.0.1
This newest iteration of Table introduces the new HashTable struct.
You can now instantiate HashTables which enables the use of large
parent and large child keys, just like a standard hashtable. Previously,
the user would have to instantiate a Table to do this on their own which -
while doable - is something the user should not have to do if I can add it
to this resource myself (especially if they are inexperienced).
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array
//Enables myHash[parentKey][childKey] syntax.
//Basically, it creates a Table in the place of the parent key if
//it didn't already get created earlier.
method operator [] takes integer index returns Table
local Table t = Table(this)[index]
if t == 0 then
set t = Table.create()
set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
endif
return t
endmethod
//You need to call this on each parent key that you used if you
//intend to destroy the HashTable or simply no longer need that key.
method remove takes integer index returns nothing
local Table t = Table(this)[index]
if t != 0 then
call t.destroy()
call Table(this).remove(index)
endif
endmethod
//Added in version 4.1
method has takes integer index returns boolean
return Table(this).has(index)
endmethod
//HashTables are just fancy Table indices.
method destroy takes nothing returns nothing
call Table(this).destroy()
endmethod
//Like I said above...
static method create takes nothing returns thistype
return Table.create()
endmethod
endstruct
endlibrary
/*****************************************************************************
*
* RegisterNativeEvent v1.1.1.5
* by Bannar
*
* Storage of trigger handles for native events.
*
******************************************************************************
*
* Optional requirements:
*
* Table by Bribe
* hiveworkshop.com/threads/snippet-new-table.188084/
*
******************************************************************************
*
* Important:
*
* Avoid using TriggerSleepAction within functions registered.
* Destroy native event trigger on your own responsibility.
*
******************************************************************************
*
* Core:
*
* function IsNativeEventRegistered takes integer whichIndex, integer whichEvent returns boolean
* Whether index whichIndex has already been attached to event whichEvent.
*
* function RegisterNativeEventTrigger takes integer whichIndex, integer eventId returns boolean
* Registers whichIndex within whichEvent scope and assigns new trigger handle for it.
*
* function GetIndexNativeEventTrigger takes integer whichIndex, integer whichEvent returns trigger
* Retrieves trigger handle for event whichEvent specific to provided index whichIndex.
*
* function GetNativeEventTrigger takes integer whichEvent returns trigger
* Retrieves trigger handle for event whichEvent.
*
*
* Custom events:
*
* function CreateNativeEvent takes nothing returns integer
* Returns unique id for new event and registers it with RegisterNativeEvent.
*
* function RegisterIndexNativeEvent takes integer whichIndex, integer whichEvent, code func returns triggercondition
* Registers new event handler func for event whichEvent specific to index whichIndex.
*
* function RegisterNativeEvent takes integer whichEvent, code func returns triggercondition
* Registers new event handler func for specified event whichEvent.
*
* function UnregisterNativeEventHandler takes integer whichEvent, triggercondition handler returns nothing
* Unregisters specified event handler for event whichEvent. Requires Warcraft 1.30.4+.
*
*****************************************************************************/
library RegisterNativeEvent uses optional Table
globals
private integer eventIndex = 500 // 0-499 reserved for Blizzard native events
endglobals
private module NativeEventInit
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set table = TableArray[0x2000]
endif
endmethod
endmodule
private struct NativeEvent extends array
static if LIBRARY_Table then
static TableArray table
else
static hashtable table = InitHashtable()
endif
implement NativeEventInit
endstruct
function IsNativeEventRegistered takes integer whichIndex, integer whichEvent returns boolean
static if LIBRARY_Table then
return NativeEvent.table[whichEvent].trigger.has(whichIndex)
else
return HaveSavedHandle(NativeEvent.table, whichEvent, whichIndex)
endif
endfunction
function RegisterNativeEventTrigger takes integer whichIndex, integer whichEvent returns boolean
if not IsNativeEventRegistered(whichIndex, whichEvent) then
static if LIBRARY_Table then
set NativeEvent.table[whichEvent].trigger[whichIndex] = CreateTrigger()
else
call SaveTriggerHandle(NativeEvent.table, whichEvent, whichIndex, CreateTrigger())
endif
return true
endif
return false
endfunction
function GetIndexNativeEventTrigger takes integer whichIndex, integer whichEvent returns trigger
static if LIBRARY_Table then
return NativeEvent.table[whichEvent].trigger[whichIndex]
else
return LoadTriggerHandle(NativeEvent.table, whichEvent, whichIndex)
endif
endfunction
function GetNativeEventTrigger takes integer whichEvent returns trigger
return GetIndexNativeEventTrigger(bj_MAX_PLAYER_SLOTS, whichEvent)
endfunction
function CreateNativeEvent takes nothing returns integer
local integer eventId = eventIndex
call RegisterNativeEventTrigger(bj_MAX_PLAYER_SLOTS, eventId)
set eventIndex = eventIndex + 1
return eventId
endfunction
function RegisterIndexNativeEvent takes integer whichIndex, integer whichEvent, code func returns triggercondition
call RegisterNativeEventTrigger(whichIndex, whichEvent)
return TriggerAddCondition(GetIndexNativeEventTrigger(whichIndex, whichEvent), Condition(func))
endfunction
function RegisterNativeEvent takes integer whichEvent, code func returns triggercondition
return RegisterIndexNativeEvent(bj_MAX_PLAYER_SLOTS, whichEvent, func)
endfunction
function UnregisterNativeEventHandler takes integer whichEvent, triggercondition handler returns nothing
call TriggerRemoveCondition(GetNativeEventTrigger(whichEvent), handler)
endfunction
endlibrary
/******************************************************************************************************/
/*************************************Bounty Controller by HerlySQR************************************/
/******************************************************************************************************/
//
// https://www.hiveworkshop.com/threads/jass-lua-bounty-controller-gui-friendly.332114/
//
// This library was made to have almost every control of the Bountie.s of the units
// Important is have deactivated the Bountie.s (this system do that, but don't active them)
// and you have to set the values of the Bountie.s manually, only requires JassHelper.
//! novjass
//////If you wanna set the default value of the bounty of the units, first use the event "BountyEvent becomes Equal to 2.00"
// (If you wanna do it in the map initialization) and then you must use these functions:
SetBountyBase("'ID of the unit'","Bounty: Base")
SetBountyDice("'ID of the unit'","Bounty: Number of dice")
SetBountySides("'ID of the unit'","Bounty: Sides per dice")
// or to do it all in once use this function:
BOUNTY("'ID of the unit'","Bounty: Base","Bounty: Number of dice","Bounty: Sides per dice")
// to get a posible bounty from a unit use the function:
GetBountyFromUnitType("'ID of the unit'")
// to get the individual values of the bounty use these functions:
GetBountyBase("'ID of the unit'")
GetBountyDice("'ID of the unit'")
GetBountySides("'ID of the unit'")
//
//////Is also posible do it in GUI, doing this steps
SetBountyBase:
Set BountyUnitID = "Unit-Type of you unit"
Set BountyBase = "Bounty: Base"
Trigger - Run BountySetBase (Ignoring conditions)
SetBountyDice:
Set BountyUnitID = "Unit-Type of you unit"
Set BountyDice = "Bounty: Number of dice"
Trigger - Run BountySetDice (Ignoring conditions)
SetBountySides:
Set BountyUnitID = "Unit-Type of you unit"
Set BountySides = "Bounty: Sides per dice"
Trigger - Run BountySetBase (Ignoring conditions)
BOUNTY:
Set BountyUnitID = "Unit-Type of you unit"
Set BountyBase = "Bounty: Base"
Set BountyDice = "Bounty: Number of dice"
Set BountySides = "Bounty: Sides per dice"
Trigger - Run BountySet (Ignoring conditions)
//
//////The variables used are cleaned automatically, and to get the values do:
GetBountyBase:
Set BountyUnitID = "Unit-Type of you unit"
Trigger - Run BountyGetBase (Ignoring conditions)
The variable "BountyBase" has the value wanted.
GetBountyDice:
Set BountyUnitID = "Unit-Type of you unit"
Trigger - Run BountyGetDice (Ignoring conditions)
The variable "BountyDice" has the value wanted.
GetBountySides:
Set BountyUnitID = "Unit-Type of you unit"
Trigger - Run BountyGetBase (Ignoring conditions)
The variable "BountySides" has the value wanted.
GetBountyFromUnitType:
Set BountyUnitID = "Unit-Type of you unit"
Trigger - Run BountyGet (Ignoring conditions)
The variable "Bounty" has the value wanted.
//
//////To edit the values of a bounty when a unit dies you must have
// a trigger with the event "BountyDeadEvent becomes Equal to 1.00", this event happens when
// a unit dies and the function "BountyText" will be called (That is called it doesn't mean the text will be displayed
// and the bounty will be given to the player, only those two will happen if all the rest of values are valid)
// the variables that you can edit are:
"Bounty": The quantity of gold or lumber that you will receive (it can be negative).
"BountyTextTag": The texttag that will be displayed.
"BountyPermanent": This allows erase it (care, if this value is true and you don't use the texttag later it can be an object leak)
"BountyColor": The color of the text (if is not set, the color of the text will have the default values depending of the state).
"BountySize": The size of the text.
"BountyLifeSpan": The lifetime of the text (if "BountyPermanent" is true this value is useless).
"BountyFadePoint": When the text will start to fade.
"BountySpeed": The speed of the text.
"BountyDirection": The direction to the texttag will move.
"BountyHeight": How many distance the text will be from the floor.
"BountyShow": To show the text or not.
"BountyShowNothing": If the Bounty is 0 by default the text is not showed, if you set this to true, the text will be showed even if the bounty is 0.
"BountyAllowFriendFire": By default the bounty only will happen if the dying unit is enemy of the killing unit, if you set this to true, the bounty will happen even if they weren't enemies.
"BountyEffect": The effect that will be displayed (In the same place of the text)
"BountyShowEffect": The effect will be displayed if this value is true.
"BountyPlayer": The player how will receive the bounty.
"BountyPlayerState": What type of bounty the player will receive (only "gold" and "lumber" are valid).
"BountyUnitPos": The position of the text and the effect (If is a unit)
"BountyLocPos": The position of the text and the effect (If is a location, this have more priority than BountyUnitPos, and is removed with the clear function to prevent object leak, of course only if "BountyNotClear" is not true, and for this reason don't set it to a variable that you gonna use later)
"BountyPosX", "BountyPosY", "BountyPosZ": The coords of the texttag when is displayed (they are only to read them, and only accesible with the event "BountyEvent becomes Equal to 1.00").
"BountyWhoSee": The players who can see the text.
"BountyData": Is an integer that you can store (Since the process is practically instant there is no much point on storing a value, but you can use it to add an extra "condition").
/* To reffering the killing unit use the variable */"BountyKillingUnit"/* and to the dying unit, */"BountyDyingUnit"/*
// and when the bounty is given an (maybe) the text displayed you can use the event */"BountyEvent becomes Equal to 1.00"/*
// You can't edit the values with this (except BountyNotClear), because it happens after the process ends, but you can get them.
// If you wanna use the */function BountyText/* with a trigger with the */"BountyEvent" or "BountyDeadEvent"/*, to not overwrite the values you should use */"Trigger - Run BountyHold (Ignoring conditions)"/*
// or in Jass just */call BountyHold()/* (this will treat the next values as new, at least BountyNotClear is true) and in the end use */"Trigger - Run BountyRelease (Ignoring conditions)"/*
// or in Jass just */call BountyRelease()/* (only once).
//
// (Note: If you wanna change the variable */"BountyPlayer"/*, to show him the text you have to (maybe) remove the previous player
// and add the new player to the player group */"BountyWhoSee"/*, but in Jass you can use the */function ChangeBountyPlayer(player newPlayer, boolean removePrevious, boolean addNew)/*.)
//
//////If you wanna have your own bounty with another event or function just set some of the variables previously seen
// there are neccesary values like */"Bounty"/*, */"BountyPlayer"/*, */"BountyWhoSee"/* (You have to add manually the */BountyPlayer/* in this case),
// */"BountyUnitPos or BountyLocPos"/*, because they not have default values different than nothing
// and then add in GUI */"Trigger - Run BountyText (Ignoring conditions)"/* or in Jass */call BountyText()/*
// But in Jass you can use the function */BountyCall(integer bounty, unit unitpos, player bountyPlayer, boolean addplayer, boolean permanent)/*.
//
//////If you wanna have access to the texttag use the variable */"BountyTextTag"/*, but you have to know how, you can only do it with the event */"BountyEvent"/*
// if you use this when you use manually the */function BountyText/* better do */set Temp=BountyText()/* or */set Temp=BountyCall(...)/*.
//
// And if you wanna keep the changes of the previous instance (included */"BountyTextTag"/*), set the variable */"BountyNotClear"/* to true, and you have to do it every instance
// you do if you wanna still saving the changes because this value is returned to false, but carefully, because the next instance can have
// unwanted changes.
//
// Additionally it has the variable */LocalPlayer/* to not use */GetLocalPlayer()/* everytime, if you don't like it,
// just uncoment the "private" before of it in the global section.
*/
//////If you wanna deactive the system do "Trigger - Turn off Bounty Controller <gen>"
//
//////You can use the functions
RegisterBountyDeadEvent(code func)
RegisterBountyEvent(code func)
// To replace
set mytrigger=CreateTrigger()
call TriggerRegisterVariableEvent(mytrigger,"udg_BountyDeadEvent",EQUAL,1.00)
call TriggerAddAction(mytrigger,function Actions)
// For
call RegisterBountyDeadEvent(function Actions)
// To only use a single trigger that use these custom events and make it more easy to code and to reffer to the principal trigger use:
GetNativeBountyDeadEventTrigger()
GetNativeBountyEventTrigger()
//! endnovjass
//=====================================================================================================
library BountyController initializer Init /*
*/requires /*
*/optional Table, /*https://www.hiveworkshop.com/threads/snippet-new-table.188084/
*/optional RegisterNativeEvent /*https://www.hiveworkshop.com/threads/snippet-registerevent-pack.250266/ */
globals
/*private*/ player LocalPlayer
//This constants can be edited (obviously only valid values)
private constant string DEF_COLOR_GOLD="ffcc00"
private constant string DEF_COLOR_LUMBER="32cd32"
private constant integer DEF_SIZE=10
private constant real DEF_LIFE_SPAN=3.50
private constant real DEF_AGE=0.00
private constant real DEF_SPEED=64
private constant real DEF_DIRECTION=90
private constant real DEF_FADE_POINT=2.50
private constant string DEF_STATE="gold"
private constant real DEF_HEIGHT=0
private constant boolean DEF_SHOW=true
private constant boolean DEF_SHOW_NOTHING=false
private constant boolean DEF_ALLOW_FRIEND_FIRE=false
private constant string DEF_EFFECT="UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
private constant boolean DEF_SHOW_EFFECT=true
private constant boolean DEF_PERMANENT=false
private constant integer LIMIT_RECURSION=16 //If a loop caused by recursion is doing in porpouse you can edit the tolerance of how many calls can do
endglobals
private struct Bountie extends array
static force ForceEnum
static integer Recursion=0
static boolean array Cleared
static boolean array ByKill
static if LIBRARY_Table then
static Table array s
static integer Index=3
else
static hashtable s=InitHashtable()
endif
static if LIBRARY_RegisterNativeEvent then
static integer UNIT_BOUNTY_DEAD_EVENT
static integer UNIT_BOUNTY_EVENT
else
static trigger t1=CreateTrigger()
static trigger t2=CreateTrigger()
endif
endstruct
//The functions to set the bounty stats
function SetBountyBase takes integer id, integer base returns nothing
static if LIBRARY_Table then
set Bountie.s[0].integer[id]=base
else
call SaveInteger(Bountie.s,0,id,base)
endif
endfunction
function SetBountyDice takes integer id, integer dice returns nothing
static if LIBRARY_Table then
set Bountie.s[1].integer[id]=dice
else
call SaveInteger(Bountie.s,1,id,dice)
endif
endfunction
function SetBountySides takes integer id, integer sides returns nothing
static if LIBRARY_Table then
set Bountie.s[2].integer[id]=sides
else
call SaveInteger(Bountie.s,2,id,sides)
endif
endfunction
function BOUNTY takes integer id, integer base, integer dice, integer side returns nothing
call SetBountyBase(id,base)
call SetBountyDice(id,dice)
call SetBountySides(id,side)
endfunction
//The functions to get the bounty stats (that you set before)
function GetBountyBase takes integer id returns integer
static if LIBRARY_Table then
return Bountie.s[0].integer[id]
else
return LoadInteger(Bountie.s,0,id)
endif
endfunction
function GetBountyDice takes integer id returns integer
static if LIBRARY_Table then
return Bountie.s[1].integer[id]
else
return LoadInteger(Bountie.s,1,id)
endif
endfunction
function GetBountySides takes integer id returns integer
static if LIBRARY_Table then
return Bountie.s[2].integer[id]
else
return LoadInteger(Bountie.s,2,id)
endif
endfunction
function GetBountyFromUnitType takes integer id returns integer
return GetBountyBase(id)+GetRandomInt(0,GetBountyDice(id)*GetBountySides(id))
endfunction
//This function is runned at the map initialization, if you wanna use it to set your Bountie.s, you can do it
private function SetData takes nothing returns nothing
local integer i
static if LIBRARY_Table then
set Bountie.s[0]=Table.create()
set Bountie.s[1]=Table.create()
set Bountie.s[2]=Table.create()
else
call SaveInteger(Bountie.s,0,-1,3)
endif
/*Peasant*/ call BOUNTY('hpea',35,6,3)
set i=0
loop
exitwhen i>PLAYER_NEUTRAL_AGGRESSIVE
call SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY,false,Player(i))
set i=i+1
endloop
set i=0
loop
exitwhen i>LIMIT_RECURSION
set Bountie.Cleared[i]=false
set Bountie.ByKill[i]=false
set i=i+1
endloop
endfunction
//To clear the data
function BountyClear takes nothing returns nothing
if not udg_BountyNotClear then
set udg_BountyTextTag=null
set udg_BountyColor=null
set udg_BountySize=DEF_SIZE
set udg_BountyLifeSpan=DEF_LIFE_SPAN
set udg_BountyAge=DEF_AGE
set udg_BountyFadePoint=DEF_FADE_POINT
set udg_BountySpeed=DEF_SPEED
set udg_BountyDirection=DEF_DIRECTION
set udg_BountyPlayerState=DEF_STATE
set udg_BountyHeight=DEF_HEIGHT
set udg_BountyShow=DEF_SHOW
set udg_BountyShowNothing=DEF_SHOW_NOTHING
set udg_BountyAllowFriendFire=DEF_ALLOW_FRIEND_FIRE
set udg_BountyEffect=DEF_EFFECT
set udg_BountyShowEffect=DEF_SHOW_EFFECT
set udg_BountyPermanent=DEF_PERMANENT
set udg_BountyPlayer=null
set udg_BountyUnitPos=null
set udg_BountyPosX=0.00
set udg_BountyPosY=0.00
set udg_Bounty=0
set udg_BountyData=0
call ForceClear(udg_BountyWhoSee)
if udg_BountyLocPos!=null then
call RemoveLocation(udg_BountyLocPos)
set udg_BountyLocPos=null
endif
set udg_BountyKillingUnit=null
set udg_BountyDyingUnit=null
endif
set Bountie.Cleared[Bountie.Recursion]=true
set udg_BountyNotClear=false
endfunction
//This is to store the values of a BountyDeadEvent and BountyEvent in case you wanna use the BountyText function
private function ForceAddForce takes nothing returns nothing
call ForceAddPlayer(Bountie.ForceEnum,GetEnumPlayer())
endfunction
private function CopyForce takes force princ returns force
set Bountie.ForceEnum=CreateForce()
call ForForce(princ,function ForceAddForce)
return Bountie.ForceEnum
endfunction
function BountyHold takes nothing returns nothing
static if LIBRARY_Table then
set Bountie.Index=Bountie.Index+1
set Bountie.s[Bountie.Index]=Table.create()
set Bountie.s[Bountie.Index].string[0]=udg_BountyColor
set Bountie.s[Bountie.Index].real[1]=udg_BountySize
set Bountie.s[Bountie.Index].real[2]=udg_BountyLifeSpan
set Bountie.s[Bountie.Index].real[3]=udg_BountyAge
set Bountie.s[Bountie.Index].real[4]=udg_BountyFadePoint
set Bountie.s[Bountie.Index].real[5]=udg_BountySpeed
set Bountie.s[Bountie.Index].real[6]=udg_BountyDirection
set Bountie.s[Bountie.Index].string[7]=udg_BountyPlayerState
set Bountie.s[Bountie.Index].real[8]=udg_BountyHeight
set Bountie.s[Bountie.Index].boolean[9]=udg_BountyShow
set Bountie.s[Bountie.Index].boolean[10]=udg_BountyShowNothing
set Bountie.s[Bountie.Index].boolean[11]=udg_BountyAllowFriendFire
set Bountie.s[Bountie.Index].string[12]=udg_BountyEffect
set Bountie.s[Bountie.Index].boolean[13]=udg_BountyShowEffect
set Bountie.s[Bountie.Index].boolean[14]=udg_BountyPermanent
set Bountie.s[Bountie.Index].player[15]=udg_BountyPlayer
set Bountie.s[Bountie.Index].unit[16]=udg_BountyUnitPos
set Bountie.s[Bountie.Index].integer[17]=udg_Bounty
set Bountie.s[Bountie.Index].force[18]=CopyForce(udg_BountyWhoSee)
set Bountie.s[Bountie.Index].location[19]=udg_BountyLocPos
set Bountie.s[Bountie.Index].unit[20]=udg_BountyKillingUnit
set Bountie.s[Bountie.Index].unit[21]=udg_BountyDyingUnit
set Bountie.s[Bountie.Index].boolean[22]=udg_BountyNotClear
set Bountie.s[Bountie.Index].integer[23]=udg_BountyData
set Bountie.s[Bountie.Index].texttag[24]=udg_BountyTextTag
else
local integer i=LoadInteger(Bountie.s,0,-1)+1
call SaveInteger(Bountie.s,0,-1,i)
call SaveStr(Bountie.s,i,0,udg_BountyColor)
call SaveReal(Bountie.s,i,1,udg_BountySize)
call SaveReal(Bountie.s,i,2,udg_BountyLifeSpan)
call SaveReal(Bountie.s,i,3,udg_BountyAge)
call SaveReal(Bountie.s,i,4,udg_BountyFadePoint)
call SaveReal(Bountie.s,i,5,udg_BountySpeed)
call SaveReal(Bountie.s,i,6,udg_BountyDirection)
call SaveStr(Bountie.s,i,7,udg_BountyPlayerState)
call SaveReal(Bountie.s,i,8,udg_BountyHeight)
call SaveBoolean(Bountie.s,i,9,udg_BountyShow)
call SaveBoolean(Bountie.s,i,10,udg_BountyShowNothing)
call SaveBoolean(Bountie.s,i,11,udg_BountyAllowFriendFire)
call SaveStr(Bountie.s,i,12,udg_BountyEffect)
call SaveBoolean(Bountie.s,i,13,udg_BountyShowEffect)
call SaveBoolean(Bountie.s,i,14,udg_BountyPermanent)
call SavePlayerHandle(Bountie.s,i,15,udg_BountyPlayer)
call SaveUnitHandle(Bountie.s,i,16,udg_BountyUnitPos)
call SaveInteger(Bountie.s,i,17,udg_Bounty)
call SaveForceHandle(Bountie.s,i,18,CopyForce(udg_BountyWhoSee))
call SaveLocationHandle(Bountie.s,i,19,udg_BountyLocPos)
call SaveUnitHandle(Bountie.s,i,20,udg_BountyKillingUnit)
call SaveUnitHandle(Bountie.s,i,21,udg_BountyDyingUnit)
call SaveBoolean(Bountie.s,i,22,udg_BountyNotClear)
call SaveInteger(Bountie.s,i,23,udg_BountyData)
call SaveTextTagHandle(Bountie.s,i,24,udg_BountyTextTag)
endif
call BountyClear()
endfunction
function BountyRelease takes nothing returns nothing
static if LIBRARY_Table then
set udg_BountyColor=Bountie.s[Bountie.Index].string[0]
set udg_BountySize=Bountie.s[Bountie.Index].real[1]
set udg_BountyLifeSpan=Bountie.s[Bountie.Index].real[2]
set udg_BountyAge=Bountie.s[Bountie.Index].real[3]
set udg_BountyFadePoint=Bountie.s[Bountie.Index].real[4]
set udg_BountySpeed=Bountie.s[Bountie.Index].real[5]
set udg_BountyDirection=Bountie.s[Bountie.Index].real[6]
set udg_BountyPlayerState=Bountie.s[Bountie.Index].string[7]
set udg_BountyHeight=Bountie.s[Bountie.Index].real[8]
set udg_BountyShow=Bountie.s[Bountie.Index].boolean[9]
set udg_BountyShowNothing=Bountie.s[Bountie.Index].boolean[10]
set udg_BountyAllowFriendFire=Bountie.s[Bountie.Index].boolean[11]
set udg_BountyEffect=Bountie.s[Bountie.Index].string[12]
set udg_BountyShowEffect=Bountie.s[Bountie.Index].boolean[13]
set udg_BountyPermanent=Bountie.s[Bountie.Index].boolean[14]
set udg_BountyPlayer=Bountie.s[Bountie.Index].player[15]
set udg_BountyUnitPos=Bountie.s[Bountie.Index].unit[16]
set udg_Bounty=Bountie.s[Bountie.Index].integer[17]
call ForceClear(udg_BountyWhoSee)
set Bountie.ForceEnum=udg_BountyWhoSee
call ForForce(Bountie.s[Bountie.Index].force[18],function ForceAddForce)
call DestroyForce(Bountie.s[Bountie.Index].force[18])
set udg_BountyLocPos=Bountie.s[Bountie.Index].location[19]
set udg_BountyKillingUnit=Bountie.s[Bountie.Index].unit[20]
set udg_BountyDyingUnit=Bountie.s[Bountie.Index].unit[21]
set udg_BountyNotClear=Bountie.s[Bountie.Index].boolean[22]
set udg_BountyData=Bountie.s[Bountie.Index].integer[23]
set udg_BountyTextTag=Bountie.s[Bountie.Index].texttag[24]
call Bountie.s[Bountie.Index].destroy()
set Bountie.Index=Bountie.Index-1
else
local integer i=LoadInteger(Bountie.s,0,-1)
call SaveInteger(Bountie.s,0,-1,i-1)
set udg_BountyColor=LoadStr(Bountie.s,i,0)
set udg_BountySize=LoadReal(Bountie.s,i,1)
set udg_BountyLifeSpan=LoadReal(Bountie.s,i,2)
set udg_BountyAge=LoadReal(Bountie.s,i,3)
set udg_BountyFadePoint=LoadReal(Bountie.s,i,4)
set udg_BountySpeed=LoadReal(Bountie.s,i,5)
set udg_BountyDirection=LoadReal(Bountie.s,i,6)
set udg_BountyPlayerState=LoadStr(Bountie.s,i,7)
set udg_BountyHeight=LoadReal(Bountie.s,i,8)
set udg_BountyShow=LoadBoolean(Bountie.s,i,9)
set udg_BountyShowNothing=LoadBoolean(Bountie.s,i,10)
set udg_BountyAllowFriendFire=LoadBoolean(Bountie.s,i,11)
set udg_BountyEffect=LoadStr(Bountie.s,i,12)
set udg_BountyShowEffect=LoadBoolean(Bountie.s,i,13)
set udg_BountyPermanent=LoadBoolean(Bountie.s,i,14)
set udg_BountyPlayer=LoadPlayerHandle(Bountie.s,i,15)
set udg_BountyUnitPos=LoadUnitHandle(Bountie.s,i,16)
set udg_Bounty=LoadInteger(Bountie.s,i,17)
call ForceClear(udg_BountyWhoSee)
set Bountie.ForceEnum=udg_BountyWhoSee
call ForForce(LoadForceHandle(Bountie.s,i,18),function ForceAddForce)
call DestroyForce(LoadForceHandle(Bountie.s,i,18))
set udg_BountyLocPos=LoadLocationHandle(Bountie.s,i,19)
set udg_BountyKillingUnit=LoadUnitHandle(Bountie.s,i,20)
set udg_BountyDyingUnit=LoadUnitHandle(Bountie.s,i,21)
set udg_BountyNotClear=LoadBoolean(Bountie.s,i,22)
set udg_BountyData=LoadInteger(Bountie.s,i,23)
set udg_BountyTextTag=LoadTextTagHandle(Bountie.s,i,24)
call FlushChildHashtable(Bountie.s,i)
endif
endfunction
//This is to check the sign of the bounty
private function Sign takes integer i returns string
if i<0 then
return ""
endif
return "+"
endfunction
//The function that runs the bounty and the texttag
function BountyText takes nothing returns texttag
local playerstate state
local texttag tt
set Bountie.Recursion=Bountie.Recursion+1
if Bountie.Recursion>LIMIT_RECURSION then //If there is recursion that don't stop soon, the system stops automatically
call BJDebugMsg("There is a recursion with the Bounty system, check if you are not creating a infinite loop.")
call BountyClear()
set Bountie.Cleared[Bountie.Recursion]=false
set Bountie.Recursion=Bountie.Recursion-1
return null
endif
if udg_BountyPlayerState=="gold" then
set state=PLAYER_STATE_RESOURCE_GOLD
elseif udg_BountyPlayerState=="lumber" then
set state=PLAYER_STATE_RESOURCE_LUMBER
else
if not Bountie.ByKill[Bountie.Recursion] then
call BountyClear()
endif
set Bountie.Cleared[Bountie.Recursion]=false
set Bountie.Recursion=Bountie.Recursion-1
return null //If the state is not valid, the process stop
endif
if udg_Bounty==0 and not udg_BountyShowNothing then
set udg_BountyShow=false
set udg_BountyShowEffect=false
endif
call AdjustPlayerStateSimpleBJ(udg_BountyPlayer,state,udg_Bounty)
if udg_BountyColor==null then
if udg_BountyPlayerState=="gold" then
set udg_BountyColor=DEF_COLOR_GOLD
elseif udg_BountyPlayerState=="lumber" then
set udg_BountyColor=DEF_COLOR_LUMBER
endif
endif
if udg_BountyLocPos!=null then
set udg_BountyPosX=GetLocationX(udg_BountyLocPos)
set udg_BountyPosY=GetLocationY(udg_BountyLocPos)
elseif udg_BountyUnitPos!=null then
set udg_BountyPosX=GetUnitX(udg_BountyUnitPos)
set udg_BountyPosY=GetUnitY(udg_BountyUnitPos)
else
set udg_BountyShow=false
set udg_BountyShowEffect=false //If there is no position to the text, the text and the effect won't show
endif
set udg_BountyTextTag=CreateTextTag()
call SetTextTagPermanent(udg_BountyTextTag,udg_BountyPermanent)
call SetTextTagText(udg_BountyTextTag,"|cff"+udg_BountyColor+Sign(udg_Bounty)+I2S(udg_Bounty)+"|r",TextTagSize2Height(udg_BountySize))
call SetTextTagVisibility(udg_BountyTextTag,IsPlayerInForce(LocalPlayer,udg_BountyWhoSee) and udg_BountyShow)
call SetTextTagPos(udg_BountyTextTag,udg_BountyPosX,udg_BountyPosY,udg_BountyHeight)
call SetTextTagFadepoint(udg_BountyTextTag,udg_BountyFadePoint)
call SetTextTagLifespan(udg_BountyTextTag,udg_BountyLifeSpan)
call SetTextTagVelocityBJ(udg_BountyTextTag,udg_BountySpeed,udg_BountyDirection)
call SetTextTagAge(udg_BountyTextTag,udg_BountyAge)
if udg_BountyShowEffect then
call DestroyEffect(AddSpecialEffect(udg_BountyEffect,udg_BountyPosX,udg_BountyPosY))
endif
set udg_BountyEvent=0.00
set udg_BountyEvent=1.00
set udg_BountyEvent=0.00
set tt=udg_BountyTextTag
if not Bountie.Cleared[Bountie.Recursion] and not Bountie.ByKill[Bountie.Recursion] then
call BountyClear()
endif
set Bountie.Cleared[Bountie.Recursion]=false
set Bountie.Recursion=Bountie.Recursion-1
return tt
endfunction
private function UnitBounty takes nothing returns nothing
//This is to prevent overwrite in case you add a function that kills a unit inside a trigger with the bountydead's event
local string prevColor=udg_BountyColor
local real prevSize=udg_BountySize
local real prevLifeSpan=udg_BountyLifeSpan
local real prevAge=udg_BountyAge
local real prevFadePoint=udg_BountyFadePoint
local real prevSpeed=udg_BountySpeed
local real prevDirection=udg_BountyDirection
local string prevPlayerState=udg_BountyPlayerState
local real prevHeight=udg_BountyHeight
local boolean prevShow=udg_BountyShow
local boolean prevShowNothing=udg_BountyShowNothing
local boolean prevAllowFriendFire=udg_BountyAllowFriendFire
local string prevEffect=udg_BountyEffect
local boolean prevShowEffect=udg_BountyShowEffect
local boolean prevPermanent=udg_BountyPermanent
local player prevPlayer=udg_BountyPlayer
local unit prevUnitPos=udg_BountyUnitPos
local integer prevBounty=udg_Bounty
local force prevForce=CopyForce(udg_BountyWhoSee)
local location prevLocPos=udg_BountyLocPos
local unit prevKillingUnit=udg_BountyKillingUnit
local unit prevDyingUnit=udg_BountyDyingUnit
local boolean prevNotClear=udg_BountyNotClear
local integer prevData=udg_BountyData
call BountyClear()
set udg_BountyKillingUnit=GetKillingUnit()
set udg_BountyDyingUnit=GetDyingUnit()
set udg_Bounty=GetBountyFromUnitType(GetUnitTypeId(udg_BountyDyingUnit))
set udg_BountyPlayer=GetOwningPlayer(udg_BountyKillingUnit)
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
set udg_BountyUnitPos=udg_BountyDyingUnit
set udg_BountyDeadEvent=0.00
set udg_BountyDeadEvent=1.00
set udg_BountyDeadEvent=0.00
if IsUnitEnemy(udg_BountyDyingUnit,udg_BountyPlayer) or udg_BountyAllowFriendFire then
set Bountie.ByKill[Bountie.Recursion+1]=true
call BountyText()
set Bountie.ByKill[Bountie.Recursion+1]=false
endif
set udg_BountyColor=prevColor
set udg_BountySize=prevSize
set udg_BountyLifeSpan=prevLifeSpan
set udg_BountyAge=prevAge
set udg_BountyFadePoint=prevFadePoint
set udg_BountySpeed=prevSpeed
set udg_BountyDirection=prevDirection
set udg_BountyPlayerState=prevPlayerState
set udg_BountyHeight=prevHeight
set udg_BountyShow=prevShow
set udg_BountyShowNothing=prevShowNothing
set udg_BountyAllowFriendFire=prevAllowFriendFire
set udg_BountyEffect=prevEffect
set udg_BountyShowEffect=prevShowEffect
set udg_BountyPermanent=prevPermanent
set udg_BountyPlayer=prevPlayer
set udg_BountyUnitPos=prevUnitPos
set udg_Bounty=prevBounty
call ForceClear(udg_BountyWhoSee)
set Bountie.ForceEnum=udg_BountyWhoSee
call ForForce(prevForce,function ForceAddForce)
set udg_BountyLocPos=prevLocPos
set udg_BountyKillingUnit=prevKillingUnit
set udg_BountyDyingUnit=prevDyingUnit
set udg_BountyNotClear=prevNotClear
set udg_BountyData=prevData
set prevPlayer=null
set prevUnitPos=null
set prevForce=null
set prevLocPos=null
set prevKillingUnit=null
set prevDyingUnit=null
endfunction
private function UnitBountyCheck takes nothing returns boolean
return GetKillingUnit()!=null //If there is not killing unit then the process stop
endfunction
//Functions to short the Jass process
function BountyCall takes integer bounty, unit pos, player myplayer, boolean addplayer, boolean permanent returns texttag
set udg_Bounty=bounty
set udg_BountyUnitPos=pos
set udg_BountyPlayer=myplayer
if addplayer then
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
endif
set udg_BountyPermanent=permanent
return BountyText()
endfunction
function ChangeBountyPlayer takes player newPlayer, boolean removePrevious, boolean addNew returns nothing
if removePrevious then
call ForceRemovePlayer(udg_BountyWhoSee,udg_BountyPlayer)
endif
set udg_BountyPlayer=newPlayer
if addNew then
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
endif
endfunction
function RegisterBountyDeadEvent takes code func returns nothing
static if LIBRARY_RegisterNativeEvent then
if RegisterNativeEventTrigger(0,Bountie.UNIT_BOUNTY_DEAD_EVENT) then
call TriggerRegisterVariableEvent(GetIndexNativeEventTrigger(0,Bountie.UNIT_BOUNTY_DEAD_EVENT),"udg_BountyDeadEvent",EQUAL,1.00)
endif
call RegisterIndexNativeEvent(0,Bountie.UNIT_BOUNTY_DEAD_EVENT,func)
else
call TriggerAddCondition(Bountie.t1,Condition(func))
endif
endfunction
function GetNativeBountyDeadEventTrigger takes nothing returns trigger
static if LIBRARY_RegisterNativeEvent then
return GetIndexNativeEventTrigger(0,Bountie.UNIT_BOUNTY_DEAD_EVENT)
else
return Bountie.t1
endif
endfunction
function RegisterBountyEvent takes code func returns nothing
static if LIBRARY_RegisterNativeEvent then
if RegisterNativeEventTrigger(0,Bountie.UNIT_BOUNTY_EVENT) then
call TriggerRegisterVariableEvent(GetIndexNativeEventTrigger(0,Bountie.UNIT_BOUNTY_EVENT),"udg_BountyEvent",EQUAL,1.00)
endif
call RegisterIndexNativeEvent(0,Bountie.UNIT_BOUNTY_EVENT,func)
else
call TriggerAddCondition(Bountie.t2,Condition(func))
endif
endfunction
function GetNativeBountyEventTrigger takes nothing returns trigger
static if LIBRARY_RegisterNativeEvent then
return GetIndexNativeEventTrigger(0,Bountie.UNIT_BOUNTY_EVENT)
else
return Bountie.t2
endif
endfunction
//The functions are runned using the triggers
private function callBounty takes nothing returns nothing
call BOUNTY(udg_BountyUnitID,udg_BountyBase,udg_BountyDice,udg_BountySides)
set udg_BountyUnitID=0
set udg_BountyBase=0
set udg_BountyDice=0
set udg_BountySides=0
endfunction
private function callBountyBase takes nothing returns nothing
call SetBountyBase(udg_BountyUnitID,udg_BountyBase)
set udg_BountyUnitID=0
set udg_BountyBase=0
endfunction
private function callBountyDice takes nothing returns nothing
call SetBountyDice(udg_BountyUnitID,udg_BountyDice)
set udg_BountyUnitID=0
set udg_BountyDice=0
endfunction
private function callBountySides takes nothing returns nothing
call SetBountySides(udg_BountyUnitID,udg_BountySides)
set udg_BountyUnitID=0
set udg_BountySides=0
endfunction
private function callBountyGet takes nothing returns nothing
set udg_Bounty=GetBountyFromUnitType(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
private function callBountyBaseGet takes nothing returns nothing
set udg_BountyBase=GetBountyBase(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
private function callBountyDiceGet takes nothing returns nothing
set udg_BountyDice=GetBountyDice(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
private function callBountySidesGet takes nothing returns nothing
set udg_BountySides=GetBountySides(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
//The clear function doesn't run in the initialization, so I used a timer
private function InitClear takes nothing returns nothing
call BountyClear()
call DestroyTimer(GetExpiredTimer())
set udg_BountyEvent=0.00
set udg_BountyEvent=2.00
set udg_BountyEvent=0.00
endfunction
private function Init takes nothing returns nothing
//The trigger that runs when a unit dies
set gg_trg_Bounty_Controller=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Bounty_Controller,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(gg_trg_Bounty_Controller,Condition(function UnitBountyCheck))
call TriggerAddAction(gg_trg_Bounty_Controller,function UnitBounty)
//(For GUI users) The trigger that shows the text
set udg_BountyText=CreateTrigger()
call TriggerAddAction(udg_BountyText,function BountyText)
//(For GUI users) The triggers that set the default bounty of a unit
set udg_BountySet=CreateTrigger()
call TriggerAddAction(udg_BountySet,function callBounty)
set udg_BountySetBase=CreateTrigger()
call TriggerAddAction(udg_BountySetBase,function callBountyBase)
set udg_BountySetDice=CreateTrigger()
call TriggerAddAction(udg_BountySetDice,function callBountyDice)
set udg_BountySetSides=CreateTrigger()
call TriggerAddAction(udg_BountySetSides,function callBountySides)
//(For GUI users) The triggers that get the bounty values of a unit (that you set before)
set udg_BountyGet=CreateTrigger()
call TriggerAddAction(udg_BountyGet,function callBountyGet)
set udg_BountyGetBase=CreateTrigger()
call TriggerAddAction(udg_BountyGetBase,function callBountyBaseGet)
set udg_BountyGetDice=CreateTrigger()
call TriggerAddAction(udg_BountyGetDice,function callBountyDiceGet)
set udg_BountyGetSides=CreateTrigger()
call TriggerAddAction(udg_BountyGetSides,function callBountySidesGet)
//(For GUI users) to clear manually the values
set udg_BountyClear=CreateTrigger()
call TriggerAddAction(udg_BountyClear,function BountyClear)
//(For GUI users) to hold the values during a BountyDeadEvent or BountyEvent
set udg_BountyHold=CreateTrigger()
call TriggerAddAction(udg_BountyHold,function BountyHold)
set udg_BountyRelease=CreateTrigger()
call TriggerAddAction(udg_BountyRelease,function BountyRelease)
//To register the bounty events
static if LIBRARY_RegisterNativeEvent then
set Bountie.UNIT_BOUNTY_DEAD_EVENT=CreateNativeEvent()
set Bountie.UNIT_BOUNTY_EVENT=CreateNativeEvent()
else
call TriggerRegisterVariableEvent(Bountie.t1,"udg_BountyDeadEvent",EQUAL,1.00)
call TriggerRegisterVariableEvent(Bountie.t2,"udg_BountyEvent",EQUAL,1.00)
endif
//Last details
set LocalPlayer=GetLocalPlayer()
call SetData()
call TimerStart(CreateTimer(),0.00,false,function InitClear)
endfunction
endlibrary
//******************************************************************************************************
//*************************************Bounty Controller by HerlySQR************************************
//******************************************************************************************************
//
// https://www.hiveworkshop.com/threads/jass-lua-bounty-controller-gui-friendly.332114/
//
// This library was made to have almost every control of the bounties of the units
// Important is have deactivated the bounties (this system do that, but don't active them)
// and you have to set the values of the bounties manually.
//
//////If you paste this code in the top of the custom script you can use this functions to set the default value
// of the bounty of the units, first use the event "BountyEvent becomes Equal to 2.00" (If you wanna do it in the map initialization)
// and then you must use these functions:
// SetBountyBase("'ID of the unit'","Bounty: Base")
// SetBountyDice("'ID of the unit'","Bounty: Number of dice")
// SetBountySides("'ID of the unit'","Bounty: Sides per dice")
// or to do it all in once use this function:
// BOUNTY("'ID of the unit'","Bounty: Base","Bounty: Number of dice","Bounty: Sides per dice")
// to get a posible bounty from a unit use the function:
// GetBountyFromUnitType("'ID of the unit'")
// to get the individual values of the bounty use these functions:
// GetBountyBase("'ID of the unit'")
// GetBountyDice("'ID of the unit'")
// GetBountySides("'ID of the unit'")
//
//////If not is also posible do it in GUI (or in Jass), doing this steps
// SetBountyBase:
// Set BountyUnitID = "Unit-Type of you unit"
// Set BountyBase = "Bounty: Base"
// Trigger - Run BountySetBase (Ignoring conditions)
// SetBountyDice:
// Set BountyUnitID = "Unit-Type of you unit"
// Set BountyDice = "Bounty: Number of dice"
// Trigger - Run BountySetDice (Ignoring conditions)
// SetBountySides:
// Set BountyUnitID = "Unit-Type of you unit"
// Set BountySides = "Bounty: Sides per dice"
// Trigger - Run BountySetBase (Ignoring conditions)
// BOUNTY:
// Set BountyUnitID = "Unit-Type of you unit"
// Set BountyBase = "Bounty: Base"
// Set BountyDice = "Bounty: Number of dice"
// Set BountySides = "Bounty: Sides per dice"
// Trigger - Run BountySet (Ignoring conditions)
//
//////The variables used are cleaned automatically, and to get the values do:
// GetBountyBase:
// Set BountyUnitID = "Unit-Type of you unit"
// Trigger - Run BountyGetBase (Ignoring conditions)
// The variable "BountyBase" has the value wanted.
// GetBountyDice:
// Set BountyUnitID = "Unit-Type of you unit"
// Trigger - Run BountyGetDice (Ignoring conditions)
// The variable "BountyDice" has the value wanted.
// GetBountySides:
// Set BountyUnitID = "Unit-Type of you unit"
// Trigger - Run BountyGetBase (Ignoring conditions)
// The variable "BountySides" has the value wanted.
// GetBountyFromUnitType:
// Set BountyUnitID = "Unit-Type of you unit"
// Trigger - Run BountyGet (Ignoring conditions)
// The variable "Bounty" has the value wanted.
//
//////To edit the values of a bounty when a unit dies you must have
// a trigger with the event "BountyDeadEvent becomes Equal to 1.00", this event happens when
// a unit dies and the function "BountyText" will be called (That is called it doesn't mean the text will be displayed
// and the bounty will be given to the player, only those two will happen if all the rest of values are valid)
// the variables that you can edit are:
// "Bounty": The quantity of gold or lumber that you will receive (it can be negative).
// "BountyTextTag": The texttag that will be displayed (never edit this value).
// "BountyPermanent": This allows erase it (care, if this value is true and you don't use the texttag later it can be an object leak).
// "BountyAge": For some reason the x,y position of the texttag respect to the camera depends of its speed and age, so you can edit it.
// "BountyColor": The color of the text (if is not set, the color of the text will have the default values depending of the state).
// "BountySize": The size of the text.
// "BountyLifeSpan": The lifetime of the text (if "BountyPermanent" is true this value is useless).
// "BountyFadePoint": When the text will start to fade.
// "BountySpeed": The speed of the text.
// "BountyDirection": The direction to the texttag will move.
// "BountyHeight": How many distance the text will be from the floor.
// "BountyShow": To show the text or not.
// "BountyShowNothing": If the Bounty is 0 by default the text is not showed, if you set this to true, the text will be showed even if the bounty is 0.
// "BountyAllowFriendFire": By default the bounty only will happen if the dying unit is enemy of the killing unit, if you set this to true, the bounty will happen even if they weren't enemies.
// "BountyEffect": The effect that will be displayed (In the same place of the text)
// "BountyShowEffect": The effect will be displayed if this value is true.
// "BountyPlayer": The player how will receive the bounty.
// "BountyPlayerState": What type of bounty the player will receive (only "gold" and "lumber" are valid).
// "BountyUnitPos": The position of the text and the effect (If is a unit)
// "BountyLocPos": The position of the text and the effect (If is a location, this have more priority than BountyUnitPos, and is removed with the clear function to prevent object leak, of course only if "BountyNotClear" is not true, and for this reason don't set it to a variable that you gonna use later)
// "BountyPosX", "BountyPosY": The coords of the texttag when is displayed (they are only to read them(they are only to read them, and only accesible with the event "BountyEvent becomes Equal to 1.00")).
// "BountyWhoSee": The players who can see the text.
// "BountyData": Is an integer that you can store (Since the process is practically instant there is no much point on storing a value, but you can use it to add an extra "condition").
// To reffering the killing unit use the variable "BountyKillingUnit" and to the dying unit, "BountyDyingUnit"
// and when the bounty is given an (maybe) the text displayed you can use the event "BountyEvent becomes Equal to 1.00"
// You can't edit the values with this (except BountyNotClear), because it happens after the process ends, but you can get them
// If you wanna use the function BountyText with a trigger with the "BountyEvent" or "BountyDeadEvent", to not overwrite the values you should use "Trigger - Run BountyHold (Ignoring conditions)"
// or in Jass just call BountyHold() (this will treat the next values as new, at least BountyNotClear is true) and in the end use "Trigger - Run BountyRelease (Ignoring conditions)"
// or in Jass just call BountyRelease() (only once).
// (Note: If you wanna change the variable "BountyPlayer", to show him the text you have to (maybe) remove the previous player
// and add the new player to the player group "BountyWhoSee", but in Jass you can get use the function ChangeBountyPlayer(player newPlayer, boolean removePrevious, boolean addNew).)
//
//////If you wanna have your own bounty with another event or function just set some of the variables previously seen
// there are neccesary values like "Bounty", "BountyPlayer", "BountyWhoSee" (You have to add manually the BountyPlayer in this case),
// "BountyUnitPos or BountyLocPos", because they not have default values different than nothing
// and then add in GUI "Trigger - Run BountyText (Ignoring conditions)" or in Jass "call BountyText()"
// But in Jass you can use the function BountyCall(integer bounty, unit unitpos, player bountyPlayer, boolean addplayer, boolean permanent).
//
//////If you wanna have access to the texttag use the variable "BountyTextTag", but you have to know how, you can only do it with the event "BountyEvent"
// if you use this when you use manually the function BountyText better do "set Temp=BountyText()" or "set Temp=BountyCall(...)".
//
// And if you wanna keep the changes of the previous instance (included "BountyTextTag"), set the variable "BountyNotClear" to true, and you have to do it every instance
// you do if you wanna still saving the changes because this value is returned to false, but carefully, because the next instance can have
// unwanted changes.
//
// Additionally it has the variable LocalPlayer to not use GetLocalPlayer() everytime.
//
//////If you wanna deactive the system do "Trigger - Turn off Bounty Controller Jass <gen>"
//
//=====================================================================================================
//The functions to set the bounty stats
function SetBountyBase takes integer id, integer base returns nothing
call SaveInteger(udg_Bounties,0,id,base)
endfunction
function SetBountyDice takes integer id, integer dice returns nothing
call SaveInteger(udg_Bounties,1,id,dice)
endfunction
function SetBountySides takes integer id, integer sides returns nothing
call SaveInteger(udg_Bounties,2,id,sides)
endfunction
function BOUNTY takes integer id, integer base, integer dice, integer side returns nothing
call SetBountyBase(id,base)
call SetBountyDice(id,dice)
call SetBountySides(id,side)
endfunction
//The functions to get the bounty stats (that you set before)
function GetBountyBase takes integer id returns integer
return LoadInteger(udg_Bounties,0,id)
endfunction
function GetBountyDice takes integer id returns integer
return LoadInteger(udg_Bounties,1,id)
endfunction
function GetBountySides takes integer id returns integer
return LoadInteger(udg_Bounties,2,id)
endfunction
function GetBountyFromUnitType takes integer id returns integer
return GetBountyBase(id)+GetRandomInt(0,GetBountyDice(id)*GetBountySides(id))
endfunction
//This function is runned at the map initialization, if you wanna use it to set your bounties, you can do it
function Bounty__SetData takes nothing returns nothing
local integer i
call BOUNTY('hpea',15,5,3) //Peasant
call DestroyForce(udg_Bounty__ForceEnum) //NOT EVEN A SINGLE LEAK
call SaveInteger(udg_Bounties,0,-1,3)
set i=0
loop
exitwhen i>PLAYER_NEUTRAL_AGGRESSIVE
call SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY,false,Player(i))
set i=i+1
endloop
set i=0
loop
exitwhen i>udg_LIMIT_RECURSION
set udg_Bounty__Cleared[i]=false
set udg_Bounty__ByKill[i]=false
set i=i+1
endloop
endfunction
//To clear the data
function BountyClear takes nothing returns nothing
if not udg_BountyNotClear then
set udg_BountyTextTag=null
set udg_BountyColor=null
set udg_BountySize=udg_DEF_SIZE
set udg_BountyLifeSpan=udg_DEF_LIFE_SPAN
set udg_BountyAge=udg_DEF_AGE
set udg_BountyFadePoint=udg_DEF_FADE_POINT
set udg_BountySpeed=udg_DEF_SPEED
set udg_BountyDirection=udg_DEF_DIRECTION
set udg_BountyPlayerState=udg_DEF_STATE
set udg_BountyHeight=udg_DEF_HEIGHT
set udg_BountyShow=udg_DEF_SHOW
set udg_BountyShowNothing=udg_DEF_SHOW_NOTHING
set udg_BountyAllowFriendFire=udg_DEF_ALLOW_FRIEND_FIRE
set udg_BountyEffect=udg_DEF_EFFECT
set udg_BountyShowEffect=udg_DEF_SHOW_EFFECT
set udg_BountyPermanent=udg_DEF_PERMANENT
set udg_BountyPlayer=null
set udg_BountyUnitPos=null
set udg_BountyPosX=0.00
set udg_BountyPosY=0.00
set udg_Bounty=0
set udg_BountyData=0
call ForceClear(udg_BountyWhoSee)
if udg_BountyLocPos!=null then
call RemoveLocation(udg_BountyLocPos)
set udg_BountyLocPos=null
endif
set udg_BountyKillingUnit=null
set udg_BountyDyingUnit=null
endif
set udg_Bounty__Cleared[udg_Bounty__Recursion]=true
set udg_BountyNotClear=false
endfunction
//This is to store the values of a BountyDeadEvent and BountyDeadEvent in case you wanna use the BountyText function
function Bounty__ForceAddForce takes nothing returns nothing
call ForceAddPlayer(udg_Bounty__ForceEnum,GetEnumPlayer())
endfunction
function Bounty__CopyForce takes force princ returns force
set udg_Bounty__ForceEnum=CreateForce()
call ForForce(princ,function Bounty__ForceAddForce)
return udg_Bounty__ForceEnum
endfunction
function BountyHold takes nothing returns nothing
local integer i=LoadInteger(udg_Bounties,0,-1)+1
call SaveInteger(udg_Bounties,0,-1,i)
call SaveStr(udg_Bounties,i,0,udg_BountyColor)
call SaveReal(udg_Bounties,i,1,udg_BountySize)
call SaveReal(udg_Bounties,i,2,udg_BountyLifeSpan)
call SaveReal(udg_Bounties,i,3,udg_BountyAge)
call SaveReal(udg_Bounties,i,4,udg_BountyFadePoint)
call SaveReal(udg_Bounties,i,5,udg_BountySpeed)
call SaveReal(udg_Bounties,i,6,udg_BountyDirection)
call SaveStr(udg_Bounties,i,7,udg_BountyPlayerState)
call SaveReal(udg_Bounties,i,8,udg_BountyHeight)
call SaveBoolean(udg_Bounties,i,9,udg_BountyShow)
call SaveBoolean(udg_Bounties,i,10,udg_BountyShowNothing)
call SaveBoolean(udg_Bounties,i,11,udg_BountyAllowFriendFire)
call SaveStr(udg_Bounties,i,12,udg_BountyEffect)
call SaveBoolean(udg_Bounties,i,13,udg_BountyShowEffect)
call SaveBoolean(udg_Bounties,i,14,udg_BountyPermanent)
call SavePlayerHandle(udg_Bounties,i,15,udg_BountyPlayer)
call SaveUnitHandle(udg_Bounties,i,16,udg_BountyUnitPos)
call SaveInteger(udg_Bounties,i,17,udg_Bounty)
call SaveForceHandle(udg_Bounties,i,18,Bounty__CopyForce(udg_BountyWhoSee))
call SaveLocationHandle(udg_Bounties,i,19,udg_BountyLocPos)
call SaveUnitHandle(udg_Bounties,i,20,udg_BountyKillingUnit)
call SaveUnitHandle(udg_Bounties,i,21,udg_BountyDyingUnit)
call SaveBoolean(udg_Bounties,i,22,udg_BountyNotClear)
call SaveInteger(udg_Bounties,i,23,udg_BountyData)
call SaveTextTagHandle(udg_Bounties,i,24,udg_BountyTextTag)
call BountyClear()
endfunction
function BountyRelease takes nothing returns nothing
local integer i=LoadInteger(udg_Bounties,0,-1)
call SaveInteger(udg_Bounties,0,-1,i-1)
set udg_BountyColor=LoadStr(udg_Bounties,i,0)
set udg_BountySize=LoadReal(udg_Bounties,i,1)
set udg_BountyLifeSpan=LoadReal(udg_Bounties,i,2)
set udg_BountyAge=LoadReal(udg_Bounties,i,3)
set udg_BountyFadePoint=LoadReal(udg_Bounties,i,4)
set udg_BountySpeed=LoadReal(udg_Bounties,i,5)
set udg_BountyDirection=LoadReal(udg_Bounties,i,6)
set udg_BountyPlayerState=LoadStr(udg_Bounties,i,7)
set udg_BountyHeight=LoadReal(udg_Bounties,i,8)
set udg_BountyShow=LoadBoolean(udg_Bounties,i,9)
set udg_BountyShowNothing=LoadBoolean(udg_Bounties,i,10)
set udg_BountyAllowFriendFire=LoadBoolean(udg_Bounties,i,11)
set udg_BountyEffect=LoadStr(udg_Bounties,i,12)
set udg_BountyShowEffect=LoadBoolean(udg_Bounties,i,13)
set udg_BountyPermanent=LoadBoolean(udg_Bounties,i,14)
set udg_BountyPlayer=LoadPlayerHandle(udg_Bounties,i,15)
set udg_BountyUnitPos=LoadUnitHandle(udg_Bounties,i,16)
set udg_Bounty=LoadInteger(udg_Bounties,i,17)
call ForceClear(udg_BountyWhoSee)
set udg_Bounty__ForceEnum=udg_BountyWhoSee
call ForForce(LoadForceHandle(udg_Bounties,i,18),function Bounty__ForceAddForce)
call DestroyForce(LoadForceHandle(udg_Bounties,i,18))
set udg_BountyLocPos=LoadLocationHandle(udg_Bounties,i,19)
set udg_BountyKillingUnit=LoadUnitHandle(udg_Bounties,i,20)
set udg_BountyDyingUnit=LoadUnitHandle(udg_Bounties,i,21)
set udg_BountyNotClear=LoadBoolean(udg_Bounties,i,22)
set udg_BountyData=LoadInteger(udg_Bounties,i,23)
set udg_BountyTextTag=LoadTextTagHandle(udg_Bounties,i,24)
call FlushChildHashtable(udg_Bounties,i)
endfunction
//This is to check the sign of the bounty
function Bounty__Sign takes integer i returns string
if i<0 then
return ""
endif
return "+"
endfunction
//The function that runs the bounty and the texttag
function BountyText takes nothing returns texttag
local playerstate state
local texttag tt
set udg_Bounty__Recursion=udg_Bounty__Recursion+1
if udg_Bounty__Recursion>udg_LIMIT_RECURSION then //If there is recursion that don't stop soon, the system stops automatically
call BJDebugMsg("There is a recursion with the Bounty system, check if you are not creating a infinite loop.")
call BountyClear()
set udg_Bounty__Cleared[udg_Bounty__Recursion]=false
set udg_Bounty__Recursion=udg_Bounty__Recursion-1
return null
endif
if udg_BountyPlayerState=="gold" then
set state=PLAYER_STATE_RESOURCE_GOLD
elseif udg_BountyPlayerState=="lumber" then
set state=PLAYER_STATE_RESOURCE_LUMBER
else
if not udg_Bounty__ByKill[udg_Bounty__Recursion] then
call BountyClear()
endif
set udg_Bounty__Cleared[udg_Bounty__Recursion]=false
set udg_Bounty__Recursion=udg_Bounty__Recursion-1
return null //If the state is not valid, the process stop
endif
if udg_Bounty==0 and not udg_BountyShowNothing then
set udg_BountyShow=false
set udg_BountyShowEffect=false
endif
call AdjustPlayerStateSimpleBJ(udg_BountyPlayer,state,udg_Bounty)
if udg_BountyColor==null then
if udg_BountyPlayerState=="gold" then
set udg_BountyColor=udg_DEF_COLOR_GOLD
elseif udg_BountyPlayerState=="lumber" then
set udg_BountyColor=udg_DEF_COLOR_LUMBER
endif
endif
if udg_BountyLocPos!=null then
set udg_BountyPosX=GetLocationX(udg_BountyLocPos)
set udg_BountyPosY=GetLocationY(udg_BountyLocPos)
elseif udg_BountyUnitPos!=null then
set udg_BountyPosX=GetUnitX(udg_BountyUnitPos)
set udg_BountyPosY=GetUnitY(udg_BountyUnitPos)
else
set udg_BountyShow=false
set udg_BountyShowEffect=false //If there is no position to the text, the text and the effect won't show
endif
set udg_BountyTextTag=CreateTextTag()
call SetTextTagPermanent(udg_BountyTextTag,udg_BountyPermanent)
call SetTextTagText(udg_BountyTextTag,"|cff"+udg_BountyColor+Bounty__Sign(udg_Bounty)+I2S(udg_Bounty)+"|r",TextTagSize2Height(udg_BountySize))
call SetTextTagVisibility(udg_BountyTextTag,IsPlayerInForce(udg_LocalPlayer,udg_BountyWhoSee) and udg_BountyShow)
call SetTextTagPos(udg_BountyTextTag,udg_BountyPosX,udg_BountyPosY,udg_BountyHeight)
call SetTextTagFadepoint(udg_BountyTextTag,udg_BountyFadePoint)
call SetTextTagLifespan(udg_BountyTextTag,udg_BountyLifeSpan)
call SetTextTagVelocityBJ(udg_BountyTextTag,udg_BountySpeed,udg_BountyDirection)
call SetTextTagAge(udg_BountyTextTag,udg_BountyAge)
if udg_BountyShowEffect then
call DestroyEffect(AddSpecialEffect(udg_BountyEffect,udg_BountyPosX,udg_BountyPosY))
endif
set udg_BountyEvent=0.00
set udg_BountyEvent=1.00
set tt=udg_BountyTextTag
if not udg_Bounty__Cleared[udg_Bounty__Recursion] and not udg_Bounty__ByKill[udg_Bounty__Recursion]then
call BountyClear()
set udg_Bounty__Cleared[udg_Bounty__Recursion]=false
endif
set udg_Bounty__Recursion=udg_Bounty__Recursion-1
return tt
endfunction
function Bounty__UnitBounty takes nothing returns nothing
//This is to prevent overwrite in case you add a function that kills a unit inside a trigger with the bountydead's event
local string prevColor=udg_BountyColor
local real prevSize=udg_BountySize
local real prevLifeSpan=udg_BountyLifeSpan
local real prevAge=udg_BountyAge
local real prevFadePoint=udg_BountyFadePoint
local real prevSpeed=udg_BountySpeed
local real prevDirection=udg_BountyDirection
local string prevPlayerState=udg_BountyPlayerState
local real prevHeight=udg_BountyHeight
local boolean prevShow=udg_BountyShow
local boolean prevShowNothing=udg_BountyShowNothing
local boolean prevAllowFriendFire=udg_BountyAllowFriendFire
local string prevEffect=udg_BountyEffect
local boolean prevShowEffect=udg_BountyShowEffect
local boolean prevPermanent=udg_BountyPermanent
local player prevPlayer=udg_BountyPlayer
local unit prevUnitPos=udg_BountyUnitPos
local integer prevBounty=udg_Bounty
local force prevForce=Bounty__CopyForce(udg_BountyWhoSee)
local location prevLocPos=udg_BountyLocPos
local unit prevKillingUnit=udg_BountyKillingUnit
local unit prevDyingUnit=udg_BountyDyingUnit
local boolean prevNotClear=udg_BountyNotClear
local integer prevData=udg_BountyData
call BountyClear()
set udg_BountyKillingUnit=GetKillingUnit()
set udg_BountyDyingUnit=GetDyingUnit()
set udg_Bounty=GetBountyFromUnitType(GetUnitTypeId(udg_BountyDyingUnit))
set udg_BountyPlayer=GetOwningPlayer(udg_BountyKillingUnit)
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
set udg_BountyUnitPos=udg_BountyDyingUnit
set udg_BountyDeadEvent=0.00
set udg_BountyDeadEvent=1.00
if IsUnitEnemy(udg_BountyDyingUnit,udg_BountyPlayer) or udg_BountyAllowFriendFire then
set udg_Bounty__ByKill[udg_Bounty__Recursion+1]=true
call BountyText()
set udg_Bounty__ByKill[udg_Bounty__Recursion+1]=false
endif
set udg_BountyColor=prevColor
set udg_BountySize=prevSize
set udg_BountyLifeSpan=prevLifeSpan
set udg_BountyAge=prevAge
set udg_BountyFadePoint=prevFadePoint
set udg_BountySpeed=prevSpeed
set udg_BountyDirection=prevDirection
set udg_BountyPlayerState=prevPlayerState
set udg_BountyHeight=prevHeight
set udg_BountyShow=prevShow
set udg_BountyShowNothing=prevShowNothing
set udg_BountyAllowFriendFire=prevAllowFriendFire
set udg_BountyEffect=prevEffect
set udg_BountyShowEffect=prevShowEffect
set udg_BountyPermanent=prevPermanent
set udg_BountyPlayer=prevPlayer
set udg_BountyUnitPos=prevUnitPos
set udg_Bounty=prevBounty
call ForceClear(udg_BountyWhoSee)
set udg_Bounty__ForceEnum=udg_BountyWhoSee
call ForForce(prevForce,function Bounty__ForceAddForce)
set udg_BountyLocPos=prevLocPos
set udg_BountyKillingUnit=prevKillingUnit
set udg_BountyDyingUnit=prevDyingUnit
set udg_BountyNotClear=prevNotClear
set udg_BountyData=prevData
set prevPlayer=null
set prevUnitPos=null
set prevForce=null
set prevLocPos=null
set prevKillingUnit=null
set prevDyingUnit=null
endfunction
function Bounty__UnitBountyCheck takes nothing returns boolean
return GetKillingUnit()!=null //If there is not killing unit then the process stop
endfunction
//Functions to short the Jass process
function BountyCall takes integer bounty, unit pos, player myplayer, boolean addplayer, boolean permanent returns texttag
set udg_Bounty=bounty
set udg_BountyUnitPos=pos
set udg_BountyPlayer=myplayer
if addplayer then
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
endif
set udg_BountyPermanent=permanent
return BountyText()
endfunction
function ChangeBountyPlayer takes player newPlayer, boolean removePrevious, boolean addNew returns nothing
if removePrevious then
call ForceRemovePlayer(udg_BountyWhoSee,udg_BountyPlayer)
endif
set udg_BountyPlayer=newPlayer
if addNew then
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
endif
endfunction
//The functions are runned using the triggers
function Bounty__callBounty takes nothing returns nothing
call BOUNTY(udg_BountyUnitID,udg_BountyBase,udg_BountyDice,udg_BountySides)
set udg_BountyUnitID=0
set udg_BountyBase=0
set udg_BountyDice=0
set udg_BountySides=0
endfunction
function Bounty__callBountyBase takes nothing returns nothing
call SetBountyBase(udg_BountyUnitID,udg_BountyBase)
set udg_BountyUnitID=0
set udg_BountyBase=0
endfunction
function Bounty__callBountyDice takes nothing returns nothing
call SetBountyDice(udg_BountyUnitID,udg_BountyDice)
set udg_BountyUnitID=0
set udg_BountyDice=0
endfunction
function Bounty__callBountySides takes nothing returns nothing
call SetBountySides(udg_BountyUnitID,udg_BountySides)
set udg_BountyUnitID=0
set udg_BountySides=0
endfunction
function Bounty__callBountyGet takes nothing returns nothing
set udg_Bounty=GetBountyFromUnitType(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
function Bounty__callBountyBaseGet takes nothing returns nothing
set udg_BountyBase=GetBountyBase(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
function Bounty__callBountyDiceGet takes nothing returns nothing
set udg_BountyDice=GetBountyDice(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
function Bounty__callBountySidesGet takes nothing returns nothing
set udg_BountySides=GetBountySides(udg_BountyUnitID)
set udg_BountyUnitID=0
endfunction
//The clear function doesn't run in the initialization, so I used a timer
function Bounty__InitClear takes nothing returns nothing
call TriggerExecute(gg_trg_Bounty_Set_Data)
call BountyClear()
call DestroyTimer(GetExpiredTimer())
set udg_BountyEvent=0.00
set udg_BountyEvent=2.00
set udg_BountyEvent=0.00
endfunction
function InitTrig_Bounty_Controller_Jass takes nothing returns nothing
//The trigger that runs when a unit dies
set gg_trg_Bounty_Controller_Jass=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Bounty_Controller_Jass,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(gg_trg_Bounty_Controller_Jass,Condition(function Bounty__UnitBountyCheck))
call TriggerAddAction(gg_trg_Bounty_Controller_Jass,function Bounty__UnitBounty)
//(For GUI users) The trigger that shows the text
set udg_BountyText=CreateTrigger()
call TriggerAddAction(udg_BountyText,function BountyText)
//(For GUI users) The triggers that set the default bounty of a unit
set udg_BountySet=CreateTrigger()
call TriggerAddAction(udg_BountySet,function Bounty__callBounty)
set udg_BountySetBase=CreateTrigger()
call TriggerAddAction(udg_BountySetBase,function Bounty__callBountyBase)
set udg_BountySetDice=CreateTrigger()
call TriggerAddAction(udg_BountySetDice,function Bounty__callBountyDice)
set udg_BountySetSides=CreateTrigger()
call TriggerAddAction(udg_BountySetSides,function Bounty__callBountySides)
//(For GUI users) The triggers that get the bounty values of a unit (that you set before)
set udg_BountyGet=CreateTrigger()
call TriggerAddAction(udg_BountyGet,function Bounty__callBountyGet)
set udg_BountyGetBase=CreateTrigger()
call TriggerAddAction(udg_BountyGetBase,function Bounty__callBountyBaseGet)
set udg_BountyGetDice=CreateTrigger()
call TriggerAddAction(udg_BountyGetDice,function Bounty__callBountyDiceGet)
set udg_BountyGetSides=CreateTrigger()
call TriggerAddAction(udg_BountyGetSides,function Bounty__callBountySidesGet)
//(For GUI users) to hold the values during a BountyDeadEvent or BountyEvent
set udg_BountyHold=CreateTrigger()
call TriggerAddAction(udg_BountyHold,function BountyHold)
set udg_BountyRelease=CreateTrigger()
call TriggerAddAction(udg_BountyRelease,function BountyRelease)
//(For GUI users) to clear manually the values
set udg_BountyClear=CreateTrigger()
call TriggerAddAction(udg_BountyClear,function BountyClear)
//Last details
set udg_Bounties=InitHashtable()
call Bounty__SetData()
call TimerStart(CreateTimer(),0.00,false,function Bounty__InitClear)
endfunction
function Trig_Edits_vJass_Actions takes nothing returns nothing
if GetUnitTypeId(udg_BountyDyingUnit)=='hfoo' then
set udg_BountyShowNothing=true
endif
if GetUnitTypeId(udg_BountyDyingUnit)=='hpea' then
set udg_BountyAllowFriendFire=true
set udg_Bounty=udg_Bounty*-1
endif
if udg_BountyDyingUnit==gg_unit_nrdr_0006 then
set udg_BountyPlayerState="lumber"
endif
if udg_BountyDyingUnit==gg_unit_nftk_0004 then
set udg_BountySize=20.00
endif
if udg_BountyDyingUnit==gg_unit_nfsh_0005 then
set udg_BountyColor="0000ff"
endif
if udg_BountyKillingUnit==gg_unit_Hamg_0007 then
set udg_BountyUnitPos=udg_BountyKillingUnit
endif
endfunction
//===========================================================================
function InitTrig_Edits_vJass takes nothing returns nothing
call RegisterBountyDeadEvent(function Trig_Edits_vJass_Actions)
endfunction
function Trig_Hello_vJass_Actions takes nothing returns nothing
set udg_LastCreatedTextTag=udg_BountyTextTag
set udg_TempX=udg_BountyPosX
set udg_TempY=udg_BountyPosY
set udg_TempZ=udg_BountyHeight
if udg_BountyDyingUnit==gg_unit_nspb_0017 then
call SetTextTagText(udg_BountyTextTag,"Hello!, how are you?",TextTagSize2Height(10))
endif
endfunction
//===========================================================================
function InitTrig_Hello_vJass takes nothing returns nothing
call RegisterBountyEvent(function Trig_Hello_vJass_Actions)
endfunction