[JASS] Abilities System + Buy Abilites subsystem

This bundle is marked as approved. It works and satisfies the submission rules.
A simple system for buying, acquiring and managing abilities in categories of spellbooks.

Features

  • Full MUI.
  • Performance-wise code.
  • Written in vJASS.
  • Abilities added trough items.
  • Abilities acquired moved to a category.
  • Uses spell books.
  • Buy Abilities subsystem.
  • Imported files (icons) for spell books elements icons. (Legal, shows what the system can do.)
  • Heavy documentation in the map.
  • Quests in game for a shorter description and how to use.

Requires

  • Table by Vexorian

V2.01.a1Released the completly redone version
V2.01.a2Fixed a very lame bug that allowed absolutely any unit to acquire spells, even if it did not have the Abilities ability. (lol)
Changelog

A lot of documentation in the map...

JASS:
/***************************************************************************************************\
|                                        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
Contents

Abilities System V1.04.c3 (Map)

Reviews
20:06, 17th Jun 2010 Hanky: The system is doing his job well. So I have no reason why I shouldn't approve your system.

Moderator

M

Moderator

20:06, 17th Jun 2010
Hanky:
The system is doing his job well. So I have no reason why I shouldn't approve your system.
 
Level 7
Joined
Dec 19, 2008
Messages
277
Get rid off these ugly names of functions
Trig_____Acquire_Ability_Func001Func001C

Omg...
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = udg_as_i1
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd

bjfree?? Rofl, don't lie for people, and learn,learn

Huh.... and it does not vJASS

1/5, bad code.
 
Level 15
Joined
Jul 6, 2009
Messages
888
function Trig_____Acquire_Ability_Conditions takes nothing returns boolean
if ( GetUnitAbilityLevel( GetManipulatingUnit(), A_ID) == 1 ) then
return true
endif
return false
endfunction
Can be this.
JASS:
function Trig_____Acquire_Ability_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel( GetManipulatedUnit(), A_ID ) == 1
endfunction
And the like.
JASS:
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = udg_as_i1
I believe you are just converting GUI to JASS, this is not even vJASS.

set gg_trg_____Acquire_Ability = CreateTrigger( )
Use a local trigger so it is easier to copy.
JASS:
    loop
        call TriggerRegisterPlayerUnitEvent( gg_trg_____Acquire_Ability, Player(index), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
Isn't there a BJ for that, and there is nothing wrong with the BJ.
JASS:
        if ( Trig_____Acquire_Ability_Func001Func001C() ) then
            call SetPlayerAbilityAvailable( GetOwningPlayer(GetManipulatingUnit()), udg_as_AbilityA[udg_as_ii], false )
            call UnitAddAbility( GetManipulatingUnit(), udg_as_AbilityA[udg_as_ii] )
            call RemoveItem( GetManipulatedItem() )
            return
        else
GetManipulatedUnit should be a variable maybe, and why do you call the condition, why not just put it in there.

if GetItemTypeId( BLAH BLAH ) then


DAMN! Person below me beat me to my post :D 1/5 as well, this is not a JASS system, it is a GUI system that is converted and 'BJ-FREE'.
Did you know every GUI trigger leaks 16 times?
No they don't. How come a GUI trigger I have that runs on map init doesn't leak? You probably thinking TriggerRegisterAnyUnitEventBJ leaks >.>.... no it doesn't.
 
Level 20
Joined
Dec 9, 2007
Messages
3,110
I'll update it soon.

Oh and at least a better comment...

I'm removing GUI global variables and replacing them with JASS globals, removing external functions, BJ's, global integers (bj_...) and optimizing it...

This isn't vjass, it suppose to be jass.

From what I seen, look like you make this system in GUI and then convert it to JASS.

Don't use loop index A, as far as I recall. loop index A are global variable. :p

It would bug if some moron use loop A at other trigger files with wait action. :p

At least a comment wich helped me!

Edit:
How do I make a global with array?
 
Level 15
Joined
Jul 19, 2007
Messages
613
Get rid off these ugly names of functions
Trig_____Acquire_Ability_Func001Func001C

Omg...
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = udg_as_i1
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd

bjfree?? Rofl, don't lie for people, and learn,learn

Huh.... and it does not vJASS

1/5, bad code.

when its said its bj free it means no custom BJ functions used. variables do not count since they are not any slower then any other variable. however its true that its not bj-free. BJ = Blizzard Jass and you use custom functions. still many people say its BJ free if they dont see in function name keyword BJ or Swap... so if thats the case then yea its BJ free, but in truth no.

does not use vjass?

from when jass handles:
JASS:
globals
    constant integer A_ID = 'A000' // This is the ID of the "Abilities" ability.
endglobals
//Why would I need something else?

when we are talking about this.. i dont get it why did you use GUI variables... why not just declare your own and make them private?

code is indeed fast enough but its not readable to much at least for most of people here.. well i dont have trouble with it since i am c++ coder as well and c++ is fully of this "unreadable" stuff which for c++ is naturale and readable. anyway in jass its not to fun and btw jass does not allow this:

JASS:
 local integer __cdecl

just you cant write __ without valid ASCII char...

just so u know:
JASS:
function Trig_____Use_Ability_Func001Func001Func004Func002C takes nothing returns boolean
    if ( not ( UnitHasItem(GetManipulatingUnit(), GetManipulatedItem()) == true ) ) then
        return false
    endif
    if ( not ( GetItemCharges(GetManipulatedItem()) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_____Use_Ability_Func001Func001Func004C takes nothing returns boolean
    if ( not Trig_____Use_Ability_Func001Func001Func004Func002C() ) then
        return false
    endif
    return true
endfunction

call Trig_____Use_Ability_Func001Func001Func004C()
// will stay that way... but i know that you might like if then else syntax 
//insted of single lined return... its ur system but it would be better to choose
//simple to return single line

JASS:
function Trig_____Use_Ability_Func001Func001Func004Func002C takes nothing returns boolean
    return ( GetItemCharges(GetManipulatedItem()) == 0 )
endfunction

function Trig_____Use_Ability_Func001Func001Func004C takes nothing returns boolean
    return Trig_____Use_Ability_Func001Func001Func004Func002C()
endfunction

local boolean b = Trig_____Use_Ability_Func001Func001Func004C()
// is compiled to:
local boolean b = ( GetItemCharges(GetManipulatedItem()) == 0 ) // INLINED!!

vercas said:
// Guessed right, the abilities are stored in some dirty, bloody global variables of GUI...
// For making it easyer for GUI nerds.


// As a side note...
// ~ GUI sucks ! ~

if GUI sucks then try to code from start in jass/vjass and not to do few things in GUI and then recode them a bit in jass..
 
Level 20
Joined
Dec 9, 2007
Messages
3,110
It was easier to do those two triggers in GUI, but they were EXTREMELY slow and lagging a lot when getting an ability.

Almost done... :bored:

Edit:
Done.
Better now?

Edit:
Preparing another update.
Could you, pleae, re-rate it?

Edit again:
Even more optimized.
Re-updated.

Please re-rate!
 
Last edited:
Level 11
Joined
Jul 2, 2008
Messages
601
Ehm... Am I stupid, or what? I fuc*ked up my brain trying to add ANY! spell into my spellbook, but haven't managed to do it!

Just one question - how? Just buying the spellbooks give nothing. One of them (Bash) is active, but this doesn't help me either.

Waiting for reply. =]
 
Level 17
Joined
Mar 17, 2009
Messages
1,349
As you already got alot of feedback on the scripting, there's one thing left to say:
Remove all imported material, for they're useless. Icons are never a "must" for the spell to function properly...

Although it might not seem useful to me, i think some other people might need this :)
 
Level 11
Joined
Jul 2, 2008
Messages
601
As you already got alot of feedback on the scripting, there's one thing left to say:
Remove all imported material, for they're useless. Icons are never a "must" for the spell to function properly...

Although it might not seem useful to me, i think some other people might need this :)

Well, maybe not really useful, since both of us don't work on any project (Or do you? I just dunno, but it seems, that not), but the idea is original and interesting and done well. :)
 
Level 7
Joined
Dec 19, 2008
Messages
277
These code not far away from noob-level GUI, if my comment don't help you, sorry...

But that not a real code. Make some complex system, like shop for abilities, which can be created by trigger and adding abilities to that shop. xD
 
Level 4
Joined
Jan 11, 2008
Messages
55
Can you add a function to unlearn a spell?

Also, hide spell sections that arnt being used. For example, if there are no fire spells, remove the fire spells icon.

Also class restrictions.
 
Last edited:
Just a couple of things...

First off, don't forget to null the local vars:
JASS:
    private function Init takes nothing returns nothing
    
        local trigger t  = CreateTrigger       ( )
        local trigger t2 = CreateTrigger       ( )
        
        local integer i  = 0
        ....
        set t = null
        set t2 =  null

And you don't need a boolexpr since the "null input for filters" no longer applies as of 1.24 or something:
JASS:
       // set BX = Condition                     ( function BXtrue )
        
        loop
        
            call TriggerRegisterPlayerUnitEvent( t , Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
            call TriggerRegisterPlayerUnitEvent( t2, Player(i), EVENT_PLAYER_UNIT_USE_ITEM   ,null)

So you can remove the BX and its true-condition.

Nice job otherwise. =)
 
Level 20
Joined
Dec 9, 2007
Messages
3,110
You are so lame...
I said I forgot to update it, not how to update it...

And no, you're actualy wrong.
You do not have to update the name and the screenshot has to be re-uploaded too...

This version should be fixed; please test it on all kind of units, items and abilities.
 
Level 2
Joined
Jun 24, 2010
Messages
21
We are recruiting elite war3 mappers to join in a massive project.
A contest will be held to ensure that this project will be worked on only by the best mappers all over the world. More info will be later announced to the qualified entries

To have a chance to be a part in such privilege --> contact [email protected]
 
Level 22
Joined
Feb 27, 2007
Messages
3,784
@Vercas This system has a minor error. It does not make abilities permanent after adding them to units, so they are subsequently lost upon using any morph/transformation spell. To fix this only one line needs to be added:
JASS:
    private function Action takes nothing returns nothing
        
        local integer i = GetItemTypeId( GetManipulatedItem( ) )
        call RemoveItem( GetManipulatedItem( ) )
        call UnitAddAbility( GetTriggerUnit( ) , i:ItemAbility )
        
    endfunction

//Becomes this:

    private function Action takes nothing returns nothing
        
        local integer i = GetItemTypeId( GetManipulatedItem( ) )
        call RemoveItem( GetManipulatedItem( ) )
        call UnitAddAbility( GetTriggerUnit( ) , i:ItemAbility )
        call UnitMakeAbilityPermanent(GetTriggerUnit(), true, i:ItemAbility) //<<<<<<<<<<<<<<<<        
    endfunction
@MyPad or other moderators could make this change to the resource if the author does not appear.
 
Top