--[[*****************************************************************************
*
* RegisterNativeEvent by Bannar
* Lua version by HerlySQR
*
* Storage of trigger handles for native events.
*
******************************************************************************
*
* Important:
*
* Avoid using TriggerSleepAction within functions registered.
* Destroy native event trigger on your own responsibility.
*
******************************************************************************
*
* Core:
*
* function IsNativeEventRegistered(whichIndex,whichEvent) returns boolean
* Whether index whichIndex has already been attached to event whichEvent.
*
* function RegisterNativeEventTrigger(whichIndex,eventId) returns boolean
* Registers whichIndex within whichEvent scope and assigns new trigger handle for it.
*
* function GetIndexNativeEventTrigger(whichIndex,whichEvent) returns trigger
* Retrieves trigger handle for event whichEvent specific to provided index whichIndex.
*
* function GetNativeEventTrigger(whichEvent) returns trigger
* Retrieves trigger handle for event whichEvent.
*
*
* Custom events:
*
* function CreateNativeEvent() returns integer
* Returns unique id for new event and registers it with RegisterNativeEvent.
*
* function RegisterIndexNativeEvent(whichIndex,whichEvent,func) returns triggercondition
* Registers new event handler func for event whichEvent specific to index whichIndex.
*
* function RegisterNativeEvent(whichEvent,func) returns triggercondition
* Registers new event handler func for specified event whichEvent.
*
* function UnregisterNativeEventHandler(whichEvent,handler) returns nothing
* Unregisters specified event handler for event whichEvent. Requires Warcraft 1.30.4+.
*
*****************************************************************************]]--
do
local eventIndex=500 -- 0-499 reserved for Blizzard native events
local NativeEvent={}
LIBRARY_RegisterNativeEvent=true
function IsNativeEventRegistered(whichIndex,whichEvent)
return NativeEvent[whichEvent][whichIndex]
end
function RegisterNativeEventTrigger(whichIndex,whichEvent)
if not NativeEvent[whichEvent] then
NativeEvent[whichEvent]={}
end
if not IsNativeEventRegistered(whichIndex,whichEvent) then
NativeEvent[whichEvent][whichIndex]=CreateTrigger()
return true
end
return false
end
function GetIndexNativeEventTrigger(whichIndex,whichEvent)
return NativeEvent[whichEvent][whichIndex]
end
function GetNativeEventTrigger(whichEvent)
return GetIndexNativeEventTrigger(bj_MAX_PLAYER_SLOTS,whichEvent)
end
function CreateNativeEvent()
local eventId=eventIndex
RegisterNativeEventTrigger(bj_MAX_PLAYER_SLOTS,eventId)
eventIndex=eventIndex+1
return eventId
end
function RegisterIndexNativeEvent(whichIndex,whichEvent,func)
RegisterNativeEventTrigger(whichIndex,whichEvent)
return TriggerAddAction(GetIndexNativeEventTrigger(whichIndex,whichEvent),func)
end
function RegisterNativeEvent(whichEvent,func)
return RegisterIndexNativeEvent(bj_MAX_PLAYER_SLOTS,whichEvent,func)
end
function UnregisterNativeEventHandler(whichEvent,handler)
TriggerRemoveCondition(GetNativeEventTrigger(whichEvent), handler)
end
end
Name | Type | is_array | initial_value |
Bounties | hashtable | No | |
Bounty | integer | No | |
Bounty_Controller | trigger | 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 | |
LastCreatedTextTag | texttag | No | |
TempX | real | No | |
TempY | real | No | |
TempZ | real | No |
--[[*****************************************************************************
*
* RegisterNativeEvent by Bannar
* Lua version by HerlySQR
*
* Storage of trigger handles for native events.
*
******************************************************************************
*
* Important:
*
* Avoid using TriggerSleepAction within functions registered.
* Destroy native event trigger on your own responsibility.
*
******************************************************************************
*
* Core:
*
* function IsNativeEventRegistered(whichIndex,whichEvent) returns boolean
* Whether index whichIndex has already been attached to event whichEvent.
*
* function RegisterNativeEventTrigger(whichIndex,eventId) returns boolean
* Registers whichIndex within whichEvent scope and assigns new trigger handle for it.
*
* function GetIndexNativeEventTrigger(whichIndex,whichEvent) returns trigger
* Retrieves trigger handle for event whichEvent specific to provided index whichIndex.
*
* function GetNativeEventTrigger(whichEvent) returns trigger
* Retrieves trigger handle for event whichEvent.
*
*
* Custom events:
*
* function CreateNativeEvent() returns integer
* Returns unique id for new event and registers it with RegisterNativeEvent.
*
* function RegisterIndexNativeEvent(whichIndex,whichEvent,func) returns triggercondition
* Registers new event handler func for event whichEvent specific to index whichIndex.
*
* function RegisterNativeEvent(whichEvent,func) returns triggercondition
* Registers new event handler func for specified event whichEvent.
*
* function UnregisterNativeEventHandler(whichEvent,handler) returns nothing
* Unregisters specified event handler for event whichEvent. Requires Warcraft 1.30.4+.
*
*****************************************************************************]]--
do
local eventIndex=500 -- 0-499 reserved for Blizzard native events
local NativeEvent={}
LIBRARY_RegisterNativeEvent=true
function IsNativeEventRegistered(whichIndex,whichEvent)
return NativeEvent[whichEvent][whichIndex]
end
function RegisterNativeEventTrigger(whichIndex,whichEvent)
if not NativeEvent[whichEvent] then
NativeEvent[whichEvent]={}
end
if not IsNativeEventRegistered(whichIndex,whichEvent) then
NativeEvent[whichEvent][whichIndex]=CreateTrigger()
return true
end
return false
end
function GetIndexNativeEventTrigger(whichIndex,whichEvent)
return NativeEvent[whichEvent][whichIndex]
end
function GetNativeEventTrigger(whichEvent)
return GetIndexNativeEventTrigger(bj_MAX_PLAYER_SLOTS,whichEvent)
end
function CreateNativeEvent()
local eventId=eventIndex
RegisterNativeEventTrigger(bj_MAX_PLAYER_SLOTS,eventId)
eventIndex=eventIndex+1
return eventId
end
function RegisterIndexNativeEvent(whichIndex,whichEvent,func)
RegisterNativeEventTrigger(whichIndex,whichEvent)
return TriggerAddAction(GetIndexNativeEventTrigger(whichIndex,whichEvent),func)
end
function RegisterNativeEvent(whichEvent,func)
return RegisterIndexNativeEvent(bj_MAX_PLAYER_SLOTS,whichEvent,func)
end
function UnregisterNativeEventHandler(whichEvent,handler)
TriggerRemoveCondition(GetNativeEventTrigger(whichEvent), handler)
end
end
--[[
********************************************************************************************************
**************************************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 wanna set the default value of the bounty of the units you must use these functions (you can use Map Initialization):
SetBountyBase("FourCC("ID of the unit")","Bounty: Base")
SetBountyDice("FourCC("ID of the unit")","Bounty: Number of dice")
SetBountySides("FourCC("ID of the unit")","Bounty: Sides per dice")
or to do it all in once use this function:
BOUNTY("FourCC("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("FourCC("ID of the unit")")
to get the individual values of the bounty use these functions:
GetBountyBase("FourCC("ID of the unit")")
GetBountyDice("FourCC("ID of the unit")")
GetBountySides("FourCC("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).
"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, 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 previous 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 Lua 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 Lua 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 Lua you can use the function ChangeBountyPlayer(newPlayer,removePrevious,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 Lua BountyText()
But in Lua you can use the function BountyCall(bounty,unitpos,bountyPlayer,addplayer,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 Temp=BountyText() or Temp=BountyCall(<stuff>).
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 "local" before of it in the variables section.
If you wanna deactive the system do "Trigger - Turn off Bounty_Controller"
You can use the functions
RegisterBountyDeadEvent(func)
RegisterBountyEvent(func)
To replace
mytrigger=CreateTrigger()
TriggerRegisterVariableEvent(mytrigger,"udg_BountyDeadEvent",EQUAL,1.00)
TriggerAddAction(mytrigger,Actions)
For
RegisterBountyDeadEvent(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()
=====================================================================================================
]]
do
local Bounties={[0]={},[1]={},[2]={}}
--[[local]] LocalPlayer=nil
--This "constants" can be edited (obviously only valid values)
local DEF_COLOR_GOLD="ffcc00"
local DEF_COLOR_LUMBER="32cd32"
local DEF_SIZE=10
local DEF_LIFE_SPAN=3.50
local DEF_AGE=0.00
local DEF_SPEED=64
local DEF_DIRECTION=90
local DEF_FADE_POINT=2.50
local DEF_STATE="gold"
local DEF_HEIGHT=0
local DEF_SHOW=true
local DEF_SHOW_NOTHING=false
local DEF_ALLOW_FRIEND_FIRE=false
local DEF_EFFECT="UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
local DEF_SHOW_EFFECT=true
local DEF_PERMANENT=false
local LIMIT_RECURSION=16 --If a loop caused by recursion is doing in porpouse you can edit the tolerance of how many calls can do
--The functions to set the bounty stats
function SetBountyBase(id,base) Bounties[0][id]=base end
function SetBountyDice(id,dice) Bounties[1][id]=dice end
function SetBountySides(id,sides) Bounties[2][id]=sides end
function BOUNTY(id,base,dice,side)
SetBountyBase(id,base)
SetBountyDice(id,dice)
SetBountySides(id,side)
end
--The functions to get the bounty stats (that you set before)
function GetBountyBase(id)
if Bounties[0][id] then
return Bounties[0][id]
end
return 0
end
function GetBountyDice(id)
if Bounties[1][id] then
return Bounties[1][id]
end
return 0
end
function GetBountySides(id)
if Bounties[2][id] then
return Bounties[2][id]
end
return 0
end
function GetBountyFromUnitType(id)
return GetBountyBase(id)+GetRandomInt(0,GetBountyDice(id)*GetBountySides(id))
end
--This function is runned at the map initialization, if you wanna use it to set your bounties, you can do it
local function SetData()
--[[Peasant]] BOUNTY(FourCC("hpea"),35,6,3)
for i=0,PLAYER_NEUTRAL_AGGRESSIVE do
SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY,false,Player(i))
end
end
--To clear the data
local Cleared={}
local ByKill={}
local Recursion=0
function BountyClear()
if not udg_BountyNotClear then
udg_BountyTextTag=nil
udg_BountyColor=nil
udg_BountySize=DEF_SIZE
udg_BountyLifeSpan=DEF_LIFE_SPAN
udg_BountyAge=DEF_AGE
udg_BountyFadePoint=DEF_FADE_POINT
udg_BountySpeed=DEF_SPEED
udg_BountyDirection=DEF_DIRECTION
udg_BountyPlayerState=DEF_STATE
udg_BountyHeight=DEF_HEIGHT
udg_BountyShow=DEF_SHOW
udg_BountyShowNothing=DEF_SHOW_NOTHING
udg_BountyAllowFriendFire=DEF_ALLOW_FRIEND_FIRE
udg_BountyEffect=DEF_EFFECT
udg_BountyShowEffect=DEF_SHOW_EFFECT
udg_BountyPermanent=DEF_PERMANENT
udg_BountyPlayer=nil
udg_BountyUnitPos=nil
udg_BountyPosX=0.00
udg_BountyPosY=0.00
udg_Bounty=0
udg_BountyData=0
ForceClear(udg_BountyWhoSee)
if udg_BountyLocPos then
RemoveLocation(udg_BountyLocPos)
udg_BountyLocPos=nil
end
udg_BountyKillingUnit=nil
udg_BountyDyingUnit=nil
end
Cleared[Recursion]=true
udg_BountyNotClear=false
end
--This is to store the values of a BountyDeadEvent and BountyDeadEvent in case you wanna use the BountyText function
local function CopyForce(princ)
local f=CreateForce()
ForForce(princ,function() ForceAddPlayer(f,GetEnumPlayer()) end)
return f
end
local Holded={}
local Index=0
function BountyHold()
Index=Index+1
Holded[Index]={}
Holded[Index][0]=udg_BountyColor
Holded[Index][1]=udg_BountySize
Holded[Index][2]=udg_BountyLifeSpan
Holded[Index][3]=udg_BountyAge
Holded[Index][4]=udg_BountyFadePoint
Holded[Index][5]=udg_BountySpeed
Holded[Index][6]=udg_BountyDirection
Holded[Index][7]=udg_BountyPlayerState
Holded[Index][8]=udg_BountyHeight
Holded[Index][9]=udg_BountyShow
Holded[Index][10]=udg_BountyShowNothing
Holded[Index][11]=udg_BountyAllowFriendFire
Holded[Index][12]=udg_BountyEffect
Holded[Index][13]=udg_BountyShowEffect
Holded[Index][14]=udg_BountyPermanent
Holded[Index][15]=udg_BountyPlayer
Holded[Index][16]=udg_BountyUnitPos
Holded[Index][17]=udg_Bounty
Holded[Index][18]=CopyForce(udg_BountyWhoSee)
Holded[Index][19]=udg_BountyLocPos
Holded[Index][20]=udg_BountyKillingUnit
Holded[Index][21]=udg_BountyDyingUnit
Holded[Index][22]=udg_BountyNotClear
Holded[Index][23]=udg_BountyData
Holded[Index][24]=udg_BountyTextTag
BountyClear()
end
function BountyRelease()
udg_BountyColor=Holded[Index][0]
udg_BountySize=Holded[Index][1]
udg_BountyLifeSpan=Holded[Index][2]
udg_BountyAge=Holded[Index][3]
udg_BountyFadePoint=Holded[Index][4]
udg_BountySpeed=Holded[Index][5]
udg_BountyDirection=Holded[Index][6]
udg_BountyPlayerState=Holded[Index][7]
udg_BountyHeight=Holded[Index][8]
udg_BountyShow=Holded[Index][9]
udg_BountyShowNothing=Holded[Index][10]
udg_BountyAllowFriendFire=Holded[Index][11]
udg_BountyEffect=Holded[Index][12]
udg_BountyShowEffect=Holded[Index][13]
udg_BountyPermanent=Holded[Index][14]
udg_BountyPlayer=Holded[Index][15]
udg_BountyUnitPos=Holded[Index][16]
udg_Bounty=Holded[Index][17]
ForceClear(udg_BountyWhoSee)
ForForce(Holded[Index][18],function() ForceAddPlayer(udg_BountyWhoSee,GetEnumPlayer()) end)
DestroyForce(Holded[Index][18])
udg_BountyLocPos=Holded[Index][19]
udg_BountyKillingUnit=Holded[Index][20]
udg_BountyDyingUnit=Holded[Index][21]
udg_BountyNotClear=Holded[Index][22]
udg_BountyData=Holded[Index][23]
udg_BountyTextTag=Holded[Index][24]
Holded[Index]=nil
Index=Index-1
end
--This is to check the sign of the bounty
local function Sign(i)
if i<0 then
return ""
end
return "+"
end
--The function that runs the bounty and the texttag
function BountyText()
local tt
Recursion=Recursion+1
if Recursion>LIMIT_RECURSION then --If there is recursion that don't stop soon, the system stops automatically
print("There is a recursion with the Bounty system, check if you are not creating a infinite loop.")
BountyClear()
Cleared[Recursion]=false
Recursion=Recursion-1
return nil
end
if udg_BountyPlayerState=="gold" then
tt=PLAYER_STATE_RESOURCE_GOLD
elseif udg_BountyPlayerState=="lumber" then
tt=PLAYER_STATE_RESOURCE_LUMBER
else
if not ByKill[Recursion] then
BountyClear()
end
Cleared[Recursion]=false
Recursion=Recursion-1
return nil --If the state is not valid, the process stop
end
if udg_Bounty==0 and not udg_BountyShowNothing then
udg_BountyShow=false
udg_BountyShowEffect=false
end
AdjustPlayerStateSimpleBJ(udg_BountyPlayer,tt,udg_Bounty)
if not udg_BountyColor then
if udg_BountyPlayerState=="gold" then
udg_BountyColor=DEF_COLOR_GOLD
elseif udg_BountyPlayerState=="lumber" then
udg_BountyColor=DEF_COLOR_LUMBER
end
end
if udg_BountyLocPos then
udg_BountyPosX=GetLocationX(udg_BountyLocPos)
udg_BountyPosY=GetLocationY(udg_BountyLocPos)
elseif udg_BountyUnitPos then
udg_BountyPosX=GetUnitX(udg_BountyUnitPos)
udg_BountyPosY=GetUnitY(udg_BountyUnitPos)
else
udg_BountyShow=false
udg_BountyShowEffect=false --If there is no position to the text, the text and the effect won't show
end
udg_BountyTextTag=CreateTextTag()
SetTextTagPermanent(udg_BountyTextTag,udg_BountyPermanent)
SetTextTagText(udg_BountyTextTag,"|cff"..udg_BountyColor..Sign(udg_Bounty)..I2S(udg_Bounty).."|r",TextTagSize2Height(udg_BountySize))
SetTextTagVisibility(udg_BountyTextTag,IsPlayerInForce(LocalPlayer,udg_BountyWhoSee) and udg_BountyShow)
SetTextTagPos(udg_BountyTextTag,udg_BountyPosX,udg_BountyPosY,udg_BountyHeight)
SetTextTagFadepoint(udg_BountyTextTag,udg_BountyFadePoint)
SetTextTagLifespan(udg_BountyTextTag,udg_BountyLifeSpan)
SetTextTagVelocityBJ(udg_BountyTextTag,udg_BountySpeed,udg_BountyDirection)
SetTextTagAge(udg_BountyTextTag,udg_BountyAge)
if udg_BountyShowEffect then
DestroyEffect(AddSpecialEffect(udg_BountyEffect,udg_BountyPosX,udg_BountyPosY))
end
globals.udg_BountyEvent=0.00
globals.udg_BountyEvent=1.00
tt=udg_BountyTextTag
if not Cleared[Recursion] and not ByKill[Recursion] then
BountyClear()
end
Cleared[Recursion]=false
Recursion=Recursion-1
return tt
end
--Functions to short the Lua process
function BountyCall(bounty,pos,myplayer,addplayer,permanent)
udg_Bounty=bounty
udg_BountyUnitPos=pos
udg_BountyPlayer=myplayer
if addplayer then ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer) end
udg_BountyPermanent=permanent
return BountyText()
end
function ChangeBountyPlayer(newPlayer,removePrevious,addNew)
if removePrevious then ForceRemovePlayer(udg_BountyWhoSee,udg_BountyPlayer) end
udg_BountyPlayer=newPlayer
if addNew then ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer) end
end
--These is to register native event
local UNIT_BOUNTY_DEAD_EVENT=nil
local UNIT_BOUNTY_EVENT=nil
local t1,t2=nil,nil
function RegisterBountyDeadEvent(func)
if LIBRARY_RegisterNativeEvent then
if RegisterNativeEventTrigger(0,UNIT_BOUNTY_DEAD_EVENT) then
TriggerRegisterVariableEvent(GetIndexNativeEventTrigger(0,UNIT_BOUNTY_DEAD_EVENT),"udg_BountyDeadEvent",EQUAL,1.00)
end
RegisterIndexNativeEvent(0,UNIT_BOUNTY_DEAD_EVENT,func)
else
TriggerAddCondition(t1,Condition(func))
end
end
function GetNativeBountyDeadEventTrigger()
if LIBRARY_RegisterNativeEvent then
return GetIndexNativeEventTrigger(0,UNIT_BOUNTY_DEAD_EVENT)
else
return t1
end
end
function RegisterBountyEvent(func)
if LIBRARY_RegisterNativeEvent then
if RegisterNativeEventTrigger(0,UNIT_BOUNTY_EVENT) then
TriggerRegisterVariableEvent(GetIndexNativeEventTrigger(0,UNIT_BOUNTY_EVENT),"udg_BountyEvent",EQUAL,1.00)
end
RegisterIndexNativeEvent(0,UNIT_BOUNTY_EVENT,func)
else
TriggerAddCondition(t2,Condition(func))
end
end
function GetNativeBountyEventTrigger()
if LIBRARY_RegisterNativeEvent then
return GetIndexNativeEventTrigger(0,UNIT_BOUNTY_EVENT)
else
return t2
end
end
local oldInit = InitBlizzard
function InitBlizzard()
oldInit()
--The trigger that runs when a unit dies
udg_Bounty_Controller=CreateTrigger()
TriggerRegisterAnyUnitEventBJ(udg_Bounty_Controller,EVENT_PLAYER_UNIT_DEATH)
TriggerAddCondition(udg_Bounty_Controller,Condition(function()
return GetKillingUnit()~=nil --If there is not killing unit then the process stop
end))
TriggerAddAction(udg_Bounty_Controller,function()
--This is to prevent overwrite in case you add a function that kills a unit inside a trigger with the bountydead's event
local prevColor=udg_BountyColor
local prevSize=udg_BountySize
local prevLifeSpan=udg_BountyLifeSpan
local prevAge=udg_BountyAge
local prevFadePoint=udg_BountyFadePoint
local prevSpeed=udg_BountySpeed
local prevDirection=udg_BountyDirection
local prevPlayerState=udg_BountyPlayerState
local prevHeight=udg_BountyHeight
local prevShow=udg_BountyShow
local prevShowNothing=udg_BountyShowNothing
local prevAllowFriendFire=udg_BountyAllowFriendFire
local prevEffect=udg_BountyEffect
local prevShowEffect=udg_BountyShowEffect
local prevPermanent=udg_BountyPermanent
local prevPlayer=udg_BountyPlayer
local prevUnitPos=udg_BountyUnitPos
local prevBounty=udg_Bounty
local prevForce=CopyForce(udg_BountyWhoSee)
local prevLocPos=udg_BountyLocPos
local prevKillingUnit=udg_BountyKillingUnit
local prevDyingUnit=udg_BountyDyingUnit
local prevNotClear=udg_BountyNotClear
local prevData=udg_BountyData
udg_BountyKillingUnit=GetKillingUnit()
udg_BountyDyingUnit=GetDyingUnit()
udg_Bounty=GetBountyFromUnitType(GetUnitTypeId(udg_BountyDyingUnit))
if not udg_Bounty then udg_Bounty=0 end
udg_BountyPlayer=GetOwningPlayer(udg_BountyKillingUnit)
ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
udg_BountyUnitPos=udg_BountyDyingUnit
globals.udg_BountyDeadEvent=0.00
globals.udg_BountyDeadEvent=1.00
if IsUnitEnemy(udg_BountyDyingUnit,udg_BountyPlayer) or udg_BountyAllowFriendFire then
local i=Recursion+1
ByKill[i]=true
BountyText()
ByKill[i]=false
end
udg_BountyColor=prevColor
udg_BountySize=prevSize
udg_BountyLifeSpan=prevLifeSpan
udg_BountyAge=prevAge
udg_BountyFadePoint=prevFadePoint
udg_BountySpeed=prevSpeed
udg_BountyDirection=prevDirection
udg_BountyPlayerState=prevPlayerState
udg_BountyHeight=prevHeight
udg_BountyShow=prevShow
udg_BountyShowNothing=prevShowNothing
udg_BountyAllowFriendFire=prevAllowFriendFire
udg_BountyEffect=prevEffect
udg_BountyShowEffect=prevShowEffect
udg_BountyPermanent=prevPermanent
udg_BountyPlayer=prevPlayer
udg_BountyUnitPos=prevUnitPos
udg_Bounty=prevBounty
ForceClear(udg_BountyWhoSee)
ForForce(prevForce,function() ForceAddPlayer(udg_BountyWhoSee,GetEnumPlayer()) end)
DestroyForce(prevForce)
udg_BountyLocPos=prevLocPos
udg_BountyKillingUnit=prevKillingUnit
udg_BountyDyingUnit=prevDyingUnit
udg_BountyNotClear=prevNotClear
udg_BountyData=prevData
end)
--(For GUI users) The trigger that shows the text
udg_BountyText=CreateTrigger()
TriggerAddAction(udg_BountyText,BountyText)
--(For GUI users) The triggers that set the default bounty of a unit
udg_BountySet=CreateTrigger()
TriggerAddAction(udg_BountySet,function()
BOUNTY(udg_BountyUnitID,udg_BountyBase,udg_BountyDice,udg_BountySides)
udg_BountyUnitID,udg_BountyBase,udg_BountyDice,udg_BountySides=0,0,0,0
end)
udg_BountySetBase=CreateTrigger()
TriggerAddAction(udg_BountySetBase,function()
SetBountyBase(udg_BountyUnitID,udg_BountyBase)
udg_BountyUnitID,udg_BountyBase=0,0
end)
udg_BountySetDice=CreateTrigger()
TriggerAddAction(udg_BountySetDice,function()
SetBountyDice(udg_BountyUnitID,udg_BountyDice)
udg_BountyUnitID,udg_BountyDice=0,0
end)
udg_BountySetSides=CreateTrigger()
TriggerAddAction(udg_BountySetSides,function()
SetBountySides(udg_BountyUnitID,udg_BountySides)
udg_BountyUnitID=0
udg_BountySides=0
end)
--(For GUI users) The triggers that get the bounty values of a unit (that you set before)
udg_BountyGet=CreateTrigger()
TriggerAddAction(udg_BountyGet,function()
udg_Bounty=GetBountyFromUnitType(udg_BountyUnitID)
udg_BountyUnitID=0
end)
udg_BountyGetBase=CreateTrigger()
TriggerAddAction(udg_BountyGetBase,function()
udg_BountyBase=GetBountyBase(udg_BountyUnitID)
udg_BountyUnitID=0
end)
udg_BountyGetDice=CreateTrigger()
TriggerAddAction(udg_BountyGetDice,function()
udg_BountyDice=GetBountyDice(udg_BountyUnitID)
udg_BountyUnitID=0
end)
udg_BountyGetSides=CreateTrigger()
TriggerAddAction(udg_BountyGetSides,function()
udg_BountySides=GetBountySides(udg_BountyUnitID)
udg_BountyUnitID=0
end)
--(For GUI users) to hold the values during a BountyDeadEvent or BountyEvent
udg_BountyHold=CreateTrigger()
TriggerAddAction(udg_BountyHold,BountyHold)
udg_BountyRelease=CreateTrigger()
TriggerAddAction(udg_BountyRelease,BountyRelease)
--(For GUI users) to clear manually the values
udg_BountyClear=CreateTrigger()
TriggerAddAction(udg_BountyClear,BountyClear)
--Last details
if LIBRARY_RegisterNativeEvent then
UNIT_BOUNTY_DEAD_EVENT=CreateNativeEvent()
UNIT_BOUNTY_EVENT=CreateNativeEvent()
else
t1=CreateTrigger()
TriggerRegisterVariableEvent(t1,"udg_BountyDeadEvent",EQUAL,1.00)
t2=CreateTrigger()
TriggerRegisterVariableEvent(t2,"udg_BountyEvent",EQUAL,1.00)
end
TimerStart(CreateTimer(),0.00,false,function()
LocalPlayer=GetLocalPlayer()
SetData()
DestroyTimer(GetExpiredTimer())
end)
end
local oldGlobals=InitGlobals
function InitGlobals()
oldGlobals()
BountyClear()
end
end
function InitTrig_Edits_Lua()
RegisterBountyDeadEvent(function()
if GetUnitTypeId(udg_BountyDyingUnit)==FourCC("hfoo") then
udg_BountyShowNothing=true
end
if udg_BountyKillingUnit==gg_unit_Hamg_0007 then
udg_BountyUnitPos=udg_BountyKillingUnit
end
if GetUnitTypeId(udg_BountyDyingUnit)==FourCC("hpea") then
udg_BountyAllowFriendFire=true
udg_Bounty=udg_Bounty*-1
end
if udg_BountyDyingUnit==gg_unit_nrdr_0006 then
udg_BountyPlayerState="lumber"
end
if udg_BountyDyingUnit==gg_unit_nftk_0004 then
udg_BountySize=20.00
end
if udg_BountyDyingUnit==gg_unit_nfsh_0005 then
udg_BountyColor="0000ff"
end
end)
end
function InitTrig_Hello_Lua()
RegisterBountyEvent(function()
udg_LastCreatedTextTag=udg_BountyTextTag
udg_TempX=udg_BountyPosX
udg_TempY=udg_BountyPosY
udg_TempZ=udg_BountyHeight
if udg_BountyDyingUnit==gg_unit_nspb_0017 then
SetTextTagText(udg_BountyTextTag,"Hello!, how are you?",TextTagSize2Height(10))
end
end)
end