Larcenist
REP: Respect, Envy, Prosperity?
- Reaction score
- 211
What might this be?
LEET is an experience and bounty system, which does nothing more than handling the experience and bounty gain of units. Experience and bounty values are registered to unittypes, and can be changed throughout the whole game. For a more detailed list of functionality check section 3, Function List, in the main trigger's comments.
Requires:
- Jass NewGen Pack.
Pros:
- Gives the user great control over the experience and bounty in general.
- Gives the user control over things such as dynamic bounty throughout the game.
- Shouldn't be very difficult to use at all.
- It's LEET.
Cons:
- Disables all regular experience and bounty gain, which requires all unittypes that are to give experience and/or bounty to be registered (if both functionalities are to be used that is, else you can prevent this by changing global variables).
Code:
Example Usage:
And yes the test map is ridiculously plain, so I want no complaining about it .
Changelog:
- v. 1.3: Added 2 new global boolean variables, UTILIZE_EXP/BOUNTY_FUNCTIONALITY.
- v. 1.2b: Made globals N and U public for custom filter usage.
- v. 1.2: Made it possible to give bounty in an AoE, aswell as split it equally among heroes who gain bounty. Added a few functions related to bounty similar to the old experience funcions (see the function list for more info).
- v. 1.1: Made it possible to split exp equally among heroes who gain exp. Added 4 new functions:
* SetUnitTypeExpShareFlag - Shared exp or not?
* GetUnitTypeExpShareFlag - Gets the current flag of the unittype
* SetUnitTypeExpFilter - Sets a new exp filter function to the unittype.
* ResetUnitTypeExpFilter - Sets the exp filter to the default one.
- v. 1.0b: Fixed bounty text to appear over the correct unit.
- v. 1.0: Initial release.
LEET is an experience and bounty system, which does nothing more than handling the experience and bounty gain of units. Experience and bounty values are registered to unittypes, and can be changed throughout the whole game. For a more detailed list of functionality check section 3, Function List, in the main trigger's comments.
Requires:
- Jass NewGen Pack.
Pros:
- Gives the user great control over the experience and bounty in general.
- Gives the user control over things such as dynamic bounty throughout the game.
- Shouldn't be very difficult to use at all.
- It's LEET.
Cons:
- Disables all regular experience and bounty gain, which requires all unittypes that are to give experience and/or bounty to be registered (if both functionalities are to be used that is, else you can prevent this by changing global variables).
Code:
JASS:
/* Larcenist´s Enhanced Experience Trigger (LEET) v. 1.3
by Larcenist (obviously)
1) Implementation:
- Create a new trigger and name it whatever you feel like naming it, LEET for example.
- Convert the trigger to custom text. Edit > Convert to custom text.
- Copy and paste this code into your newly created trigger.
2) How to use:
- Register any unittypes that you want registered by calling the register function.
Just create a new trigger and add the calls to the init function of that one.
(Function list is located in section 3.)
- The system will now distribute the experience according to the default settings
set in the global block.
- Exp will be given by unittypes until they are unregistered (see section 3 for functions).
3) Function List:
3a) Functions without return values:
- function LEET_RegisterUnitType takes integer utype, integer exp, integer bountylb, integer bountyhb returns nothing
* utype is the unittype that is to be registered. 'hfoo' for example.
* exp is the amount of experience gained from killing a unit of this type.
* bountylb is the low bound of the bounty given.\
-- Bounty given is a random integer between lowbound and highbound
* bountyhb is the highbound of the bounty given./
- function LEET_RegisterHeroType takes integer utype returns nothing
* utype is the unittype to be registered. This is for heroes only.
- function LEET_UnregisterUnitType takes integer utype returns nothing
* utype is the unittype you wish to unregister from the experience system.
- function LEET_SetUnitTypeExp takes integer utype, integer newexp returns nothing
* utype is the unittype of which you wish to change the exp rate.
* newexp is the new amount of exp to be gained by killing a unit of this type.
- function LEET_SetUnitTypeExpFlag takes integer utype boolean flag returns nothing
* utype is the unittype of which you wish to change the flag.
* flag is a boolean that indicates whether or not the entered unittype gives
exp to all enemies of the dying unit in an AoE around it.
- function LEET_SetUnitTypeExpShareFlag takes integer utype, boolean flag returns nothing
* utype is the unittype of which you wish to change the flag.
* flag is a boolean that indicates whether or not the experience given by a unit
of entered type is equally shared between the units who gain exp.
- function LEET_SetUnitTypeExpRadius takes integer utype, real radius returns nothing
* utype is the unittype of which you wish to change the radius.
* radius is the experience AoE radius.
- function LEET_SetUnitTypeBounty takes integer utype, integer bountylb, integer bountyhb returns nothing
* utype is the unittype of which you wish to change the bounty.
* bountylb is the lowbound of the bounty given.
* bountyhb is the highbound of the bounty given.
- function LEET_SetUnitTypeBountyFlag takes integer utype, boolean flag returns nothing
* utype is the unittype of which you wish to change the flag.
* flag is a boolean that indicated whether or not the entered unittype gives
bounty to all enemies of the dying unit in an AoE around it.
- function LEET_SetUnitTypeBountyShareFlag takes integer utype, boolean flag returns nothing
* utype is the unittype of which you wish the change the flag.
* flag is a boolean that indicated whether or not given bounty is equally distributed.
- function LEET_SetUnitTypeBountyRadius takes integer utype, real radius returns nothing
* utype is the unittype of which you wish to change the radius.
* radius is the bounty AoE radius.
- function LEET_SetUnitTypeExpFilter takes integer utype, boolexpr filter returns nothing
* utype is the unittype of which you wish to change the filter.
* filter is the new filter function you wish the entered unittype should use when granting exp.
< Note that this takes a boolexpr, not code argument. So you have to add Filter(function myFunc) in the arguments.
- function LEET_SetUnitTypeBountyFilter takes integer utype, boolexpr filter returns nothing
* utype is the unittype of which you wish to change the filter.
* filter is the new filter function you wish the entered unittype should use when giving bounty.
< Note that this takes a boolexpr, not code argument. So you have to add Filter(function myFunc) in the arguments.
- function LEET_ResetUnitTypeExpFilter takes integer utype returns nothing
* utype is the unittype of which you wish to reset the filter.
< This resets any custom filter function attached to the unittype and makes it use the default one again.
- function LEET_ResetUnitTypeBountyFilter takes integer utype returns nothing
* utype is the unittype of which you wish to reset the filter.
< This resets any custom filter function attached to the unittype and makes it use the default one again.
3b) Functions with return values:
- function LEET_GetUnitTypeExp takes integer utype returns integer
* utype is the unittype of which you wish to get the current experience set to it.
> Returns the experience you´ve set to the unittype.
- function LEET_GetUnitTypeExpFlag takes integer utype returns boolean
* utype is the unittype of which you wish to get the current exp AoE flag set to it.
> Returns whether or not the unittype grants AoE experience.
- function LEET_GetUnitTypeExpShareFlag takes integer utype returns boolean
* utype is the unittype of which you wish to get the current exp share flag set to it.
> Returns whether or not the exp granted by the unittype is split equally between exp recievers.
< Note that this will return false for unittypes with the ExpFlag set to false.
- function LEET_GetUnitTypeExpRadius takes integer utype returns real
* utype is the unittype of which you wish to get the current exp radius set to it.
> Returns the Experience AoE radius you´ve set to the unittype.
< Note that this will return 0. for unittypes with the ExpFlag set to false.
- function LEET_GetUnitTypeBountyLowBound takes integer utype returns integer
* utype is the unittype of which you wish to get the current bounty lowbound set to it.
> Returns the bounty lowbound you´ve set to the unittype.
- function LEET_GetUnitTypeBountyHighBound takes integer utype returns integer
* utype is the unittype of which you wish to get the current bounty highbound set to it.
> Returns the bounty highbound you´ve set to the unittype.
- function LEET_GetUnitTypeBountyFlag takes integer utype returns boolean
* utype is the unittype of which you wish to get the current bounty AoE flag set to it.
> Returns whether or not the unittype gives AoE bounty.
- function LEET_GetUnitTypeBountyShareFlag takes integer utype returns boolean
* utype is the unittype of which you wish to get the current bounty share flag set to it.
> Returns whether or not the bounty given by the unittype is split equally among bounty recievers.
< Note that this will return false for unittypes with the BountyFlag set to false.
- function LEET_GetUnitTypeBountyRadius takes integer utype returns real
* utype is the unittype of which you wish to get the current bounty radius set to it.
> Returns the bounty AoE radius you´ve set to the unittype.
< Note that this will return 0. for unittypes with the BountyFlag set to false.
4) Credits:
- Jesus4Lyf for his rawcode hashing.
- Vexorian for his bounty texttag which I totally ripped and merged into the actions function.
5) Various Notes:
- This system disables any regular experience and bounty gain.
- In any custom filter function added, please remember to add the line "set LEET_N = LEET_N + 1"
if a unit is to be given exp/bounty. This is for the split function to work properly.
- If you wish to use the dying unit in your custom filter function, simply refer to it by using LEET_U.
*/
library LEET initializer Init
globals
//These you may mess with.
private constant boolean UTILIZE_EXP_FUNCTIONALITY = true //Should the system handle the exp given by units?
private constant boolean UTILIZE_BOUNTY_FUNCTIONALITY = true //Should the system handle the bounty given by units?
private constant boolean EXP_AOE_BY_DEFAULT = true //Should exp be given in an AoE around the dying unit by default?
private constant boolean BOUNTY_AOE_BY_DEFAULT = false //Should bounty be given in an AoE around the dying unit by default?
private constant boolean SHARED_EXP_BY_DEFAULT = false //Should exp be equally divided by units within the AoE by default?
private constant boolean SHARED_BOUNTY_BY_DEFAULT = false //Should bounty be equally divided by units within the AoE by default?
private constant real DEFAULT_EXP_RADIUS = 1000. //The default radius of the exp AoE.
private constant real DEFAULT_BOUNTY_RADIUS = 500. //The default radius of the bounty AoE.
private constant real DENY_RATE = 1. //Percentage amount of exp gained when a unit is denied (meaning an allied unit kills it instead of an enemy). 1. == 100% and so on.
//=======================================================\\
//These you may not mess with.
public integer N
public unit U
endglobals
//Function for calculating the bounty given by a hero when killed.
private function GetHeroBounty takes unit hero returns integer
return 200 + 15 * GetHeroLevel(hero)
endfunction
//Function for calculating the experience given by a hero when killed.
private function GetHeroExp takes unit hero returns integer
return 100 + 50 * GetHeroLevel(hero)
endfunction
//Default experience filter.
private function DefaultExpFilter takes nothing returns boolean
local unit u = GetFilterUnit()
local boolean bool = false
if (IsUnitEnemy(u, GetOwningPlayer(U)) == true) and (IsUnitType(u, UNIT_TYPE_HERO) == true) and (GetWidgetLife(u) > .405) then
set bool = true
set N = N + 1
endif
set u = null
return bool
endfunction
//Default bounty filter.
private function DefaultBountyFilter takes nothing returns boolean
local unit u = GetFilterUnit()
local boolean bool = false
if (IsUnitEnemy(u, GetOwningPlayer(U)) == true) and (IsUnitType(u, UNIT_TYPE_HERO) == true) and (GetWidgetLife(u) > .405) then
set bool = true
set N = N + 1
endif
set u = null
return bool
endfunction
private struct Node
integer exp
integer bountylb
integer bountyhb
boolean regd = true
boolean aoe = EXP_AOE_BY_DEFAULT
boolean baoe = BOUNTY_AOE_BY_DEFAULT
boolean expshare = SHARED_EXP_BY_DEFAULT
boolean bountyshare = SHARED_BOUNTY_BY_DEFAULT
boolexpr expfilter
boolexpr bountyfilter
real exprad = DEFAULT_EXP_RADIUS
real bountyrad = DEFAULT_BOUNTY_RADIUS
static method create takes integer exp, integer blb, integer bhb returns Node
local Node n = Node.allocate()
set n.exp = exp
set n.bountylb = blb
set n.bountyhb = bhb
set n.expfilter = Filter(function DefaultExpFilter)
set n.bountyfilter = Filter(function DefaultBountyFilter)
return n
endmethod
endstruct
globals
private constant integer HASH_NEXT=53
private constant integer MAX_HASH_VALUE=8191
private integer array HashedInt
private Node array D
private group G = CreateGroup()
private integer temp
private integer J
endglobals
private function Hash takes integer int returns integer
local integer hash=int-(int/MAX_HASH_VALUE)*MAX_HASH_VALUE
loop
exitwhen HashedInt[hash]==int
if HashedInt[hash]==0 then
set HashedInt[hash]=int
return hash
endif
set hash=hash+HASH_NEXT
if hash>=MAX_HASH_VALUE then
set hash=hash-MAX_HASH_VALUE
endif
endloop
return hash
endfunction
public function SetUnitTypeBountyFilter takes integer utype, boolexpr filter returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyfilter = filter
debug else
debug call BJDebugMsg("Cannot set the bounty filter of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeExpFilter takes integer utype, boolexpr filter returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.expfilter = filter
debug else
debug call BJDebugMsg("Cannot set the experience filter of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeBounty takes integer utype, integer bountylb, integer bountyhb returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountylb = bountylb
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyhb = bountyhb
debug else
debug call BJDebugMsg("Cannot set the bounty of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeBountyRadius takes integer utype, real radius returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyrad = radius
debug else
debug call BJDebugMsg("Cannot set the bounty radius of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeExpRadius takes integer utype, real radius returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exprad = radius
debug else
debug call BJDebugMsg("Cannot set the exp radius of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeBountyShareFlag takes integer utype, boolean flag returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyshare = flag
debug else
debug call BJDebugMsg("Cannot share bounty given of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeExpShareFlag takes integer utype, boolean flag returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.expshare = flag
debug else
debug call BJDebugMsg("Cannot share exp given of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeBountyFlag takes integer utype, boolean flag returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.baoe = flag
debug else
debug call BJDebugMsg("Cannot set the bounty area flag of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeExpFlag takes integer utype, boolean flag returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.aoe = flag
debug else
debug call BJDebugMsg("Cannot set the exp area flag of a non-registered unittype.")
endif
endfunction
public function SetUnitTypeExp takes integer utype, integer newexp returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exp = newexp
debug else
debug call BJDebugMsg("Cannot set the experience value of a non-registered unittype.")
endif
endfunction
public function GetUnitTypeBountyHighBound takes integer utype returns integer
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyhb
debug else
debug call BJDebugMsg("Cannot get the bounty highbound of a non-registered unittype.")
endif
return 0
endfunction
public function GetUnitTypeBountyLowBound takes integer utype returns integer
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountylb
debug else
debug call BJDebugMsg("Cannot get the bounty lowbound of a non-registered unittype.")
endif
return 0
endfunction
public function GetUnitTypeBountyRadius takes integer utype returns real
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) and (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.baoe) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyrad
debug else
debug call BJDebugMsg("Cannot get the radius of a unittype that is either unregistered or has the bounty area flag set to false.")
endif
return 0.
endfunction
public function GetUnitTypeExpRadius takes integer utype returns real
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) and (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.aoe) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exprad
debug else
debug call BJDebugMsg("Cannot get the radius of a unittype that is either unregistered or has the exp area flag set to false.")
endif
return 0.
endfunction
public function GetUnitTypeBountyShareFlag takes integer utype returns boolean
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) and (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.baoe) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyshare
debug else
debug call BJDebugMsg("Cannot get the bounty share flag of a unittype that is either unregistered or has the AoE flag set to false.")
endif
return false
endfunction
public function GetUnitTypeExpShareFlag takes integer utype returns boolean
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) and (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.aoe) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.expshare
debug else
debug call BJDebugMsg("Cannot get the exp share flag of a unittype that is either unregistered or has the AoE flag set to false.")
endif
return false
endfunction
public function GetUnitTypeBountyFlag takes integer utype returns boolean
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.baoe
debug else
debug call BJDebugMsg("Cannot get the area bounty flag of a non-registered unittype.")
endif
return false
endfunction
public function GetUnitTypeExpFlag takes integer utype returns boolean
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.aoe
debug else
debug call BJDebugMsg("Cannot get the area exp flag of a non-registered unittype.")
endif
return false
endfunction
public function GetUnitTypeExp takes integer utype returns integer
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
return hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exp
debug else
debug call BJDebugMsg("Cannot get the experience of a non-registered unittype.")
endif
return 0
endfunction
public function ResetUnitTypeBountyFilter takes integer utype returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyfilter = Filter(function DefaultBountyFilter)
debug else
debug call BJDebugMsg("Cannot reset the bounty filter of a non-registered unittype.")
endif
endfunction
public function ResetUnitTypeExpFilter takes integer utype returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.expfilter = Filter(function DefaultExpFilter)
debug else
debug call BJDebugMsg("Cannot reset the exp filter of a non-registered unittype.")
endif
endfunction
public function UnregisterUnitType takes integer utype returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd = false
debug else
debug call BJDebugMsg("Non-registered unittype unregistered.")
endif
endfunction
public function RegisterHeroType takes integer utype returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" /> == 0) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" /> = Node.create(0, 0, 0)
return
endif
if (not hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd = true
debug else
debug call BJDebugMsg("HeroType registered twice")
endif
endfunction
public function RegisterUnitType takes integer utype, integer exp, integer bountylb, integer bountyhb returns nothing
local integer hash = Hash(utype)
if (hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" /> == 0) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" /> = Node.create(exp, bountylb, bountyhb)
return
endif
if (not hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd) then
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exp = exp
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountylb = bountylb
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyhb = bountyhb
set hash<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd = true
debug else
debug call BJDebugMsg("UnitType registered twice.")
endif
endfunction
private function GetUnitBounty takes integer lb, integer hb returns integer
if (hb < lb) then
return GetRandomInt(hb, lb)
endif
return GetRandomInt(lb, hb)
endfunction
private function GroupCallback takes nothing returns nothing
call AddHeroXP(GetEnumUnit(), temp, true)
endfunction
private function Conditions takes nothing returns boolean
set J = Hash(GetUnitTypeId(GetTriggerUnit()))
return J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.regd
endfunction
private function BountyCallback takes nothing returns nothing
local texttag t = CreateTextTag()
local string s = "+"
local unit u = GetEnumUnit()
if (temp <= 0) then
set s = ""
else
call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + temp)
call SetTextTagText(t,s+I2S(temp),0.025)
call SetTextTagPos(t,GetUnitX(U),GetUnitY(U), 0.00)
call SetTextTagColor(t,255,220,0,255)
call SetTextTagVelocity(t,0,0.03)
if (GetLocalPlayer() == GetOwningPlayer(u)) then
call SetTextTagVisibility(t,true)
set s="UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
else
call SetTextTagVisibility(t,false)
set s=""
endif
call DestroyEffect(AddSpecialEffect(s,GetUnitX(U),GetUnitY(U)))
endif
call SetTextTagFadepoint(t,2)
call SetTextTagLifespan(t,3)
call SetTextTagPermanent(t,false)
set u = null
set t = null
endfunction
private function Actions takes nothing returns nothing
local unit u = GetKillingUnit()
local texttag t = CreateTextTag()
local player p = GetOwningPlayer(u)
local string s = "+"
local integer i
set U = GetTriggerUnit()
if (IsUnitType(U, UNIT_TYPE_HERO) == true) then
set temp = GetHeroExp(U)
set i = GetHeroBounty(U)
else
set temp = J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exp
set i = GetUnitBounty(J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountylb, J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyhb)
endif
if (IsUnitAlly(u, GetOwningPlayer(U)) == true) then
set temp = R2I(temp * DENY_RATE)
set i = 0
endif
if (UTILIZE_EXP_FUNCTIONALITY) then
if (J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.aoe) then
set N = 0
call GroupEnumUnitsInRange(G, GetUnitX(u), GetUnitY(u), J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.exprad, J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.expfilter)
if (J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.expshare) then
set temp = R2I(temp / N)
endif
call ForGroup(G, function GroupCallback)
else
call AddHeroXP(u, temp, true)
endif
endif
if (UTILIZE_BOUNTY_FUNCTIONALITY) then
if (i <= 0) then
set s = ""
else
if (J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.baoe) then
set N = 0
call GroupEnumUnitsInRange(G, GetUnitX(u), GetUnitY(u), J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyrad, J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyfilter)
if (J<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />.bountyshare) then
set temp = R2I(i / N)
else
set temp = i
endif
call ForGroup(G, function BountyCallback)
else
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) + i)
call SetTextTagText(t,s+I2S(i),0.025)
call SetTextTagPos(t,GetUnitX(U),GetUnitY(U), 0.00)
call SetTextTagColor(t,255,220,0,255)
call SetTextTagVelocity(t,0,0.03)
if (GetLocalPlayer() == p) then
call SetTextTagVisibility(t,true)
set s="UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
else
call SetTextTagVisibility(t,false)
set s=""
endif
call DestroyEffect(AddSpecialEffect(s,GetUnitX(U),GetUnitY(U)))
endif
endif
endif
call SetTextTagFadepoint(t,2)
call SetTextTagLifespan(t,3)
call SetTextTagPermanent(t,false)
set u = null
set p = null
set t = null
endfunction
private function Init takes nothing returns nothing
local trigger trig = CreateTrigger()
local integer i = 0
call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(trig, Condition(function Conditions))
call TriggerAddAction(trig, function Actions)
loop
if (GetPlayerController(Player(i)) == MAP_CONTROL_USER) and (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) and (UTILIZE_EXP_FUNCTIONALITY) then
call SetPlayerHandicapXP(Player(i), 0.)
endif
if (UTILIZE_BOUNTY_FUNCTIONALITY) then
call SetPlayerState(Player(i), PLAYER_STATE_GIVES_BOUNTY, 0)
endif
set i = i + 1
exitwhen i == 16
endloop
endfunction
endlibrary
Example Usage:
JASS:
scope ExperienceRegistry initializer Init
private function Init takes nothing returns nothing
call LEET_RegisterUnitType(039;hpea039;, 20, 10, 20) //Registers Peasants to give 20 exp, and bounty between 10 and 20.
call LEET_RegisterUnitType(039;opeo039;, 50, 10, 40) //Registers Peons to give 50 exp, and bounty between 10 and 40.
call LEET_RegisterUnitType(039;uaco039;, 100, 20, 30) //Registers Acolytes to give 100 exp, and bounty between 20 and 30.
call LEET_RegisterUnitType(039;nftr039;, 150, 20, 50) //Registers Forest Trolls to give 150 exp, and bounty between 20 and 50.
call LEET_RegisterHeroType(039;Hblm039;) //Registers the Blood Mage hero.
call LEET_RegisterHeroType(039;Hamg039;) //Registers the Archmage hero.
endfunction
endscope
And yes the test map is ridiculously plain, so I want no complaining about it .
Changelog:
- v. 1.3: Added 2 new global boolean variables, UTILIZE_EXP/BOUNTY_FUNCTIONALITY.
- v. 1.2b: Made globals N and U public for custom filter usage.
- v. 1.2: Made it possible to give bounty in an AoE, aswell as split it equally among heroes who gain bounty. Added a few functions related to bounty similar to the old experience funcions (see the function list for more info).
- v. 1.1: Made it possible to split exp equally among heroes who gain exp. Added 4 new functions:
* SetUnitTypeExpShareFlag - Shared exp or not?
* GetUnitTypeExpShareFlag - Gets the current flag of the unittype
* SetUnitTypeExpFilter - Sets a new exp filter function to the unittype.
* ResetUnitTypeExpFilter - Sets the exp filter to the default one.
- v. 1.0b: Fixed bounty text to appear over the correct unit.
- v. 1.0: Initial release.