[JASS] Abilities System + Buy Abilites subsystem

Submitted by Vercas

Uploaded on 2009-07-25

Tags: System, vJASS

Filesize: 153.48 KB

Last edited on 2010-06-17

Abilities System V1.04.c3

Filesize: 153.48 KB

Filename: Abilities System V2.01.a2.w3x

Description

A simple system for buying, acquiring and managing abilities in categories of spellbooks.


Features


Requires


TABLE


A lot of documentation in the map...

The code
/***************************************************************************************************\
|                                        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


Please give credits if you use the system (Abilities System) in your map![/center

Keywords:
vercas, system, managing, manage, ability, abilities, spell, spells, skill, skills, buy, item, acquire, spellbook