| 12-11-2007, 09:27 PM | #1 |
I'm trying to make an item that will has a chance to restore mana when a unit casts a spell. Here is the whole trigger. JASS:function Trig_Mana_Regain_Effect_Actions takes nothing returns nothing local integer random = GetRandomInt(1,100) local integer chance = 0 local unit u = GetTriggerUnit() local real mana = GetUnitState(u, UNIT_STATE_MANA) local location l = GetUnitLoc(u) local real managain local integer i = 1 loop exitwhen i > 6 if GetItemTypeId(UnitItemInSlot(u,i)) == 'I017' then set chance = 20 set managain = 50.00 endif set i = i + 1 endloop if random < chance then call SetUnitState(u, UNIT_STATE_MANA, (mana+managain)) call CreateTextTagLocBJ( ("+ " + I2S(R2I(managain)) ), OffsetLocation(l, ( I2R(StringLength(("+ " + I2S(R2I(managain))))) * -9.00 ), 15.00), 0, 10, 20.00, 20.00, 100.00, 0 ) call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 80.00, 90 ) call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 1.50 ) call SetTextTagFadepointBJ( GetLastCreatedTextTag(), 1.00 ) call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false ) call RemoveLocation (l) endif set u = null set l = null endfunction //=========================================================================== function InitTrig_Mana_Regain_Effect takes nothing returns nothing set gg_trg_Mana_Regain_Effect = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Mana_Regain_Effect, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddAction( gg_trg_Mana_Regain_Effect, function Trig_Mana_Regain_Effect_Actions ) endfunction This line in particular seems to not work JASS:if GetItemTypeId(UnitItemInSlot(u,i)) == 'I017' then Thanks ahead of time. |
| 12-11-2007, 09:36 PM | #2 |
UnitItemInSlot indexes the inventory from 0, not 1. The fix would be local integer i = 0 loop exitwhen i == 6 if GetItemTypeId(UnitItemInSlot(u,i)) == 'I017' then set chance = 20 set managain = 50.00 endif set i = i + 1 endloop |
