/***************************************************************************************************\
| Abilities System |
| by Vercas |
| |
| Requires: - Table |
| by Vexorian |
| |
| I made this system for my map, for making managing abilities easier but I thought other |
| people could use it as well so I uploaded it! |
| |
| Since version 2.01.a1, it has been completly rewritten and now the only reason to lag is...|
| ABILITIES PRELOADING!!! |
| You know, the crappy Warcraft 3 engine lags the first time it sees an ability on a unit... |
| So do not complain for the lag, I will fix it later! |
| |
| I've kept the old documentation trigger if you have any questions... |
| |
| |
| Application Programming Interface (API) : |
| |
| AddAbil( item ID, ability ID, boolean) -> nothing |
| This adds an item to the system; |
| Assigns an ability to an item! If the boolean is true, the ability is given when |
| the item is picked up, else when it's used. |
\***************************************************************************************************/
/**/library AbilitiesSystem initializer Init requires Table/***************************************/
globals
private Table ItemAbility // Fastest way to get the ability assigned to an item
private Table ItemUsed // 0 is true ; anything else is false... Pretty useless...
private Table AbilityItem // To be used later for backwards compatibility
private boolexpr BX
endglobals
function AddAbil takes integer it, integer abil, boolean c returns nothing
local integer i = 0
set it:ItemAbility = abil
if c then
set it:ItemUsed = 0
else
set it:ItemUsed = 1
endif
set abil:AbilityItem = it
loop
call SetPlayerAbilityAvailable( Player( i ), abil, false )
set i = i + 1
exitwhen i >= 16
endloop
endfunction
private function Action takes nothing returns nothing
local integer i = GetItemTypeId( GetManipulatedItem( ) )
call RemoveItem( GetManipulatedItem( ) )
call UnitAddAbility( GetTriggerUnit( ) , i:ItemAbility )
endfunction
private function Cond1 takes nothing returns boolean
local integer i = GetItemTypeId( GetManipulatedItem( ) )
return i:ItemAbility != 0 and i:ItemUsed == 0
endfunction
private function Cond2 takes nothing returns boolean
local integer i = GetItemTypeId( GetManipulatedItem( ) )
return i:ItemAbility != 0 and i:ItemUsed != 0
endfunction
private function BXtrue takes nothing returns boolean
return true
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger ( )
local trigger t2 = CreateTrigger ( )
local integer i = 0
set ItemAbility = Table.create ( )
set ItemUsed = Table.create ( )
set AbilityItem = Table.create ( )
set BX = Condition ( function BXtrue )
loop
call TriggerRegisterPlayerUnitEvent( t , Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, BX )
call TriggerRegisterPlayerUnitEvent( t2, Player(i), EVENT_PLAYER_UNIT_USE_ITEM , BX )
set i = i + 1
exitwhen i >= 16
endloop
call TriggerAddCondition ( t , Condition( function Cond1 ) )
call TriggerAddCondition ( t2, Condition( function Cond2 ) )
call TriggerAddAction ( t , function Action )
call TriggerAddAction ( t2, function Action )
endfunction
endlibrary