//TESH.scrollpos=0
//TESH.alwaysfold=0
function HeroHasItem takes unit U, integer Item_Code returns boolean
local integer nloops=1
local integer nloopsmax=6
local item I
loop
exitwhen nloops>nloopsmax
set I=UnitItemInSlot(U,nloops)
if(GetItemTypeId(I)==Item_Code)then
return true
endif
set nloops=nloops+nloopsmax
endloop
return false
endfunction
Name | Type | is_array | initial_value |
d | real | No | |
i | integer | No | |
u | unit | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library HandleWizard initializer HW_Init
//===========================================================================
// Handle Wizard by Alain.Mark
//
// -About-
// I always use this stuff. Since this thing makes data & handle management
// easy and less confusing.
//
// -How to Use-
// SetHandleData(handle h, string label, integer data)
// -This will attach "data" to "h" with a pointer "label".
//
// GetHandleData(handle h, string label)
// -This will return the "data" of "h" that was pointed by "label". Expect 0
// to be the defualt return value.
//
// FlushHandleData(handle h, string label)
// -This will actually set the "data" of "h" pointed by "label" to 0.
//
//===========================================================================
globals
hashtable HW_Ht
integer HW_Default
endglobals
//===========================================================================
function H2I takes handle H returns integer
return GetHandleId(H)
endfunction
//===========================================================================
function S2Int takes string S returns integer
return StringHash(S)
endfunction
//===========================================================================
function SetHandleData takes handle h, string label, integer data returns nothing
call SaveInteger(HW_Ht,H2I(h),S2Int(label),data)
endfunction
//===========================================================================
function GetHandleData takes handle h, string label returns integer
return LoadInteger(HW_Ht,H2I(h),S2Int(label))
endfunction
//===========================================================================
function FlushHandleData takes handle h, string label returns nothing
call SetHandleData(h,label,HW_Default)
endfunction
//===========================================================================
// Textmacro Version
//! textmacro Extras takes NAME, TYPE
function SetHandle$NAME$ takes handle h, string label, $TYPE$ $NAME$ returns nothing
call Save$NAME$(HW_Ht,H2I(h),S2Int(label),$NAME$)
endfunction
//===========================================================================
function GetHandle$NAME$ takes handle h, string label returns $TYPE$
call Load$NAME$(HW_Ht,H2I(h),S2Int(label),$NAME$)
endfunction
//===========================================================================
function Flush$NAME$ takes handle h, string label returns nothing
call RemoveSaved$NAME$(HW_Ht,H2I(h),S2Int(label),$NAME$)
endfunction
//! endtextmacro
//===========================================================================
function HW_Init takes nothing returns nothing
set HW_Ht=InitHashtable()
set HW_Default=0
endfunction
//===========================================================================
endlibrary
//TESH.scrollpos=162
//TESH.alwaysfold=0
library DamageDetector initializer DD_Init requires HandleWizard
//===========================================================================
// Damage Detector by Alain.Mark
//
// -How to Use-
// DD_DetectDamageFor(unit U, boolean Yes)
// -This will enable/disable the damage detection for "U".
//
// DD_UseDetector(trigger TRG)
// -This will include "TRG" to the list of triggers that are fired everytime
// a damage event is detected or in other words use this if you want "TRG"
// to use this system.
//
// DD_SkipThis(trigger TRG, integer times)
// -This will make "DD_RunQueue" skip "TRG" for "times" times. This function
// has special applications (prevent chain damage).
//
// DD_DamageTarget(unit Source, unit Target, real Damage, boolean Hide)
// -This will cause "Source" to deal "Damage" to "Target". The damage will
// be hidden if "Hide" is equal to true.
//
// DD_GetDamageAmount()
// -This will return the amount of damage dealt
//
// DD_GetDamageVictim()
// -This will return the damaged unit
//
// DD_GetDamageSource
// -This will return the damaging unit
//
// DD_GetDamageMethod()
// -This will return the damage method depending on the condtion. Use
// DD_DM_ATTACK to check if the damage was dealt by an attack on the other
// hand use DD_DM_SPELL to check if the damage was dealt by a spell.
//
// NOTE: DD_DM_ATTACK is returned if the damage was NOT done using the the
// DD_DamageTarget function. DD_DamageTarget will always have a DD_DM_SPELL
// damage method. In other words if you want this system to distinguish if
// damage is dealt by an attack or by a spell, DEAL DAMAGE BY USING THE
// DD_DAMAGETARGET FUNCTION.
//
// -Credits- (Please give credits to the people below)
// Weep (I used his GDD system as a base)
//
//===========================================================================
globals // Obtainable informations are marked with //* at the end
integer DD_Instances =-1
integer DD_Held_Count =-1
integer DD_Detector_Users_Count =-1
integer DD_Free_Triggers =-1
integer DD_HELD ='held'
integer DD_DM_ATTACK ='attk' //Put a random value here
integer DD_DM_SPELL ='spll' //Put a random value here
integer DD_HIDDEN ='hddn' //Put a random value here
integer array DD_Free_Trigger_ID
integer array DD_Skips
integer array DD_Damage_Method
boolean array DD_Hidden_Damage
real array DD_Damage_Amount
unit array DD_Damage_Victim
unit array DD_Damage_Source
trigger array DD_Trigger
trigger array DD_Detector_User
endglobals
//===========================================================================
function DD_SkipThis takes trigger TRG, integer times returns nothing
local integer ID=GetHandleData(TRG,"DD_Detector_Users_ID")
set DD_Skips[ID]=times
endfunction
//===========================================================================
function DD_RunQueue takes nothing returns nothing
local integer nloops=0
local integer nloopsmax=DD_Detector_Users_Count
loop
exitwhen nloops>nloopsmax
if(DD_Skips[nloops]==0)then
call TriggerExecute(DD_Detector_User[nloops])
else
set DD_Skips[nloops]=DD_Skips[nloops]-1
endif
set nloops=nloops+1
endloop
set DD_Instances=DD_Instances-1
endfunction
//===========================================================================
function DD_Queue takes nothing returns nothing
set DD_Instances=DD_Instances+1
set DD_Damage_Amount[DD_Instances]=GetEventDamage()
set DD_Damage_Victim[DD_Instances]=GetTriggerUnit()
set DD_Damage_Source[DD_Instances]=GetEventDamageSource()
if(GetHandleData(DD_Damage_Source[DD_Instances],"DD_Damage_Method")!=DD_DM_SPELL)then
set DD_Damage_Method[DD_Instances]=DD_DM_ATTACK
else
set DD_Damage_Method[DD_Instances]=DD_DM_SPELL
endif
if(GetHandleData(DD_Damage_Source[DD_Instances],"DD_Damage_Hidden")!=DD_HIDDEN)then
set DD_Hidden_Damage[DD_Instances]=false
else
set DD_Hidden_Damage[DD_Instances]=true
endif
call DD_RunQueue()
endfunction
//===========================================================================
//! textmacro Multiple takes NAME, RETURN_TYPE
function DD_GetDamage$NAME$ takes nothing returns $RETURN_TYPE$
return DD_Damage_$NAME$[DD_Instances]
endfunction
//! endtextmacro
//! runtextmacro Multiple("Amount","real")
//! runtextmacro Multiple("Victim","unit")
//! runtextmacro Multiple("Source","unit")
//! runtextmacro Multiple("Method","integer")
//===========================================================================
function DD_IsDamageHidden takes nothing returns boolean
return DD_Hidden_Damage[DD_Instances]
endfunction
//===========================================================================
function DD_CreateTriggerFor takes unit U returns nothing
local integer ID
if(DD_Free_Triggers>=0)then
set ID=DD_Free_Trigger_ID[DD_Free_Triggers]
set DD_Free_Triggers=DD_Free_Triggers-1
else
set DD_Held_Count=DD_Held_Count+1
if(DD_Held_Count==8190)then
call BJDebugMsg("|cffff0000WARNING: <YOUR MESSAGE HERE> its impossible for a real game to reach this anyway...")
return
else
set ID=DD_Held_Count
set DD_Trigger[ID]=CreateTrigger()
endif
endif
call TriggerRegisterUnitEvent(DD_Trigger[ID],U,EVENT_UNIT_DAMAGED)
call TriggerAddAction(DD_Trigger[ID],function DD_Queue)
call SetHandleData(U,"DD_Recovery_ID",ID)
endfunction
//===========================================================================
function DD_DestroyTriggerFor takes unit U returns nothing
local integer ID=GetHandleData(U,"DD_Recovery_ID")
set DD_Free_Triggers=DD_Free_Triggers+1
set DD_Free_Trigger_ID[DD_Free_Triggers]=ID
call DestroyTrigger(DD_Trigger[ID])
set DD_Trigger[ID]=CreateTrigger()
endfunction
//===========================================================================
function DD_DetectDamageFor takes unit U, boolean Yes returns nothing
if(Yes==true)then
if(GetHandleData(U,"DD_Safety_Tag")==DD_HELD)then
call BJDebugMsg("|cffff0000WARNING:|r Holding a unit twice is dangerous and might result to a crash!")
return
else
call DD_CreateTriggerFor(U)
call SetHandleData(U,"DD_Safety_Tag",DD_HELD)
endif
else
call DD_DestroyTriggerFor(U)
call FlushHandleData(U,"DD_Safety_TAG")
endif
endfunction
//===========================================================================
function DD_UseDetector takes trigger TRG returns nothing
set DD_Detector_Users_Count=DD_Detector_Users_Count+1
set DD_Detector_User[DD_Detector_Users_Count]=TRG
call SetHandleData(TRG,"DD_Detector_Users_ID",DD_Detector_Users_Count)
endfunction
//===========================================================================
function DD_DamageTargetEx takes unit Source, unit Target, real Damage, attacktype Atk_type, damagetype Dmg_type, boolean Hide returns nothing
call SetHandleData(Source,"DD_Damage_Method",DD_DM_SPELL)
if(Hide==true)then
call SetHandleData(Source,"DD_Damage_Hidden",DD_HIDDEN)
endif
call UnitDamageTarget(Source,Target,Damage,false,false,Atk_type,Dmg_type,WEAPON_TYPE_WHOKNOWS)
endfunction
//===========================================================================
function DD_DamageTarget takes unit Source, unit Target, real Damage, boolean Hide returns nothing
call DD_DamageTargetEx(Source,Target,Damage,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,Hide)
endfunction
//===========================================================================
function DD_UseDetectorBulk takes nothing returns nothing
//use this if you want to include triggers in bulk within one function call.
call DD_UseDetector(gg_trg_Detect_Attack_Damage) //testmap only
call DD_UseDetector(gg_trg_Detect_Spell_Damage) //testmap only
call DD_UseDetector(gg_trg_Voltage_Wand) //testmap only
endfunction
//===========================================================================
function DD_Init takes nothing returns nothing
call TimerStart(CreateTimer(),0.01,false,function DD_UseDetectorBulk)
endfunction
//===========================================================================
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//===========================================================================
// Texttag Helper by Alain.Mark
//
// -About-
// I just made this for the testmap. Copy-Paste friendly again if you want
// to use it in your map too. :)
//
//===========================================================================
globals
integer TT_Ratio=4
real TT_Height=0.00575*TT_Ratio
real TT_Fadepoint=0.6125*TT_Ratio
real TT_Lifespan=0.725*TT_Ratio
real TT_Velocity=0.0078125*TT_Ratio
endglobals
//===========================================================================
function TT_Tag takes integer nPlayer, string txt, real x, real y returns nothing
local texttag tt=CreateTextTag()
call SetTextTagText(tt,txt,TT_Height)
call SetTextTagPos(tt,x-15,y,-18)
call SetTextTagPermanent(tt,false)
call SetTextTagFadepoint(tt,TT_Fadepoint)
call SetTextTagLifespan(tt,TT_Lifespan)
call SetTextTagVelocity(tt,0,TT_Velocity)
if (nPlayer==0) then
set tt=null
return
endif
if (IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS)) then
call SetTextTagVisibility(tt,false)
endif
if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_PLAYER[nPlayer-1])) then
call SetTextTagVisibility(tt,true)
endif
set tt=null
endfunction
//===========================================================================
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Detect_Attack_Damage_Actions takes nothing returns nothing
local real x
local real y
local string s
if(DD_GetDamageMethod()==DD_DM_ATTACK and DD_GetDamageAmount()!=0)then
set x=GetUnitX(DD_GetDamageVictim())
set y=GetUnitY(DD_GetDamageVictim())
set s=I2S(R2I(DD_GetDamageAmount()))
call TT_Tag(0,"|cffff0000"+s,x,y)
endif
endfunction
//===========================================================================
function InitTrig_Detect_Attack_Damage takes nothing returns nothing
set gg_trg_Detect_Attack_Damage = CreateTrigger( )
call TriggerAddAction( gg_trg_Detect_Attack_Damage, function Trig_Detect_Attack_Damage_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Detect_Spell_Damage_Actions takes nothing returns nothing
local real x
local real y
local string s
if(DD_GetDamageMethod()==DD_DM_SPELL and DD_GetDamageAmount()!=0)then
set x=GetUnitX(DD_GetDamageVictim())
set y=GetUnitY(DD_GetDamageVictim())
set s=I2S(R2I(DD_GetDamageAmount()))
call TT_Tag(0,"|cffaf19af"+s,x,y)
endif
endfunction
//===========================================================================
function InitTrig_Detect_Spell_Damage takes nothing returns nothing
set gg_trg_Detect_Spell_Damage = CreateTrigger( )
call TriggerAddAction( gg_trg_Detect_Spell_Damage, function Trig_Detect_Spell_Damage_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Psi_Axe_Actions takes nothing returns nothing
if(GetSpellAbilityId()=='A002')then
call DD_DamageTarget(GetTriggerUnit(),GetSpellTargetUnit(),100,false)
endif
endfunction
//===========================================================================
function InitTrig_Voltage_Wand takes nothing returns nothing
set gg_trg_Voltage_Wand = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Voltage_Wand, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( gg_trg_Voltage_Wand, function Trig_Psi_Axe_Actions )
endfunction