Help with item fusion trigger efficiency.

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
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)
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
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
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.
 

dracolich

TH.net Regular
Reaction score
15
bj funcs is bad only when u start to use them everywhere. some of them pretty clean and useful, no need to claim them.
but current func do u use is fine, it shouldnt be a problem at all
and funny thing - ur code is exactly the same i used for diablo defense map :D and its never made lags
 

afisakov

You can change this now in User CP.
Reaction score
37
bj funcs is bad only when u start to use them everywhere. some of them pretty clean and useful, no need to claim them.
but current func do u use is fine, it shouldnt be a problem at all
and funny thing - ur code is exactly the same i used for diablo defense map :D and its never made lags
Well, now you know where I got the trigger. I just never really knew who made that map.

I agree that in diablo it never lagged, but then there you never had 8 units acquire 6 items each simultaneously. Also the map I am currently using it in has about 3x as many recipes and alot more other stuff processed at once. I am not sure if it is the source of the lag, but was worth investigating.

btw, did you ever make a more updated version of diablo - more specifically one with better translated tooltips. I love the map, but I had to spend alot of time modifying it so me and my friends would know what the abilities actually did. instead of just saying: ___330___250___700___12
 

dracolich

TH.net Regular
Reaction score
15
meh. im just a jasser, and real developer have no clue about english -_-
those system works on every item pickup and for sure it wont be efficient in case of many instances happen. you can reduce it by using checking manipulated item type id and, if its not a part of any combo, just dont run function
 

afisakov

You can change this now in User CP.
Reaction score
37
ok thanks. Are you still in contact with developer? I have the version I was working on with alot of the abilities translated, and I was wondering if he would let me release it as the next official version, if he isn't still working on it.
Granted I have made a couple other changes of my own, like a box to buy items remotely so you don't have to return to town to shop, and a couple stat-based abilities that I think make it more fun. Though the biggest draw would probably be tooltips people can understand, since it is very hard to play a hero if you don't know what half his abilities do.
If you could put me in contact with owner I would appreciate it.
 

dracolich

TH.net Regular
Reaction score
15
as i said, you cant even talk with him xD
if u have some time u can send me russian strings and ill somehow will send back translated version. it will take some time tho
 

afisakov

You can change this now in User CP.
Reaction score
37
as i said, you cant even talk with him xD
if u have some time u can send me russian strings and ill somehow will send back translated version. it will take some time tho
that's ok, I can "translate" most of them myself by seeing what the abilities actually do and just writing them in. It won't have the original flavor text, but that would mostly be lost in translation anyway.
My hope was to see if I can get official approval to release the version I translated, in hopes of increasing the popularity of the map beyond my circle of friends to play more on b.net

I also would have wanted some of the features I added, like a couple new recipes and a box that lets you buy items remotely, to get added to official version.
I also added triggering to make some of the abilities, like jump and magma flow, do stat-based damage.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top