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.
Credits:
Rising_Dusk - Massive Coding Help
emjlr3 - Minor Coding Help & Test Map
phyrex1an - Minor Coding Help
SFilip - Minor Coding Help
Uberplayer - Minor Coding Help
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:
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, "You039;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