Naga'sShadow
Ultra Cool Member
- Reaction score
- 49
I searched for a bit but didn't see one. So I made one. My question is there a more efficient way to set it up. Currently there's an if/then for every spell that can be learned, and then a short block for actually adding the spells.
This is what I'm working with now.
I'm nesting the if/then in else ifs but is that any more efficient than placing and endif followed by another if statement?
Edit: Is there a way to prevent the lag when a spell is added to a unit for the first time?
This is what I'm working with now.
I'm nesting the if/then in else ifs but is that any more efficient than placing and endif followed by another if statement?
JASS:
scope SpellSelection initializer init
globals
private constant integer DUMMY = 039;a000039; //Used as a benchmark
//Abilites in alphabetical order
private constant integer AVATAR = 039;AHav039;
private constant integer BANISH = 039;AHbn039;
private constant integer BLIZZARD = 039;AHbz039;
private constant integer HOLY_LIGHT = 039;AHhb039;
//Items in numerical order
private constant integer HOLY_STONE = 039;I000039;
private constant integer BLIZ_STONE = 039;I001039;
private constant integer AVA_STONE = 039;I002039;
private constant integer BANISH_STONE = 039;I003039;
endglobals
private function Actions takes nothing returns nothing
local unit learner = GetTriggerUnit()
local player owner = GetOwningPlayer(learner)
local integer spell = DUMMY
local boolean ult = false
//in the order I get to them
if GetItemTypeId(GetManipulatedItem()) == BLIZ_STONE then
set spell = BLIZZARD
elseif GetItemTypeId(GetManipulatedItem()) == HOLY_STONE then
set spell = HOLY_LIGHT
elseif GetItemTypeId(GetManipulatedItem()) == AVA_STONE then
set spell = AVATAR
set ult = true
elseif GetItemTypeId(GetManipulatedItem()) == BANISH_STONE then
set spell = BANISH
endif //for now ;(
if spell != DUMMY and ult == false then
if GetUnitAbilityLevel(learner, spell) == 0 then
call UnitAddAbility(learner, spell)
call UnitMakeAbilityPermanent(learner, true, spell)
call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " learned!")
elseif GetUnitAbilityLevel(learner, spell) < 20 then
call IncUnitAbilityLevel(learner, spell)
call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " is now level " + I2S(GetUnitAbilityLevel(learner, spell)) + ".")
elseif GetUnitAbilityLevel(learner, spell) == 20 then
call SimError(owner, "Max Level Reached. Refunding Skill Points.")
call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER) + 1)
endif
elseif spell !=DUMMY and ult == true then
if GetUnitAbilityLevel(learner, spell) == 0 then
call UnitAddAbility(learner, spell)
call UnitMakeAbilityPermanent(learner, true, spell)
call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " learned!")
elseif GetUnitAbilityLevel(learner, spell) < 3 then
call IncUnitAbilityLevel(learner, spell)
call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " is now level " + I2S(GetUnitAbilityLevel(learner, spell)) + ".")
elseif GetUnitAbilityLevel(learner, spell) == 3 then
call SimError(owner, "Max Level Reached. Refunding Skill Points.")
call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER) + 3)
endif
endif
set learner = null
set owner = null
endfunction
private function Conditions takes nothing returns boolean
if GetItemType(GetManipulatedItem()) == ITEM_TYPE_POWERUP then
call Actions()
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(t, Condition( function Conditions))
endfunction
endscope
Edit: Is there a way to prevent the lag when a spell is added to a unit for the first time?