luorax
Invasion in Duskwood
- Reaction score
- 67
How can I immediately give the item back to its owner if it drops it? Because this crashes my WC3:
Any idea why?
JASS:
library InventorySystem requires Table,ItemList,SimError,Status,Champion,AII
private struct Data extends array
boolean sold
boolean dropped
private method AII_onDestroy takes nothing returns nothing
set this.sold=false
set this.dropped=false
endmethod
implement AII
endstruct
//The Inventory struct..
struct Inventory
unit Owner
integer ShopId
Champion Champ
public static HandleTable table
//creates a new Inventory for the unit
static method create takes unit whichUnit, Champion c returns thistype
local thistype this = 0
if not thistype.table.exists(whichUnit) then
set this = thistype.allocate()
set this.Owner = whichUnit
set this.ShopId = GetPlayerId(GetOwningPlayer(this.Owner))
set this.Champ = c
call TriggerRegisterUnitEvent(thistype.Pickup, this.Owner, EVENT_UNIT_PICKUP_ITEM)
call TriggerRegisterUnitEvent(thistype.Drop, this.Owner, EVENT_UNIT_DROP_ITEM)
call TriggerRegisterUnitEvent(thistype.Sell, this.Owner, EVENT_UNIT_PAWN_ITEM)
call TriggerRegisterUnitEvent(thistype.LevelUp, this.Owner, EVENT_UNIT_HERO_LEVEL)
set thistype.table[this.Owner] = this
return this
endif
return 0
endmethod
//will be runned whenever an item is picked up
private static method pickupItem takes nothing returns boolean
if Data[GetManipulatedItem()].dropped then
set Data[GetManipulatedItem()].dropped=false
else
call thistype.equipItem(GetTriggerUnit(),GetManipulatedItem())
endif
return false
endmethod
//Will be runned whenever an item is dropped
private static method dropItem takes nothing returns boolean
if not Data[GetManipulatedItem()].sold then
set Data[GetManipulatedItem()].dropped=true
call UnitAddItem(GetTriggerUnit(),GetManipulatedItem())
call SimError(GetOwningPlayer(GetTriggerUnit()), "You can039;t drop items!")
endif
return false
endmethod
//Will be runned whenever an item is sold
private static method sellItem takes nothing returns boolean
set Data[GetSoldItem()].sold=true
call thistype.unequipItem(GetTriggerUnit(),GetSoldItem())
return false
endmethod
private static method levelUpAct takes nothing returns boolean
local unit u=GetTriggerUnit()
local Champion c=Champion.getChampionById(GetUnitTypeId(u))
local real life=GetUnitState(u,UNIT_STATE_LIFE)
local real mana=GetUnitState(u,UNIT_STATE_MANA)
call Status<u>.modHealthBonus(c.healthPerLevel)
call Status<u>.modManaBonus(c.manaPerLevel)
call Status<u>.modHealthRegenBonus(c.healthRegenPerLevel/5)
call Status<u>.modManaRegenBonus(c.manaRegenPerLevel/5)
call SetHeroStr(u, GetHeroStr(u,false)+c.resistancePerLevel, true)
call SetPlayerTechResearched(GetOwningPlayer(u),039;UPGA039;,GetHeroLevel(u)-1)
call SetPlayerTechResearched(GetOwningPlayer(u),039;UPGD039;,(GetHeroLevel(u)-1)*c.damagePerLevel)
set DamageStats<u>.AttackSpeedMultiplier=DamageStats<u>.AttackSpeedMultiplier+c.attackSpeedPerLevel
call SetUnitState(u,UNIT_STATE_LIFE,life+c.healthPerLevel)
call SetUnitState(u,UNIT_STATE_MANA,mana+c.manaPerLevel)
set u = null
return false
endmethod
private static trigger Pickup = CreateTrigger()
private static trigger Drop = CreateTrigger()
private static trigger LevelUp = CreateTrigger()
private static trigger Sell = CreateTrigger()
//initialization of the Inventory struct
private static method onInit takes nothing returns nothing
set thistype.table=HandleTable.create()
call TriggerAddCondition(thistype.Pickup, Condition(function thistype.pickupItem))
call TriggerAddCondition(thistype.Drop, Condition(function thistype.dropItem))
call TriggerAddCondition(thistype.Sell, Condition(function thistype.sellItem))
call TriggerAddCondition(thistype.LevelUp, Condition(function thistype.levelUpAct))
endmethod
endstruct
endlibrary
</u></u></u></u></u></u>
Any idea why?