I am getting back to coding a map with vJass. I am trying to make a use of the struct below ( I write by myself)
in order to make this
DaggerLeveling will replace 2 lower level daggers with 1 upper level dagger. So, 2 daggers lvl 1 => 1 dagger lvl 2, 2 daggers lvl 2 => 1 dagger lvl 3, etc.
Issues:
- exitwhen this.i>6 or this.sum>N doesn't syntax
- function DaggersCond
Advices are appreciated.
JASS:
struct item
integer i = 1
integer sum = 0
integer index
item Item
method GetInventoryIndexOfItemType takes unit whichUnit, integer itemId returns integer
loop
set this.Item=UnitItemInSlot(whichUnit,this.sum)
if this.Item !=null and GetItemTypeId(this.Item)==itemId then
return this.sum + 1
endif
set this.sum = this.sum + 1
exitwhen this.sum >= bj_MAX_INVENTORY
endloop
return 0
endmethod
method GetItemOfTypeFromUnit takes unit whichUnit,integer itemId returns item
set this.i=this.GetInventoryIndexOfItemType(whichUnit,itemId)
if this.i>0 then
return UnitItemInSlot(whichUnit,this.i-1)
else
return null
endif
endmethod
method GetNumberItemsAUnitHas takes unit u,integer itemId returns integer
loop
exitwhen this.i>6
if GetItemTypeId(UnitItemInSlot(u,this.i-1))==itemId then
set this.sum=this.sum+1
endif
set this.i=this.i+1
endloop
return sum
endmethod
static method RemoveNItemsFromUnit takes integer N, integer itemId, unit u returns nothing
loop
exitwhen this.i>6 or this.sum>N
if GetItemTypeId(UnitItemInSlot(u,this.i-1))==itemId then
set this.sum=this.sum+1
set this.Item=UnitItemInSlot(u,this.i-1)
call UnitRemoveItem(u,this.Item)
call RemoveItem(this.Item)
set this.Item=null
endif
set this.i=this.i+1
endloop
endmethod
endstruct
in order to make this
JASS:
scope dagger initializer Daggers
globals
private constant integer ITEM1='I001'
private constant integer ITEM2='I002'
private constant integer ITEM3='I003'
private constant integer ITEM4='I004'
endglobals
private function DaggerLeveling takes integer itemID1, integer itemID2 returns nothing
// if item.GetNumberItemsAUnitHas(GetManipulatingUnit(),itemID1) == 2 then
if HaveSavedInteger(table, itemID1, 2) then
call item.RemoveNItemsFromUnit(2,itemID1,GetManipulatingUnit())
call UnitAddItemById( GetManipulatingUnit(), itemID2 )
endif
if (0 == itemID2) then
return
endif
endfunction
private function DaggersCond takes nothing returns boolean
call SaveInteger(table, ITEM1, 0, ITEM2)
call SaveInteger(table, ITEM2, 0, ITEM3)
call SaveInteger(table, ITEM3, 0, ITEM4)
if GetItemTypeId(GetManipulatedItem())==ITEM1 or GetItemTypeId(GetManipulatedItem())==ITEM2 or GetItemTypeId(GetManipulatedItem())==ITEM3 then
call DaggerLeveling(GetItemTypeId(GetManipulatedItem()),LoadInteger(table, GetItemTypeId(GetManipulatedItem())))
endif
return false
endfunction
private function Daggers takes nothing returns nothing
local trigger t=CreateTrigger()
local integer i=0
loop
exitwhen i>11
call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,false)
set i=i+1
endloop
call TriggerAddCondition(t,Condition(function DaggersCond))
set t=null
endfunction
endscope
DaggerLeveling will replace 2 lower level daggers with 1 upper level dagger. So, 2 daggers lvl 1 => 1 dagger lvl 2, 2 daggers lvl 2 => 1 dagger lvl 3, etc.
Issues:
- exitwhen this.i>6 or this.sum>N doesn't syntax
- function DaggersCond
Advices are appreciated.
Last edited: