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 The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top