Cokemonkey11
Spell Reviewer
- Joined
- May 9, 2006
- Messages
- 3,570
I'm trying to make a system that will add an ability to a unit for each level of the stack (charges) an item has.
For some reason the unit never even gets the ability.
Thanks,
For some reason the unit never even gets the ability.
JASS:
globals
constant integer JAVEITEM='I02X' //Rawcode of the javelin crew item
constant integer JAVEABIL='A01Y' //Rawcode of the javelin crew ability
endglobals
scope stackWeapSys initializer i
private function c takes nothing returns boolean
return GetItemType(GetManipulatedItem())==ITEM_TYPE_POWERUP
endfunction
private function numberOfItems takes unit u, integer itemID returns integer
local integer amt=0
local integer i=0
loop
exitwhen i>5
if GetItemTypeId(UnitItemInSlot(u,i))==itemID then
set amt=amt+1
endif
set i=i+1
endloop
return amt
endfunction
private function itemSlot takes unit u, integer itemID returns integer
local integer i=0
loop
exitwhen i>5
if GetItemTypeId(UnitItemInSlot(u,i))==itemID then
return i
endif
set i=i+1
endloop
return 0
endfunction
private function a takes nothing returns nothing
local integer iType=GetItemTypeId(GetManipulatedItem())
local item oldItem
local integer gold
local effect e
if numberOfItems(GetTriggerUnit(),iType)>1 then
call RemoveItem(GetManipulatedItem())
set oldItem=UnitItemInSlot(GetTriggerUnit(),itemSlot(GetTriggerUnit(),iType))
if GetItemCharges(oldItem)<10 then
call SetItemCharges(oldItem,GetItemCharges(oldItem)+1)
if GetItemTypeId(GetManipulatedItem())==JAVEITEM then
call UnitAddAbility(GetTriggerUnit(),JAVEABIL)
endif
set e=AddSpecialEffect("Abilities\\Spells\\Other\\Doom\\DoomTarget.mdl",GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()))
call DestroyEffect(e)
else
call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()),0,0,"You can only have 10 stacked!")
set gold=GetPlayerState(GetOwningPlayer(GetTriggerUnit()),PLAYER_STATE_RESOURCE_GOLD)
call SetPlayerState(GetOwningPlayer(GetTriggerUnit()),PLAYER_STATE_RESOURCE_GOLD,gold+R2I(GetWidgetLife(GetManipulatedItem())))
endif
else
if GetItemTypeId(GetManipulatedItem())==JAVEITEM then
call UnitAddAbility(GetTriggerUnit(),JAVEABIL)
endif
endif
endfunction
private function i takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(t,Condition(function c))
call TriggerAddAction(t,function a)
endfunction
endscope
JASS:
scope stackDropped initializer i
private function c takes nothing returns boolean
return GetItemType(GetManipulatedItem())==ITEM_TYPE_POWERUP
endfunction
private function a takes nothing returns nothing
local integer level=GetItemCharges(GetManipulatedItem())
local integer i=1
loop
exitwhen i>level
if GetItemTypeId(GetManipulatedItem())==JAVEITEM then
call UnitRemoveAbility(GetTriggerUnit(),JAVEABIL)
endif
set i=i+1
endloop
endfunction
private function i takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddCondition(t,Condition(function c))
call TriggerAddAction(t,function a)
endfunction
endscope
Thanks,