| 02-20-2005, 03:06 PM | #1 |
I was wandering if this would work, and if there would be any way to improve it. It's an item creation function that i was thinking of using in an rpg project Code:
Function 2items takes item item1, item item2, item createditem, unit crafter returns nothing
a = integer
aend = integer
b = integer
bend = integer
set a = 1
set aend = 6
set b = 1
set bend = 6
loop
exitwhen a>aend
if ( GetItemTypeId(UnitItemInSlotBJ(crafter, a)) == item1 ) ) then
loop
exitwhen b>bend
if ( GetItemTypeId(UnitItemInSlotBJ(crafter, b)) == item2 ) and a != b ) then
call RemoveItem( UnitItemInSlotBJ(crafter, a) )
call RemoveItem( UnitItemInSlotBJ(crafter, b) )
call UnitAddItemByIdSwapped( createditem, crafter )
else
endif
set b = b+1
endloop
else
endif
endloopthx for any help ![]() |
| 02-20-2005, 08:00 PM | #2 |
Code:
function 2items takes item item1, item item2, item createditem, unit crafter returns nothing
//Set All local variables for looping
local integer array loopVars
set loopVars[0] = 1 //A
set loopVars[1] = 6 //A end
set loopVars[2] = 1 //B
set loopVars[3] = 6 //B end
loop
exitwhen loopVars[0] > loopVars[1]
if GetItemTypeId(UnitItemInSlotBJ(crafter, loopVars[0])) == item1 then
loop
exitwhen loopVars[2] > loopVars[3]
if GetItemTypeId(UnitItemInSlotBJ(crafter, loopVars[2])) == item2 then
if loopVars[0] != loopVars[2] then
call RemoveItem( UnitItemInSlotBJ(crafter, loopVars[0]) )
call RemoveItem( UnitItemInSlotBJ(crafter, loopVars[0]) )
call UnitAddItemByIdSwapped( createditem, crafter )
endif
endif
set loopVars[2] = loopVars[2] + 1
endloop
endif
loopVars[0] = loopVars[0] + 1
endloop
set item1 = null
set item2 = null
set createditem = null
endfunction |
| 02-21-2005, 04:32 PM | #3 |
Thankyou very much : ) rep given ![]() EDIT: when i put this intop my map, it returns a load of errors, like Line 31: Expected a name and Line 35: Expected a variable name... why? i have changed nothing before i pasted this into the test map :\ :( |
