Outbreak191
New Member
- Reaction score
- 17
I'm not too good with JASS but I wrote a function designed to combine items by taking the material they are made of (I made alternate versions of each item made of materials like Iron and Bronze) and if that is a valid combination it creates a base item of the highest priority used in the combination and made of the new material. However all it seems to do when called is remove item b from the game.
Yes it probably is inefficient but I'll tackle that when it actually works and DeclareItems has definetly already been caled at Init.
JASS:
function RegisterItem takes integer id, integer priority, integer material, string base returns nothing
local string s = I2S(id)
call StoreString(udg_Item_Stats,s,"base",base)
call StoreInteger(udg_Item_Stats,s,"priority",priority)
call StoreInteger(udg_Item_Stats,s,"material",material)
call StoreInteger(udg_Item_Stats,base,I2S(material),id)
endfunction
function DeclareItems takes nothing returns nothing
call RegisterItem(039;Iclt039;,1,1,"Claw")
call RegisterItem(039;Iclc039;,1,2,"Claw")
call RegisterItem(039;Iclb039;,1,3,"Claw")
call RegisterItem(039;Icli039;,1,4,"Claw")
call RegisterItem(039;Iclh039;,1,5,"Claw")
call RegisterItem(039;Icls039;,1,6,"Claw")
call RegisterItem(039;Iclm039;,1,7,"Claw")
call RegisterItem(039;Icld039;,1,8,"Claw")
endfunction
function CombineItems takes item a, item b, unit u returns nothing
local string ida = I2S(GetItemTypeId(a))
local string idb = I2S(GetItemTypeId(b))
local integer array material
local integer i = 1
local integer o = 2
local integer nm = 0
local string base
local integer newid
local integer array priority
local item newi
set priority[1] = GetStoredInteger(udg_Item_Stats,ida,"priority")
set priority[2] = GetStoredInteger(udg_Item_Stats,idb,"priority")
set material[1] = GetStoredInteger(udg_Item_Stats,ida,"material")
set material[2] = GetStoredInteger(udg_Item_Stats,idb,"material")
loop
exitwhen i > 2
if material<i> == 1 and material[o] == 2 then
set nm = 3
endif
if material<i> == 3 and material[o] == 4 then
set nm = 5
endif
if material<i> == 5 and material[o] == 6 then
set nm = 7
endif
if material<i> == 6 and material[o] == 7 then
set nm = 8
endif
set i = i + 1
set o = o - 1
endloop
if nm == 0 then
if material[1] > material[2] then
set nm = material[1]
else
if material[2] > material[1] then
set nm = material[2]
else
if material[1] == material[2] then
set nm = material[1]
endif
endif
endif
endif
if priority[1] > priority[2] then
set base = GetStoredString(udg_Item_Stats,ida,"base")
else
if priority[2] > priority[1] then
set base = GetStoredString(udg_Item_Stats,idb,"base")
else
if priority[1] == priority[2] then
set base = GetStoredString(udg_Item_Stats,ida,"base")
endif
endif
endif
set newid = GetStoredInteger(udg_Item_Stats,base,I2S(nm))
set newi = CreateItem(newid,GetUnitX(u),GetUnitY(u))
call RemoveItem(a)
call RemoveItem(b)
call UnitAddItemSwapped( newi, u )
set newi = null
endfunction</i></i></i></i>
Yes it probably is inefficient but I'll tackle that when it actually works and DeclareItems has definetly already been caled at Init.