- Joined
- Jul 1, 2008
- Messages
- 1,314
Hey guys,
Here is an example to explain, whats the problem:
Inventory Slots // Item Type
0 // Car
1 // Light
2 // Apple
3 // Light
4 // Car
5 // Apple
0 // Car
1 // Apple
2 // null
3 // Apple
4 // Apple
5 // Car
Function Should return
1. example : 0 = Car, 1 =Light, 2 = Apple
2. example : 0 = Car, 2 = Apple
THE FUNCTIONS
1. Finds out, if there are >=2 items of type x in inventory
2. Checks the inventory, and should return things as in the examples
It returns in example 1 : 0 = Car, 1 = Light
but why doesnt it return the Apple?
Would be very great if you could help me out with some logic
Greets
Here is an example to explain, whats the problem:
Inventory Slots // Item Type
0 // Car
1 // Light
2 // Apple
3 // Light
4 // Car
5 // Apple
0 // Car
1 // Apple
2 // null
3 // Apple
4 // Apple
5 // Car
Function Should return
1. example : 0 = Car, 1 =Light, 2 = Apple
2. example : 0 = Car, 2 = Apple
THE FUNCTIONS
1. Finds out, if there are >=2 items of type x in inventory
JASS:
function CountItemsOfTypeFromUnit takes unit whichUnit, integer whatItemtype returns integer
local integer index = 0
local integer count = 0
loop
exitwhen index >= bj_MAX_INVENTORY
if ( GetItemTypeId ( UnitItemInSlot ( whichUnit, index ) ) == whatItemtype ) then
set count = count + 1
endif
set index = index + 1
endloop
return count
endfunction
2. Checks the inventory, and should return things as in the examples
JASS:
function CountEveryItemInSlot takes nothing returns nothing
local unit u = udg_X
local integer i = 0
local integer array amount
local integer Type
set amount[0] = 0
set amount[1] = 0
set amount[2] = 0
set amount[3] = 0
set amount[4] = 0
set amount[5] = 0
set udg_TempIntegerCount[0] = 0
set udg_TempIntegerCount[1] = 0
set udg_TempIntegerCount[2] = 0
loop
exitwhen i > 5
set Type = GetItemTypeId(UnitItemInSlot(u,i))
if Type != 0 then
set amount[i] = CountItemsOfTypeFromUnit(u,Type)
if amount[i] >= 2 then
if Type != udg_TempIntegerCount[0] and amount[0] < 2 then
set udg_TempIntegerCount[0] = Type
set amount[0] = amount[i]
elseif Type != udg_TempIntegerCount[1] and amount[1] < 2 then
set udg_TempIntegerCount[1] = Type
set amount[1] = amount[i]
elseif Type != udg_TempIntegerCount[2] and amount[2] < 2 then
set udg_TempIntegerCount[2] = Type
set amount[2] = amount[i]
endif
endif
endif
set i = i+1
endloop
endfunction
It returns in example 1 : 0 = Car, 1 = Light
but why doesnt it return the Apple?
Would be very great if you could help me out with some logic
Greets