Hope this will be more useful then my first submission
ZINC version:
JASS:
library GetLastCastAbility uses Table, RegisterPlayerUnitEvent, UnitIndexer
/* by edo494 version 1.8d
*
*============================================================================
*
* Requires:
*
* Table by Bribe - http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
* RegisterPlayerUnitEvent by Magtheridon96 - http://www.hiveworkshop.com/forums/jass-resources-412/snippet-registerplayerunitevent-203338/
*
* UnitIndexer by Nestharus - http://www.hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*
*============================================================================
*
* This library includes:
*
* - Allows you to retrieve last cast spells ID(returns integer)
* - Allows you to retrieve last cast spells target
* - Allows you to retrieve last cast spells caster
* - Allows you to retrieve last cast spells X and Y coordiantions
* - Allows you to retrieve last cast spells ID by specific unit
* - Allows you to retrieve target of cast spell by specific unit
* - Allows you to retrieve X and Y coordinates of last cast spell by specific unit
* - Additionally this allows you to pass unit's index and returns the unit's last cast ability
*
* This also features "BAN/UNBAN" SPELL which you can add spells into it
* If units cast those spells it will not get registered.
*
* This feature can be used for things like Spell Steal for either
* not registering the spell steal(because you dont want to steal that dont you?)
* or for spells that you dont want to be spell stealed.
*
* Also if you want to catch only heros spells, there is texted if in MainBody function which
* you can use.
*
*============================================================================
*
* Issues:
* You cant register passives for instance Bash because they
* technically never fire the event Unit - a Unit starts the effect of an ability.
*
* Also if you cast spell with no target the GetLastCastAbilityX, Y and
* GetLastCastSpellTarget will return 0, 0, null
*
*============================================================================
*
* The API is:
*
* function GetLastCastAbility takes nothing returns integer
* function GetLastCastAbilityTarget takes nothing returns unit
* function GetLastCastAbilityUnit takes nothing returns unit
* function GetLastCastAbilityX takes nothing returns real
* function GetLastCastAbilityY takes nothing returns real
*
* Based on Unit:
*
* function GetUnitLastCastAbility takes unit returns integer
* function GetUnitLastCastAbilityTarget takes unit returns unit
* function GetUnitLastCastAbilityX takes unit returns real
* function GetUnitLastCastAbilityX takes unit returns real
*
* Based on Unit's index:
*
* function GetUnitLastCastAbilityById takes integer returns integer
* function GetUnitLastCastAbilityTargetById takes integer returns unit
* function GetUnitLastCastAbilityXById takes integer returns real
* function GetUnitLastCastAbilityXById takes integer returns real
*
* Ban API:
*
* function LastAbilityAddFilter takes integer returns nothing
* function LastAbilityRemoveFilter takes integer returns nothing
*
*============================================================================
*
* Change Log:
*
* 1.0 - Intial Release
*
* 1.1 - Added BanAbility
* - Added UnbanAbility
* - Added Get(Unit)LastCastAbilityX and Y
* - Changed GetLastCast***what***ByUnit to GetUnitLastCast***what***
*
* 1.2 - Added TempBanAbility function
* - Removed Get(Unit)LastCastAbility and Get(Unit)LastCastAbilityLoc
*
* 1.3 - Changed AbilityId to Ability
* - Added support for Table
*
* 1.4 - Changed Size of myTab from 0x1000000(lol this wont work anyways) to 0x200
*
* 1.5 - Resized the Table from 0x200 to 5
* - Removed TempBan function
*
* 1.6 - Changed Ban/Unban Ability to LastAbilityAddFilter/LastAbilityRemoveFilter
* - Implemented support for RegisterPlayerUnitEvent Library
* - changed Scope Initializer to Module Initializer
*
* 1.7 - Added "Deinxeding" when unit dies
*
* 1.7a - Improved speed a very little bit
*
* 1.8 - Remade the idea of GetUnitLastCastAbility
*
* 1.8a - Removed Useless stuff
* - Changed the way how the nulling variables works(Special thanks to Bribe)
*
* 1.8b - TableArray -> Table (special thanks to Yixx)
*
* 1.8b.1 - Changed how GetLastCast***what*** works(thanks to Magtheridon96)
* - Removed local unit u from Deindex function
*
* 1.8b.2 - unit lastCastAbilityUnit -> integer lastCastAbilityCaster
*
* 1.8c - Reorganized the structure of the header
* - Added GetUnitLastCast ability taking unit's index instead of actual unit
* - Changed names of textmacroes(added GetLastCastAbility_ to their name)
*
* 1.8d - removed local integer from mainbody function
*
*============================================================================
*/
globals
private integer lastCastAbilityCaster = 0
/*
* table for Filter/UnFilter
*/
private Table myTab
/*
* variables for GetUnitLastCast
*/
private integer array lastCastUnitAbility
private unit array lastCastUnitTarget
private real array lastCastUnitX
private real array lastCastUnitY
endglobals
//! textmacro GetLastCastAbility_GETLAST takes Name, RSName, RName
function GetLastCast$Name$ takes nothing returns $RSName$
return $RName$
endfunction
//! endtextmacro
//! runtextmacro GetLastCastAbility_GETLAST("Ability", "integer", "lastCastUnitAbility[lastCastAbilityCaster]")
//! runtextmacro GetLastCastAbility_GETLAST("AbilityUnit", "unit", "GetUnitById(lastCastAbilityCaster)")
//! runtextmacro GetLastCastAbility_GETLAST("AbilityTarget", "unit", "lastCastUnitTarget[lastCastAbilityCaster]")
//! runtextmacro GetLastCastAbility_GETLAST("AbilityX", "real", "lastCastUnitY[lastCastAbilityCaster]")
//! runtextmacro GetLastCastAbility_GETLAST("AbilityY", "real", "lastCastUnitY[lastCastAbilityCaster]")
//! textmacro GetLastCastAbility_GETUNITLAST takes name, return, what
function GetUnitLastCast$name$ takes unit u returns $return$
return lastCastUnit$what$[GetUnitUserData(u)]
endfunction
//! endtextmacro
//! runtextmacro GetLastCastAbility_GETUNITLAST("Ability", "integer", "Ability")
//! runtextmacro GetLastCastAbility_GETUNITLAST("X", "real", "X")
//! runtextmacro GetLastCastAbility_GETUNITLAST("Y", "real", "Y")
//! runtextmacro GetLastCastAbility_GETUNITLAST("Target", "unit", "Target")
//! textmacro GetLastCastAbility_GETUNITLASTBYID takes name, return, what
function GetUnitLastCast$name$ById takes integer index returns $return$
return lastCastUnit$what$[index]
endfunction
//! endtextmacro
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("Ability", "integer", "Ability")
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("X", "real", "X")
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("Y", "real", "Y")
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("Target", "unit", "Target")
function LastAbilityAddFilter takes integer abilcode returns nothing
set myTab[abilcode] = 1
endfunction
function LastAbilityRemoveFilter takes integer abilcode returns nothing
set myTab[abilcode] = 0
endfunction
private function MainBody takes nothing returns nothing
//if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then
if myTab[GetSpellAbilityId()] != 1 then
set lastCastAbilityCaster = GetUnitId(GetTriggerUnit())
set lastCastUnitAbility[lastCastAbilityCaster] = GetSpellAbilityId()
set lastCastUnitTarget[lastCastAbilityCaster] = GetSpellTargetUnit()
set lastCastUnitX[lastCastAbilityCaster] = GetSpellTargetX()
set lastCastUnitY[lastCastAbilityCaster] = GetSpellTargetY()
endif
//endif
endfunction
private module GetLastAbility
private static method onInit takes nothing returns nothing
/*
* for ban list
*/
set myTab = Table.create()
/*
* Registering the starts the effect of an ability to the function
*/
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function MainBody)
endmethod
endmodule
private struct GetLast
implement GetLastAbility
endstruct
//***************************************************************
//***************************************************************
//When unit dies, null the numbers
private function DiesFunc takes nothing returns boolean
local integer i = GetIndexedUnitId()
set lastCastUnitAbility[i] = 0
set lastCastUnitTarget[i] = null
set lastCastUnitX[i] = 0
set lastCastUnitY[i] = 0
return false
endfunction
//***************************************************************
private module DiesInit
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function DiesFunc), UnitIndexer.DEINDEX)
endmethod
endmodule
private struct DIES
implement DiesInit
endstruct
endlibrary
ZINC version:
JASS:
//! zinc
library GetLastCastAbility requires Table, RegisterPlayerUnitEvent, UnitIndexer
/* by edo494 version 1.0.a.z
*
*============================================================================
*
* Requires:
*
* Table by Bribe - http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
* RegisterPlayerUnitEvent by Magtheridon96 - http://www.hiveworkshop.com/forums/jass-resources-412/snippet-registerplayerunitevent-203338/
*
* UnitIndexer by Nestharus - http://www.hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*
*============================================================================
*
* This library includes:
*
* - Allows you to retrieve last cast spells ID(returns integer)
* - Allows you to retrieve last cast spells target
* - Allows you to retrieve last cast spells caster
* - Allows you to retrieve last cast spells X and Y coordiantions
* - Allows you to retrieve last cast spells ID by specific unit
* - Allows you to retrieve target of cast spell by specific unit
* - Allows you to retrieve X and Y coordinates of last cast spell by specific unit
* - Additionally this allows you to pass unit's index and returns the unit's last cast ability
*
* This also features "BAN/UNBAN" SPELL which you can add spells into it
* If units cast those spells it will not get registered.
*
* This feature can be used for things like Spell Steal for either
* not registering the spell steal(because you dont want to steal that dont you?)
* or for spells that you dont want to be spell stealed.
*
* Also if you want to catch only heros spells, there is texted if in MainBody function which
* you can use.
*
*============================================================================
*
* Issues:
* You cant register passives for instance Bash because they
* technically never fire the event Unit - a Unit starts the effect of an ability.
*
* Also if you cast spell with no target the GetLastCastAbilityX, Y and
* GetLastCastSpellTarget will return 0, 0, null
*
*============================================================================
*
* The API is:
*
* function GetLastCastAbility takes nothing returns integer
* function GetLastCastAbilityTarget takes nothing returns unit
* function GetLastCastAbilityUnit takes nothing returns unit
* function GetLastCastAbilityX takes nothing returns real
* function GetLastCastAbilityY takes nothing returns real
*
* Based on Unit:
*
* function GetUnitLastCastAbility takes unit returns integer
* function GetUnitLastCastAbilityTarget takes unit returns unit
* function GetUnitLastCastAbilityX takes unit returns real
* function GetUnitLastCastAbilityX takes unit returns real
*
* Based on Unit's index:
*
* function GetUnitLastCastAbilityById takes integer returns integer
* function GetUnitLastCastAbilityTargetById takes integer returns unit
* function GetUnitLastCastAbilityXById takes integer returns real
* function GetUnitLastCastAbilityXById takes integer returns real
*
* Ban API:
*
* function LastAbilityAddFilter takes integer returns nothing
* function LastAbilityRemoveFilter takes integer returns nothing
*
*============================================================================
*
* Change Log:
*
* 1.0.z - Intial Release
*
* 1.0.a.z - removed the local integer from mainbody function
*
*============================================================================
*/
{
private integer lastCastAbilityCaster = 0;
private Table myTab;
private integer lastCastUnitAbility[8192];
private unit lastCastUnitTarget[8192];
private real lastCastUnitX[8192];
private real lastCastUnitY[8192];
//! textmacro GETLAST_GetLast takes Name, RSName, RName
public function GetLastCast$Name$() -> $RSName$ { return $RName$; }
//! endtextmacro
//! runtextmacro GETLAST_GetLast("Ability", "integer", "lastCastUnitAbility[lastCastAbilityCaster]")
//! runtextmacro GETLAST_GetLast("AbilityUnit", "unit", "GetUnitById(lastCastAbilityCaster)")
//! runtextmacro GETLAST_GetLast("AbilityTarget", "unit", "lastCastUnitTarget[lastCastAbilityCaster]")
//! runtextmacro GETLAST_GetLast("AbilityX", "real", "lastCastUnitY[lastCastAbilityCaster]")
//! runtextmacro GETLAST_GetLast("AbilityY", "real", "lastCastUnitY[lastCastAbilityCaster]")
//! textmacro GETCAST_LAST_UNIT takes Name, Return, what
public function GetUnitLastCast$Name$(unit u) -> $Return$ { return lastCastUnit$what$[GetUnitUserData(u)]; }
//! endtextmacro
//! runtextmacro GETCAST_LAST_UNIT("Ability", "integer", "Ability")
//! runtextmacro GETCAST_LAST_UNIT("X", "real", "X")
//! runtextmacro GETCAST_LAST_UNIT("Y", "real", "Y")
//! runtextmacro GETCAST_LAST_UNIT("Target", "unit", "Target")
//! textmacro GetLastCastAbility_GETUNITLASTBYID takes name, return, what
public function GetUnitLastCast$name$ById(integer index) -> $return$ { return lastCastUnit$what$[index]; }
//! endtextmacro
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("Ability", "integer", "Ability")
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("X", "real", "X")
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("Y", "real", "Y")
//! runtextmacro GetLastCastAbility_GETUNITLASTBYID("Target", "unit", "Target")
public function LastAbilityAddFilter(integer abilcode) { myTab[abilcode] = 1; }
public function LastAbilityRemoveFilter(integer abilcode) { myTab[abilcode] = 0; }
function MainBody()
{
if (myTab[GetSpellAbilityId()] != 1)
{
lastCastAbilityCaster = GetUnitId(GetTriggerUnit());
lastCastUnitAbility[lastCastAbilityCaster] = GetSpellAbilityId();
lastCastUnitTarget[lastCastAbilityCaster] = GetSpellTargetUnit();
lastCastUnitX[lastCastAbilityCaster] = GetSpellTargetX();
lastCastUnitY[lastCastAbilityCaster] = GetSpellTargetY();
}
}
function DiesFunc() -> boolean
{
integer i = GetIndexedUnitId();
lastCastUnitAbility[i] = 0;
lastCastUnitTarget[i] = null;
lastCastUnitX[i] = 0;
lastCastUnitY[i] = 0;
return false;
}
function onInit()
{
myTab = Table.create();
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function MainBody);
RegisterUnitIndexEvent(Condition(function DiesFunc), UnitIndexer.DEINDEX);
}
}
//! endzinc
Last edited: