System Ability From Item

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
After a lot of coding and such, I finally got this working. HUGE thanks to Rising_Dusk.

Basically you buy an item and it gives you an ability. This doesn't stick it in a spellbook, just gives the ability.
Test map computers don't buy abilities.
I took emjlr's map, credit to him for his hero selection system.

Heres how you call it.
JASS:
call AFI_SetThings(integer MySpellID, integer MyItemID, integer SpellMaxLevel, boolean IsUltimate)


JASS:
library AFI initializer Init
globals
    //User Changable
    private constant playerstate state = PLAYER_STATE_RESOURCE_LUMBER //Set to PLAYER_STATE_RESOURCE_GOLD if you want to use gold.
    private constant integer cost = 1   //Set this to the cost of the item.
    private constant integer Ulti = 6   //Set this to the level your heros are allowed to get their ultimate.
    //System Required
    private gamecache GC
    private trigger trg = CreateTrigger()
endglobals

public function FailSafe takes nothing returns boolean
    return true
endfunction

private function Cond takes nothing returns boolean
    return GetStoredInteger(GC, I2S(GetItemTypeId(GetManipulatedItem())), "AFI_AbilityKey") != 0
endfunction

public function SetThings takes integer AbID, integer ItID, integer maxlevel, boolean IsUlti returns nothing
    call StoreInteger(GC, I2S(ItID), "AFI_AbilityKey", AbID)
    call StoreInteger(GC, I2S(ItID), "AFI_MaxLevelKey", maxlevel)
    call StoreBoolean(GC, I2S(ItID), "AFI_IsUltiKey", IsUlti)
endfunction

private function AddAbil takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item i = GetManipulatedItem()
    local integer ItID = GetItemTypeId(i)
    local integer AbID = GetStoredInteger(GC, I2S(ItID), "AFI_AbilityKey")
    local integer mlvl = GetStoredInteger(GC, I2S(ItID), "AFI_MaxLevelKey")
    local integer lvl = GetUnitAbilityLevel(u, AbID)
    local boolean b = GetStoredBoolean(GC, I2S(ItID), "AFI_IsUltiKey")
    
    call RemoveItem(i)
    if b and GetHeroLevel(u) < Ulti then
        call DisplayTextToPlayer(GetOwningPlayer(u), 0.00, 0.00, "You're too low of a level. " + "You need to be level " + I2S(Ulti) + ".")
        call SetPlayerState(GetOwningPlayer(u), state, GetPlayerState(GetOwningPlayer(u), state) + cost)
    else
        if (lvl == 0) then
            call UnitAddAbility(u, AbID)
        elseif lvl == mlvl then
            call DisplayTextToPlayer(GetOwningPlayer(u), 0.00, 0.00, "Ability is maxed, nothing happened.")
            call SetPlayerState(GetOwningPlayer(u), state, GetPlayerState(GetOwningPlayer(u), state) + cost)
        else
            call SetUnitAbilityLevel(u, AbID, lvl+1)
        endif
    endif
    set u = null
    set i = null
endfunction

private function Init takes nothing returns nothing
    local integer i = 0
    call FlushGameCache(InitGameCache("GameCache.x"))
    set GC = InitGameCache("GameCache.x")
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerUnitEvent(trg,Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, Condition(function FailSafe))
        set i = i + 1
    endloop
    call TriggerAddCondition(trg, Condition(function Cond))
    call TriggerAddAction(trg, function AddAbil)
endfunction
endlibrary


Credits:
Rising_Dusk - Massive Coding Help
emjlr3 - Minor Coding Help & Test Map
phyrex1an - Minor Coding Help
SFilip - Minor Coding Help
Uberplayer - Minor Coding Help
 

Attachments

  • AbilityFromItem - emjlrs hero selection system and test map used.w3x
    81.2 KB · Views: 227

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
1) Why of all possible things you could've used, you decided to use gamecache?

2) Why would you use this system over anything else of similar use/effect?

3) What if you would want your spells levelable? Is this an upcoming feature or is it going to stay like this?
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
1. Why not? It works great.
2. Extremely easy to use.
3. You buy Spell Level 2. ;)
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
Modifying right now.

Edit:
Sorry it took so long, updating first post now.
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
Bump

Code Improvements
Better Test Map - Thanks to emjlr3
 

Tamisrah

