afisakov
You can change this now in User CP.
- Reaction score
- 37
I found an item fusion system that lets me create recipes for items with a one-line entry. However lately I m starting to question how efficient the code in it is, since I am getting increasing lag on item acquisition.
Normally a .3 second lag picking up an item would not bother me too much, but it grows to 2 seconds or more when using mirror images and I am hoping to cut it down.
The full trigger I am now using
each "call CompleteItem" line is another recipe, so this system saves me alot of space, but I want to make sure it is as efficient as possible
The part I am thinking about replacing
I was thinking of replacing the GetItemFromUnit function with "UnitHasItemOfTypeBJ", since it sounds faster than checking item identity against all 6 items in inventory, however people have told me bad things about using BJ functions so I want to make sure doing so would actually be an improvement.
Checking the GetManipulatedItem doesn't really work for me since these recipe's are automatic, meaning the player does not need to purchase a recipe, just the components, therefore there is no natural last item and it needs to work whichever item in recipe the player picks up last.
I would appreciate any advice anyone can offer to make this run faster (and be leak-free of course), as well as feedback on whether my idea of switching to unithasitemoftypeBJ would be a improvement.
Normally a .3 second lag picking up an item would not bother me too much, but it grows to 2 seconds or more when using mirror images and I am hoping to cut it down.
The full trigger I am now using
Code:
function GetItemFromUnit takes unit u,integer i returns item
local integer ict2=0
local item loc_item1
loop
exitwhen ict2==6
set loc_item1=UnitItemInSlot(u,ict2)
if loc_item1!=null and GetItemTypeId(loc_item1)==i then
return loc_item1
endif
set ict2=ict2+1
endloop
return null
endfunction
function CompleteItem takes unit u,integer pieces,integer id0,integer id1,integer id2,integer id3,integer id4,integer id5,integer resultid returns nothing
local integer array ids
local integer ict1=0
local integer ict2=0
set ids[0]=id0
set ids[1]=id1
set ids[2]=id2
set ids[3]=id3
set ids[4]=id4
set ids[5]=id5
loop
exitwhen ict1>pieces
if GetItemFromUnit(u,ids[ict1])!=null then
set ict2=ict2+1
endif
set ict1=ict1+1
endloop
if ict2==pieces then
set ict1=0
loop
exitwhen ict1>pieces
call RemoveItem(GetItemFromUnit(u,ids[ict1]))
set ict1=ict1+1
endloop
call UnitAddItemById(u,resultid)
endif
endfunction
function CheckForCompleteItems takes nothing returns nothing
call CompleteItem(GetTriggerUnit(),4,'I01P','asbl','I01S','blba',0,0,'I017')
call CompleteItem(GetTriggerUnit(),3,'I017','I01S','I01D',0,0,0,'I0CP')
call CompleteItem(GetTriggerUnit(),3,'I00L','I01S','klmm',0,0,0,'I0BZ')
call CompleteItem(GetTriggerUnit(),3,'I01N','I01Z','I01P',0,0,0,'klmm')
call CompleteItem(GetTriggerUnit(),4,'I01Q','I01P','klmm','I017',0,0,'I02Q')
call CompleteItem(GetTriggerUnit(),3,'I0CN','I03V','I01P',0,0,0,'I02J')
call CompleteItem(GetTriggerUnit(),4,'I04S','I046','I02J','I03T',0,0,'I0CO')
call CompleteItem(GetTriggerUnit(),4,'I04E','I05J','I05S','I060',0,0,'I00R')
call CompleteItem(GetTriggerUnit(),4,'I04E','I05J','I01T','I0CP',0,0,'I00P')
call CompleteItem(GetTriggerUnit(),5,'I00P','I00R','I018','klmm','I0CP',0,'I06E')
call CompleteItem(GetTriggerUnit(),4,'I00P','I00R','I0BY','I0CO',0,0,'I00S')
call CompleteItem(GetTriggerUnit(),2,'I0CL','I036',0,0,0,0,'I058')
call CompleteItem(GetTriggerUnit(),2,'I0AU','I036',0,0,0,0,'I058')
call CompleteItem(GetTriggerUnit(),4,'I058','I0BY','I02J','I03U',0,0,'I04O')
call CompleteItem(GetTriggerUnit(),4,'I04O','I06M','I0CH','I050',0,0,'I05Y')
endfunction
set trg_makeitem=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg_makeitem,EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(trg_makeitem,function CheckForCompleteItems)
The part I am thinking about replacing
Code:
function GetItemFromUnit takes unit u,integer i returns item
local integer ict2=0
local item loc_item1
loop
exitwhen ict2==6
set loc_item1=UnitItemInSlot(u,ict2)
if loc_item1!=null and GetItemTypeId(loc_item1)==i then
return loc_item1
endif
set ict2=ict2+1
endloop
return null
endfunction
...
loop
exitwhen ict1>pieces
if GetItemFromUnit(u,ids[ict1])!=null then
//looping through all 6 item slots for each item of recipe seems kind of long
set ict2=ict2+1
endif
set ict1=ict1+1
endloop
if ict2==pieces then
set ict1=0
loop
exitwhen ict1>pieces
call RemoveItem(GetItemFromUnit(u,ids[ict1]))
set ict1=ict1+1
endloop
Checking the GetManipulatedItem doesn't really work for me since these recipe's are automatic, meaning the player does not need to purchase a recipe, just the components, therefore there is no natural last item and it needs to work whichever item in recipe the player picks up last.
I would appreciate any advice anyone can offer to make this run faster (and be leak-free of course), as well as feedback on whether my idea of switching to unithasitemoftypeBJ would be a improvement.