Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=1
library EventManager
globals
// public data
// errors code, use for EventId
constant integer EventManagerErrorCode = StringHash("EventManagerError")
constant integer GenericErrorCode = StringHash("GenericError")
constant integer TriggerRegisteredAnyEventCode = StringHash("TriggerRegisteredAnyEvent")
constant integer TriggerUnregisteredAnyEventCode = StringHash("TriggerUnregisteredAnyEvent")
// string you can use for a GenericError
string GenericError = ""
// private data
private string EventManagerError = ""
private hashtable EventManagerHash = InitHashtable()
private integer EventIdG
private trigger RegisteringTrigger
private integer RegisteredEventId
private trigger UnregisteringTrigger
private integer UnregisteredEventId
endglobals
// returns the triggering event id
function GetEventId takes nothing returns integer
return EventIdG
endfunction
// returns the internal event manager error description
function GetEventManagerError takes nothing returns string
return EventManagerError
endfunction
// returns the registering trigger
function GetRegisteringTrigger takes nothing returns trigger
return RegisteringTrigger
endfunction
// returns the registered event
function GetRegisteredEventId takes nothing returns integer
return RegisteredEventId
endfunction
// returns the unregistering trigger
function GetUnregisteringTrigger takes nothing returns trigger
return UnregisteringTrigger
endfunction
// returns the unregistered event
function GetUnregisteredEventId takes nothing returns integer
return UnregisteredEventId
endfunction
// internal function used to execute triggered trigger
private function EnumTriggers takes nothing returns nothing
local trigger trg = LoadTriggerHandle(EventManagerHash, EventIdG, GetHandleId(GetEnumUnit()))
// check the trigger's condition
if TriggerEvaluate(trg) then
call TriggerExecute(trg)
endif
set trg = null
endfunction
// we'll return true to notify at least one handler, false if there is no handler
function TriggerCustomEvent takes integer EventId returns boolean
local group List = LoadGroupHandle(EventManagerHash, EventId, 0)
// check the List
if List == null then
return false
endif
set EventIdG = EventId
call ForGroup(List, function EnumTriggers)
set List = null
// if it's a generic error, back the string to "", to avoid bad infos next time if the string doesn't change
if EventId == GenericErrorCode then
set GenericError = ""
endif
// reset the EventId's global
set EventIdG = 0
return true
endfunction
function TriggerCustomEventString takes string Event returns boolean
return TriggerCustomEvent(StringHash(Event))
endfunction
// this function just do the triggering error easy in a single line (instead of two)
// This function is just more readable and meaningfull
function TriggerError takes string message returns boolean
set GenericError = message
return TriggerCustomEvent(GenericErrorCode)
endfunction
// register a trigger with an event, so it'll be called back when the event happens
// returns false if the trigger was already registered
function TriggerRegisterCustomEvent takes trigger whichTrigger, integer EventId returns boolean
// try to load the list
local group List = LoadGroupHandle(EventManagerHash, EventId, 0)
// check the trigger isn't already bound to the event
local unit dummy = LoadUnitHandle(EventManagerHash, EventId, GetHandleId(whichTrigger))
// the trigger is already bound to an event
if dummy != null then
set List = null
set dummy = null
return false
endif
// create the dummy now, pause and hide
set dummy = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'hpea', 0, 0, 0)
call ShowUnit(dummy, false)
call PauseUnit(dummy, true)
// if the list isn't yet created, we do this right now
if List == null then
set List = CreateGroup()
call SaveGroupHandle(EventManagerHash, EventId, 0, List)
endif
// bind the unit to the trigger
call SaveTriggerHandle(EventManagerHash, EventId, GetHandleId(dummy), whichTrigger)
// and do the opposite
call SaveUnitHandle(EventManagerHash, EventId, GetHandleId(whichTrigger), dummy)
// add the unit to the list
call GroupAddUnit(List, dummy)
// send an event to notify that a trigger registered an event
set RegisteringTrigger = whichTrigger
set RegisteredEventId = EventId
call TriggerCustomEvent(TriggerRegisteredAnyEventCode)
call TriggerCustomEventString("TriggerRegisteredEvent" + I2S(EventId))
set RegisteringTrigger = null
set RegisteredEventId = 0
// and we're done : we will retrieve the trigger easily with the dummy group when something will be triggered
// we just need to clean leaks
set List = null
set dummy = null
return true
endfunction
function TriggerRegisterCustomEventString takes trigger whichTrigger, string Event returns boolean
return TriggerRegisterCustomEvent(whichTrigger, StringHash(Event))
endfunction
// return false if something is weird or if the trigger isn't registered
// if something is weird, a EventManagerError event will be triggered
function TriggerUnregisterCustomEvent takes trigger whichTrigger, integer EventId returns boolean
local group List = LoadGroupHandle(EventManagerHash, EventId, 0)
local unit dummy = LoadUnitHandle(EventManagerHash, EventId, GetHandleId(whichTrigger))
local trigger trg = null
// check if something is weird
if List == null and dummy != null then
// notify error
set EventManagerError = "The trigger seems to be registered, but the list couldn't be found... please report"
call TriggerCustomEvent(EventManagerErrorCode)
// abort
set dummy = null
set List = null
return false
endif
// if the dummy is null, the event isn't registered : abort
if dummy == null then
set List = null
return false
endif
// the trigger and the unit must be bound to each other
set trg = LoadTriggerHandle(EventManagerHash, EventId, GetHandleId(dummy))
// check the binding
if trg != whichTrigger then
// notify error
set EventManagerError = "The trigger is bound to a unit, but the unit is not bound to the trigger... please report"
call TriggerCustomEvent(EventManagerErrorCode)
// abort
set dummy = null
set List = null
set trg = null
return false
endif
// remove the bindings
call RemoveSavedHandle(EventManagerHash, EventId, GetHandleId(dummy))
call RemoveSavedHandle(EventManagerHash, EventId, GetHandleId(trg))
// remove the unit from the list
call GroupRemoveUnit(List, dummy)
// if the list is empty, destroy it
if FirstOfGroup(List) == null then
call DestroyGroup(List)
call RemoveSavedHandle(EventManagerHash, EventId, 0)
endif
// remove the unit
call RemoveUnit(dummy)
// send an event to notify that a trigger unregistered an event
set UnregisteringTrigger = whichTrigger
set UnregisteredEventId = EventId
call TriggerCustomEvent(TriggerUnregisteredAnyEventCode)
call TriggerCustomEventString("TriggerUnregisteredAnyEvent" + I2S(EventId))
set UnregisteringTrigger = null
set UnregisteredEventId = 0
// clean leaks
set List = null
set trg = null
set dummy = null
// sucess
return true
endfunction
function TriggerUnregisterCustomEventString takes trigger whichTrigger, string Event returns boolean
return TriggerUnregisterCustomEvent(whichTrigger, StringHash(Event))
endfunction
// returns true if the trigger has registered the event, false else
function IsRegisteredEvent takes trigger whichTrigger, integer EventId returns boolean
local unit dummy = LoadUnitHandle(EventManagerHash, EventId, GetHandleId(whichTrigger))
// if the dummy isn't null, the trigger is registered for the event
if dummy != null then
set dummy = null
return true
endif
// we return false else
return false
endfunction
function IsRegisteredEventString takes trigger whichTrigger, string Event returns boolean
return IsRegisteredEvent(whichTrigger, StringHash(Event))
endfunction
// returns true if the event have registered triggers, false else
function HasRegisteredTriggers takes integer EventId returns boolean
// Get the list
local group List = LoadGroupHandle(EventManagerHash, EventId, 0)
// check the List. if there is no triggers, it shall be null
if List == null then
return false
endif
// we return false else
return false
endfunction
function HasRegisteredTriggersString takes string Event returns boolean
return HasRegisteredTriggers(StringHash(Event))
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_EventManagerErrorHandler_Actions takes nothing returns nothing
// now check the event id
if GetEventId() == EventManagerErrorCode then
call BJDebugMsg("Event Manager internal error : " + GetEventManagerError())
endif
endfunction
//===========================================================================
function InitTrig_EventManagerErrorHandler takes nothing returns nothing
set gg_trg_EventManagerErrorHandler = CreateTrigger( )
// register custom event handling
call TriggerRegisterCustomEventString(gg_trg_EventManagerErrorHandler, "EventManagerError")
call TriggerAddAction( gg_trg_EventManagerErrorHandler, function Trig_EventManagerErrorHandler_Actions )
endfunction
//TESH.scrollpos=45
//TESH.alwaysfold=0
//--------------------------------
// Welcome to the documentation
//--------------------------------
// System made by : IaMfReNcH
//
// Hope you'll find all you want
// to know here. If you don't,
// feel free to ask your questions
//--------------------------------
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
// 0 - Tips
// * You can register several events for a same trigger
// * You can register several triggers for a same event
// * This is not intended for debuging purpose only.
// You may use it in various situations, giving custom data with globals
// * If you're trigger isn't for instant use of data, you shall copy globals into locals
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
// 1 - Functions to register an event handler
// those functions enables you register an event for your trigger in the same way you would do with blizzard's ones.
function TriggerRegisterCustomEvent takes trigger whichTrigger, integer EventId returns boolean
function TriggerRegisterCustomEventString takes trigger whichTrigger, string Event returns boolean
// both functions takes the handler has the first trigger argument
// The first function takes an integer for the event id to be handled by the trigger.
// It's meant to be a constant used here. Here is a sample.
constant integer GenericErrorCode = StringHash("GenericError")
// So, it's easier to avoid clashes with names
// The second function takes a string as parameter,
// so you don't need to use a constant or cast the string yourself
// Your line will looks shorter.
// If you enable inlining, you won't loss efficiency
// the functions will return false if the trigger is already bound to the event
// Once a event is triggered, you can check the event with
function GetEventId takes nothing returns integer
// Then, you may use the triggerer's function/globals to gather data
// Whenever an event is registered, a TriggerRegisteredAnyEvent event is sent.
// here is the code :
constant integer TriggerRegisteredAnyEventCode = StringHash("TriggerRegisteredAnyEvent")
// Another specific event is sent. Register it with the following line :
TriggerRegisterCustomEventString(trigger, "TriggerRegisteredEvent" + I2S(EVENT_ID))
// you can also replayer EVENT_ID by StringHash(EVENT_NAME)
// then retrieve data with :
function GetRegisteringTrigger takes nothing returns trigger
function GetRegisteredEventId takes nothing returns integer
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
// 2 - functions to unregister an event handler
// those functions simply unregister an event for a trigger, so it won't fire when the event will be summoned again
function TriggerUnregisterCustomEvent takes trigger whichTrigger, integer EventId returns boolean
function TriggerUnregisterCustomEventString takes trigger whichTrigger, string Event returns boolean
// Those functions works same as the registering ones.
// But they'll return false if the trigger isn't bound or if an error happened
// if an error happens, an EventManagerError will be triggered. Use the function below for more details on the error
function GetEventManagerError takes nothing returns string
// an event is sent, like the one sent by TriggerRegisterCustomEvent :
constant integer TriggerRegisteredAnyEventCode = StringHash("TriggerRegisteredAnyEvent")
// special event line :
TriggerRegisterCustomEventString(trigger, "TriggerUnregisteredAnyEvent" + I2S(EVENT_ID))
// data functions :
function GetUnregisteringTrigger takes nothing returns trigger
function GetUnregisteredEventId takes nothing returns integer
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
// 3 - function to trigger an event
// those functions cause the system firing all the trigger registered with the specified event id
function TriggerCustomEvent takes integer EventId returns boolean
function TriggerCustomEventString takes string Event returns boolean
// You just give as an argument the event id/name.
// the function will return false if there is no handler for this event
// You may give your own data with globals.
// The following function will trigger a GenericError event, and put message into the string GenericError.
// It's just to trigger easily error, in one meaningful line.
function TriggerError takes string message returns boolean
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
// 4 - checking functions
// those functions allows you to check a register state
// returns true if the trigger has registered the event, false else
function IsRegisteredEvent takes trigger whichTrigger, integer EventId returns boolean
function IsRegisteredEventString takes trigger whichTrigger, string Event returns boolean
// returns true if the event have registered triggers, false else
function HasRegisteredTriggers takes integer EventId returns boolean
function HasRegisteredTriggersString takes string Event returns boolean
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GenericErrorHandler_Actions takes nothing returns nothing
// now check the event id
if GetEventId() == GenericErrorCode then
call BJDebugMsg("Generic error : " + GenericError)
endif
endfunction
//===========================================================================
function InitTrig_GenericErrorHandler takes nothing returns nothing
set gg_trg_GenericErrorHandler = CreateTrigger( )
// register the event like any other event.
call TriggerRegisterCustomEventString(gg_trg_GenericErrorHandler, "GenericError")
call TriggerAddAction( gg_trg_GenericErrorHandler, function Trig_GenericErrorHandler_Actions )
endfunction
//TESH.scrollpos=18
//TESH.alwaysfold=1
// this library records deads, kills, damages done and damages taken for EVERY units
library KillCounter initializer KillCounterInit requires EventManager
globals
// data storage
private hashtable killcounter = InitHashtable()
force array CustomAlly [12]
// total
constant integer killcounterkills = StringHash("kills")
constant integer killcounterdies = StringHash("dies")
constant integer killcounterdamages = StringHash("damages")
constant integer killcounterdamagestaken = StringHash("damagestaken")
// allied
constant integer killcounterkillsallied = StringHash("killsallied")
constant integer killcounterdiesallied = StringHash("diesallied")
constant integer killcounterdamagesallied = StringHash("damagesallied")
constant integer killcounterdamagestakenallied = StringHash("damagestakenallied")
// unallied
constant integer killcounterkillsunallied = StringHash("killsunallied")
constant integer killcounterdiesunallied = StringHash("diesunallied")
constant integer killcounterdamagesunallied = StringHash("damagesunallied")
constant integer killcounterdamagestakenunallied = StringHash("damagestakenunallied")
// events
constant integer EventUnitDamagedCode = StringHash("AnyUnitDamaged")
constant integer EventUnitKilledCode = StringHash("AnyUnitKilled")
// event data
unit killer = null
unit killed = null
unit attacker = null
unit attacked = null
real damages = 0.00
boolean allied = false
// triggers
private trigger KillCounterTrg
private trigger KillCounterDamagesTrg
private trigger KillCounterNewUnitTrg
endglobals
function GetUnitKillCount takes unit whichUnit returns integer
return LoadInteger(killcounter, GetHandleId(whichUnit), killcounterkills)
endfunction
function GetUnitDieCount takes unit whichUnit returns integer
return LoadInteger(killcounter, GetHandleId(whichUnit), killcounterdies)
endfunction
function GetUnitDamagesDealtCount takes unit whichUnit returns real
return LoadReal(killcounter, GetHandleId(whichUnit), killcounterdamages)
endfunction
function GetUnitDamagesTakenCount takes unit whichUnit returns real
return LoadReal(killcounter, GetHandleId(whichUnit), killcounterdamagestaken)
endfunction
function GetUnitAlliedKillCount takes unit whichUnit returns integer
return LoadInteger(killcounter, GetHandleId(whichUnit), killcounterkillsallied)
endfunction
function GetUnitAlliedDieCount takes unit whichUnit returns integer
return LoadInteger(killcounter, GetHandleId(whichUnit), killcounterdiesallied)
endfunction
function GetUnitAlliedDamagesDealtCount takes unit whichUnit returns real
return LoadReal(killcounter, GetHandleId(whichUnit), killcounterdamagesallied)
endfunction
function GetUnitAlliedDamagesTakenCount takes unit whichUnit returns real
return LoadReal(killcounter, GetHandleId(whichUnit), killcounterdamagestakenallied)
endfunction
function GetUnitUnalliedKillCount takes unit whichUnit returns integer
return LoadInteger(killcounter, GetHandleId(whichUnit), killcounterkillsunallied)
endfunction
function GetUnitUnalliedDieCount takes unit whichUnit returns integer
return LoadInteger(killcounter, GetHandleId(whichUnit), killcounterdiesunallied)
endfunction
function GetUnitUnalliedDamagesDealtCount takes unit whichUnit returns real
return LoadReal(killcounter, GetHandleId(whichUnit), killcounterdamagesunallied)
endfunction
function GetUnitUnalliedDamagesTakenCount takes unit whichUnit returns real
return LoadReal(killcounter, GetHandleId(whichUnit), killcounterdamagestakenunallied)
endfunction
private function Trig_KillCounterTrg_Actions takes nothing returns nothing
local integer kills = LoadInteger(killcounter, GetHandleId(GetKillingUnit()), killcounterkills)
local integer dies = LoadInteger(killcounter, GetHandleId(GetDyingUnit()), killcounterdies)
local integer killsallied = LoadInteger(killcounter, GetHandleId(GetKillingUnit()), killcounterdiesallied)
local integer diesallied = LoadInteger(killcounter, GetHandleId(GetDyingUnit()), killcounterdiesallied)
local integer killsunallied = LoadInteger(killcounter, GetHandleId(GetKillingUnit()), killcounterdiesunallied)
local integer diesunallied = LoadInteger(killcounter, GetHandleId(GetDyingUnit()), killcounterdiesunallied)
set kills = kills + 1
set dies = dies + 1
set allied = ( CustomAlly[GetPlayerId(GetOwningPlayer(GetKillingUnit()))] == null and IsUnitAlly(GetKillingUnit(), GetOwningPlayer(GetDyingUnit())) ) or ( CustomAlly[GetPlayerId(GetOwningPlayer(GetKillingUnit()))] != null and IsPlayerInForce(GetOwningPlayer(GetDyingUnit()), CustomAlly[GetPlayerId(GetOwningPlayer(GetKillingUnit()))]) )
if allied then
set killsallied = killsallied + 1
set diesallied = diesallied + 1
else
set killsunallied = killsunallied + 1
set diesunallied = diesunallied + 1
endif
call SaveInteger(killcounter, GetHandleId(GetKillingUnit()), killcounterkills, kills)
call SaveInteger(killcounter, GetHandleId(GetDyingUnit()), killcounterdies, dies)
call SaveInteger(killcounter, GetHandleId(GetKillingUnit()), killcounterkillsallied, killsallied)
call SaveInteger(killcounter, GetHandleId(GetDyingUnit()), killcounterdiesallied, diesallied)
call SaveInteger(killcounter, GetHandleId(GetKillingUnit()), killcounterkillsunallied, killsunallied)
call SaveInteger(killcounter, GetHandleId(GetDyingUnit()), killcounterdiesunallied, diesunallied)
set killer = GetKillingUnit()
set killed = GetDyingUnit()
call TriggerCustomEvent(EventUnitKilledCode)
set killer = null
set killed = null
set allied = false
endfunction
private function Trig_KillCounterDamagesTrg_Actions takes nothing returns nothing
local real damagesdealt = LoadReal(killcounter, GetHandleId(GetEventDamageSource()), killcounterdamages)
local real damagestaken = LoadReal(killcounter, GetHandleId(GetTriggerUnit()), killcounterdamagestaken)
local real damagesdealtallied = LoadReal(killcounter, GetHandleId(GetEventDamageSource()), killcounterdamagesallied)
local real damagestakenallied = LoadReal(killcounter, GetHandleId(GetTriggerUnit()), killcounterdamagestakenallied)
local real damagesdealtunallied = LoadReal(killcounter, GetHandleId(GetEventDamageSource()), killcounterdamagesunallied)
local real damagestakenunallied = LoadReal(killcounter, GetHandleId(GetTriggerUnit()), killcounterdamagestakenunallied)
set damagesdealt = damagesdealt + GetEventDamage()
set damagestaken = damagestaken + GetEventDamage()
set allied = ( CustomAlly[GetPlayerId(GetOwningPlayer(GetKillingUnit()))] == null and IsUnitAlly(GetKillingUnit(), GetOwningPlayer(GetDyingUnit())) ) or ( CustomAlly[GetPlayerId(GetOwningPlayer(GetKillingUnit()))] != null and IsPlayerInForce(GetOwningPlayer(GetDyingUnit()), CustomAlly[GetPlayerId(GetOwningPlayer(GetKillingUnit()))]) )
if allied then
set damagesdealtallied = damagesdealtallied + GetEventDamage()
set damagestakenallied = damagestakenallied + GetEventDamage()
else
set damagesdealtunallied = damagesdealtunallied + GetEventDamage()
set damagestakenunallied = damagestakenunallied + GetEventDamage()
endif
call SaveReal(killcounter, GetHandleId(GetEventDamageSource()), killcounterdamages, damagesdealt)
call SaveReal(killcounter, GetHandleId(GetTriggerUnit()), killcounterdamagestaken, damagestaken)
call SaveReal(killcounter, GetHandleId(GetEventDamageSource()), killcounterdamagesallied, damagesdealtallied)
call SaveReal(killcounter, GetHandleId(GetTriggerUnit()), killcounterdamagestakenallied, damagestakenallied)
call SaveReal(killcounter, GetHandleId(GetEventDamageSource()), killcounterdamagesunallied, damagesdealtunallied)
call SaveReal(killcounter, GetHandleId(GetTriggerUnit()), killcounterdamagestakenunallied, damagestakenunallied)
set attacker = GetEventDamageSource()
set attacked = GetTriggerUnit()
set damages = GetEventDamage()
call TriggerCustomEvent(EventUnitDamagedCode)
set attacker = null
set attacked = null
set damages = 0.00
set allied = false
endfunction
private function Trig_KillCounterNewUnitTrg_Actions takes nothing returns nothing
call TriggerRegisterUnitEvent( KillCounterDamagesTrg, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
endfunction
private function InitUnitsEvents takes nothing returns nothing
call TriggerRegisterUnitEvent( KillCounterDamagesTrg, GetEnumUnit(), EVENT_UNIT_DAMAGED )
endfunction
private function KillCounterInit takes nothing returns nothing
local group temp = GetUnitsInRectAll(bj_mapInitialPlayableArea)
set KillCounterTrg = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( KillCounterTrg, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddAction( KillCounterTrg, function Trig_KillCounterTrg_Actions )
set KillCounterDamagesTrg = CreateTrigger( )
call TriggerAddAction( KillCounterDamagesTrg, function Trig_KillCounterDamagesTrg_Actions )
set KillCounterNewUnitTrg = CreateTrigger( )
call TriggerRegisterEnterRectSimple( KillCounterNewUnitTrg, bj_mapInitialPlayableArea )
call TriggerAddAction( KillCounterNewUnitTrg, function Trig_KillCounterNewUnitTrg_Actions )
call ForGroup(temp, function InitUnitsEvents)
call DestroyGroup(temp)
set temp = null
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//--------------------------------
// Welcome to the documentation
//--------------------------------
// System made by : IaMfReNcH
//
// Hope you'll find all you want
// to know here. If you don't,
// feel free to ask your questions
//--------------------------------
// 0 - dealing with unsynchronised forces
// if for any need, you unsynchronised forces (a player see that he is co-allied with another,
// and this another see that he is an ennemy of this first player), you can tell the system
// that game's forces are not real ones, and give your in this array
force array CustomAlly [12]
// in each force of this array, you may let to null for using game's forces, or create a force
// with the player that are supposed to be the real ally of the corresponding player index in the array.
// CustomAlly[0] is the force for the red player's allys
// 1 - available functions
function GetUnitKillCount takes unit whichUnit returns integer
function GetUnitDieCount takes unit whichUnit returns integer
function GetUnitDamagesDealtCount takes unit whichUnit returns real
function GetUnitDamagesTakenCount takes unit whichUnit returns real
function GetUnitAlliedKillCount takes unit whichUnit returns integer
function GetUnitAlliedDieCount takes unit whichUnit returns integer
function GetUnitAlliedDamagesDealtCount takes unit whichUnit returns real
function GetUnitAlliedDamagesTakenCount takes unit whichUnit returns real
function GetUnitUnalliedKillCount takes unit whichUnit returns integer
function GetUnitUnalliedDieCount takes unit whichUnit returns integer
function GetUnitUnalliedDamagesDealtCount takes unit whichUnit returns real
function GetUnitUnalliedDamagesTakenCount takes unit whichUnit returns real
// those functions are explicit enough, I guess. So just remember that you can
// use them on every units. Even GetUnitDieCount can be used on normal unit, but
// it's usefull only on heros.
// 2 - Custom event
// this system triggers a custom event when ANY unit is damaged. For further informations
// watch the EventManagerDoc. Here is the constant code to register your trigger with this event
constant integer EventUnitDamagedCode = StringHash("AnyUnitDamaged")
// use one of those 2 line as you normally do to register an event
call TriggerRegisterCustomEvent(trigger, EventUnitDamagedCode)
call TriggerRegisterCustomEventString(trigger, "AnyUnitDamaged")
// Once the event is triggered by the kill counter, the event manager will fire your trigger
// after checking conditions as if it was triggered by a normal event.
// You may access those globals to gather data about the event.
unit attacker // the damage source
unit attacked // the damage target
real damages // the damages dealt
// if you have unsynchronised forces in your map, watch this boolean whenever the event fires
boolean allied
// You may also use this event if you have unsynchronised forces in your maps
constant integer EventUnitKilledCode = StringHash("AnyUnitKilled")
// use same as the AnyUnitDamaged event, with the following data
unit killer
unit killed
boolean allied
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_show_stats_Actions takes nothing returns nothing
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 2.5, GetUnitName(GetTriggerUnit()) + " has dealt " + R2S(GetUnitDamagesDealtCount(GetTriggerUnit())) + " damages and taken " + R2S(GetUnitDamagesTakenCount(GetTriggerUnit())) + " damages.")
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 2.5, GetUnitName(GetTriggerUnit()) + " has killed " + I2S(GetUnitKillCount(GetTriggerUnit())) + " ennemies and died " + I2S(GetUnitDieCount(GetTriggerUnit())) + " times.")
endfunction
//===========================================================================
function InitTrig_show_stats takes nothing returns nothing
local integer index = 0
set gg_trg_show_stats = CreateTrigger( )
loop
exitwhen index > bj_MAX_PLAYERS
call TriggerRegisterPlayerUnitEvent(gg_trg_show_stats, Player(index), EVENT_PLAYER_UNIT_SELECTED, null)
set index = index + 1
endloop
call TriggerAddAction( gg_trg_show_stats, function Trig_show_stats_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
globals
constant integer CapPrecision = 200
endglobals
function Trig_damages_caps_Actions takes nothing returns nothing
// Get the cap
local integer cap = R2I(GetUnitDamagesDealtCount(attacker)/CapPrecision)*CapPrecision
// check that we just reached it. So the dealt damages before shall be lower than the cap
if GetUnitDamagesDealtCount(attacker) - damages < cap and cap > 0 then
call DisplayTimedTextToPlayer(GetOwningPlayer(attacker), 0, 0, 2.5, GetUnitName(attacker) + " has dealt more than " + I2S(cap) + " damages !")
endif
endfunction
//===========================================================================
function InitTrig_damages_caps takes nothing returns nothing
set gg_trg_damages_caps = CreateTrigger( )
call TriggerRegisterCustomEventString(gg_trg_damages_caps, "AnyUnitDamaged")
call TriggerAddAction( gg_trg_damages_caps, function Trig_damages_caps_Actions )
endfunction