Active Member
Reaction score
16
Looks really nice your system (=> some +rep for you :D)

There are only some suggestions:
1. Move the configuration calls (AFI_SetThings) to a seperate function, that might get messy the way it is with more abilities.

2. If Larcenist is so concerned about gamecache, which is in your case the best way to go, you could reduce the number of gamecache calls to 1 by storing a struct containing your abilitydata.

3. Replace those values for the player slots with a custom constant or the original bj_MAX_PLAYERS, because afaik you have mixed something up (once its 11 once 12?)

And last but not least don't be so shy and show your system :D, took me a while to find out which of those triggers contained the actual system
 

hasslarn

New Member
Reaction score
20
Nice system i just got one question

1.If i add this on my map and change the abillitys will it still work?
 

Flare

Stops copies me!
Reaction score
662
Interesting system, it does something similar to the skill selection in The Great Strategy/Custom Hero Line Wars.

Also, does it permanently add the ability, or just until you drop/lose the item?

Nice system i just got one question

1.If i add this on my map and change the abillitys will it still work?

I assume that is the original intention of the system ^^ Just specify your arguments and it should work :p
 
Reaction score
456
If this system is made to use gamecache, there is simply no reason to convert it to use a struct and an attachement system.

This system does not need to work a nanosecond faster.
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
Looks really nice your system (=> some +rep for you :D)

There are only some suggestions:
1. Move the configuration calls (AFI_SetThings) to a seperate function, that might get messy the way it is with more abilities.

3. Replace those values for the player slots with a custom constant or the original bj_MAX_PLAYERS, because afaik you have mixed something up (once its 11 once 12?)

1. Are you talking about scope kc in the map? Thats there for the hell of it, kinda like "why now have it there".

3. The only trigger in the test map (credit to emjlr3) is the last one. I use 11 because in Jass the players are 0 to 11.

Nice system i just got one question

1.If i add this on my map and change the abillitys will it still work?

Yes.

Interesting system, it does something similar to the skill selection in The Great Strategy/Custom Hero Line Wars.

Also, does it permanently add the ability, or just until you drop/lose the item?

JASS:

It removes the item, ability is permanent.

If this system is made to use gamecache, there is simply no reason to convert it to use a struct and an attachement system.

This system does not need to work a nanosecond faster.

Thanks. :)

Now you made this system really useful, great work.

Thanks. :)
 

Tamisrah

Active Member
Reaction score
16
I use 11 because in Jass the players are 0 to 11.
In kc Init you go to 12 im sure the exit condition is >12.

3. The only trigger in the test map (credit to emjlr3) is the last one.
What I wanted to express was, create a new category, name it AbilityFromItem System or what ever you like and put your system in there. So your system isn't just a single trigger within a bunch of triggers which all sound like they might have something to do with your system itself.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
It doesn't stop you from leveling a normal ability twice in a row.
Usually the level skip thingy is 1.
On yours you can buy:
@ lvl 1 devotion aura lvl 1
@ lvl 2 devotion aura lvl 2
@ lvl 3 devotion aura lvl 3

Shouldn't it be something like:
@ lvl 1 devotion aura lvl 1
@ lvl 3 devotion aura lvl 2
@ lvl 5 devotion aura lvl 3
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
To do something like that you would be either doing a O(n) eww, using the unit index, wasteful for this type of system, or H2I and I don't ever want to go there.
Maybe place your shop in different areas and use regions and triggers to put the unit at a certain shop.
 

Flare

Stops copies me!
Reaction score
662
Couldn't you just add a global constant (or an extra argument) that determines level skip, then check this:
Code:
Init Level Req + (New skill level - 1) * Level Skip
against the hero's level and not give the ability if hero level is lower? Not sure if you'd be able to refund the gold cost though :\

Also, what is this O(n) you speak of?
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
Its looping through an array looking for what you want, I believe.
That would work but you would need to attach an integer to the unit for that specific ability and.... blah!
:D
 

Tamisrah

Active Member
Reaction score
16
Sorry for my pertinacity but I don't like beeing told that I couldn't count.

As far as I know 12>12 is a false statement. Therefore kc_init regsiters a levelup event for
I don't argue whether playerslots start with 0 or 1 and I don't say its false the way it is I just wanted to point it out because I find it strange to create textmessages for computer players.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top