Will this script work? Item Recipe

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
I just finished this script and I can't test it "at the moment". I don't know if using structs/methods was a good way of making it.

JASS:
scope RecipeMix

struct RecipeItems
    integer 0 = 'I000'
    integer 1 = 'I001'
    integer 2 = 'I002'
    integer 3 = 'I003'
    unit u
    integer i = 0
    integer this
    item item1 = null
    item item2 = null
    item item3 = null
    
    method CheckItems takes nothing returns nothing
        set this.u = GetTriggerUnit()
            loop
        set this.this = GetItemTypeId(UnitItemInSlot(this.u, this.i))
        if this.this == 0 then
            set this.item1 = UnitItemInSlot(this.u, this.i)
        endif
        if this.this == 1 then
            set this.item2 = UnitItemInSlot(this.u, this.i)
        endif
        if this.this == 2 then
            set this.item3 = UnitItemInSlot(this.u, this.i)
        endif
        set this.i = this.i + 1
        exitwhen this.i >= bj_MAX_INVENTORY
    endloop
    if this.item1 != null and this.item2 != null and this.item3 != null then
        call RemoveItem(this.item1)
        call RemoveItem(this.item2)
        call RemoveItem(this.item3)
        call UnitAddItemById(this.u, 3)
        set this.item1 = null
        set this.item2 = null
        set this.item3 = null
    endif
    endmethod
    
    method RecipeSystem takes nothing returns nothing
        call this.CheckItems()
    endmethod
endstruct

function RecipeInit takes nothing returns nothing
    local RecipeItems IS=RecipeItems.create()
    call IS.RecipeSystem()
endfunction

function Conditions takes nothing returns boolean
    local integer i = GetItemTypeId(GetManipulatedItem())
    return i == 0 or i == 1 or i == 3
endfunction

function RecipeSystem takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function RecipeInit )
    call TriggerAddCondition(t, Condition(function Conditions))
    
endfunction

endscope


If you can find a better or more efficient way, please do tell.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Well, what is this supposed to do in the first place?


Just a side note, naming your variables like "this", "i", "u" etc. is generally a bad idea. Especially inside a struct.

You will get lost.


Furthermore, variable names should start with a letter, I seriously doubt whether your code syntaxes.
 

Technomancer

New Member
Reaction score
14
The above guy is right. Be ridiculously descriptive with your function names. I'm looking everything over now.

integer 0 = 'l000'
integer 1 = 'l001'
integer 2 = '1002'
integer 3 = '1003'

Needs letters, example:

integer Unit0_ID = 'l000'

"this.this"
this is a keyword, you cannot name anything "this", it would be like naming an integer integer.


Use more locals in the checkid function
for instance change "integer this" to "local integer curItemID" for a better name and to save some struct space.



You never specify a unit anywhere in your code.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
Well, what is this supposed to do in the first place?


Just a side note, naming your variables like "this", "i", "u" etc. is generally a bad idea. Especially inside a struct.

You will get lost.


Furthermore, variable names should start with a letter, I seriously doubt whether your code syntaxes.

It's suppose to check for 3 items in the hero slot and replace them with a new one. I will try to stop my habit of using 1 word/number variables.
 

Technomancer

New Member
Reaction score
14
I went at it:

JASS:
scope RecipeMix

struct RecipeItems
    integer item0_id = 'I000'
    integer item1_id = 'I001'
    integer item2_id = 'I002'
    integer recipiemakes_id = 'I003' //changed names for clarity
    unit u
//    integer i = 0
//    integer this // Removed
    item item1 = null
    item item2 = null
    item item3 = null
    
    method CheckItems takes nothing returns nothing
        local integer this_id = 0
        local integer i = 0
// new locals
            loop
        set this_id = GetItemTypeId(UnitItemInSlot(this.u, i))
        if this.this == item0_id then
            set this.item1 = UnitItemInSlot(this.u, i)
        endif
        if this_id == item1_id then
            set this.item2 = UnitItemInSlot(this.u, i)
        endif
        if this_id == item2_id then
            set this.item3 = UnitItemInSlot(this.u, i)
        endif
        set i = i + 1
        exitwhen i >= bj_MAX_INVENTORY
    endloop
    if this.item1 != null and this.item2 != null and this.item3 != null then
        call RemoveItem(this.item1)
        call RemoveItem(this.item2)
        call RemoveItem(this.item3)
        call UnitAddItemById(this.u, recipiemakes_id)
    endif
// I moved these nulls outside of brackets, because otherwise they don't get nulled even if 2/3 match or whatever.
        set this.item1 = null
        set this.item2 = null
        set this.item3 = null
    endmethod
    
    method RecipeSystem takes nothing returns nothing
        call this.CheckItems()
    endmethod
endstruct

function RecipeInit takes nothing returns nothing
    local RecipeItems IS=RecipeItems.create()
//*** this line was moved outside of the struct, otherwise I don't know if you can get the trigger unit.
    set IS.u = GetTriggerUnit()
    call IS.RecipeSystem()
    set IS.u = null
// null it after we're done.
endfunction

function Conditions takes nothing returns boolean
    local integer i = GetItemTypeId(GetManipulatedItem())
    return i == 0 or i == 1 or i == 3
endfunction

function RecipeSystem takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function RecipeInit )
    call TriggerAddCondition(t, Condition(function Conditions))
    
endfunction

endscope



A few extra notes:
Add a total of 6 item IDs, and then if you want a recipie to only use two items, just set the last four items to be the same as one of the first two. It checks them all anyway.

Ex: Recipe pwnsauce needs
1 pwn, with id 'I000'
1 sauce, with id 'I001'

integer item0_id = 'I000'
integer item1_id = 'I001'
integer item2_id = 'I001'
integer item3_id = 'I001'
integer item4_id = 'I001'
integer item5_id = 'I001'

everything would work out fine, except for the removes, but that could be done pretty easily as well.

This would make it a little slower (who cares?) but way more modular.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
For some reason the trigger doesn't work, I fixed some minor errors but it won't remove the items and give me the new one. :banghead:

JASS:
scope RecipeMix

struct RecipeItems
    integer item0_id = 'I000'
    integer item1_id = 'I001'
    integer item2_id = 'I002'
    integer item3_id = 'I003'
    unit u
//    integer i = 0
//    integer this // Removed
    item item1 = null
    item item2 = null
    item item3 = null
    
    method CheckItems takes nothing returns nothing
        local integer this_id = 0
        local integer i = 0
// new locals
            loop
        set this_id = GetItemTypeId(UnitItemInSlot(this.u, i))
        if this_id == this.item0_id then
            set this.item1 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item1_id then
            set this.item2 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item2_id then
            set this.item3 = UnitItemInSlot(this.u, i)
        endif
        set i = i + 1
        exitwhen i >= bj_MAX_INVENTORY
    endloop
    if this.item1 != null and this.item2 != null and this.item3 != null then
        call RemoveItem(this.item1)
        call RemoveItem(this.item2)
        call RemoveItem(this.item3)
        call UnitAddItemById(this.u, this.item3_id)
    endif
// I moved these nulls outside of brackets, because otherwise they don't get nulled even if 2/3 match or whatever.
        set this.item1 = null
        set this.item2 = null
        set this.item3 = null
    endmethod
    
    method RecipeSystem takes nothing returns nothing
        call this.CheckItems()
    endmethod
endstruct

function RecipeInit takes nothing returns nothing
    local RecipeItems IS=RecipeItems.create()
//*** this line was moved outside of the struct, otherwise I don't know if you can get the trigger unit.
    set IS.u = GetTriggerUnit()
    call IS.RecipeSystem()
    set IS.u = null
// null it after we're done.
endfunction

function Conditions takes nothing returns boolean
    local integer i = GetItemTypeId(GetManipulatedItem())
    return i == 0 or i == 1 or i == 3
endfunction

function RecipeSystem takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function RecipeInit )
    call TriggerAddCondition(t, Condition(function Conditions))
    
endfunction

endscope
 

Technomancer

New Member
Reaction score
14
^^ you can encapsulate it in the struct and then anyone can use it, without having to script any code. Seems like a good deal to me.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
My personal favorite would go to some function like:
call Recipies(unit, item1, item2, item3, newitem)
that would do the work.

And the trigger action has a bunch such calls.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
So there is no way of fixing the one I made?

JASS:
scope RecipeMix

struct RecipeItems
    integer item0_id = 'I000'
    integer item1_id = 'I001'
    integer item2_id = 'I002'
    integer item3_id = 'I003'
    unit u
    item item1 = null
    item item2 = null
    item item3 = null
    
    method CheckItems takes nothing returns nothing
        local integer this_id
        local integer i = 0
            loop
        set this_id = GetItemTypeId(UnitItemInSlot(this.u, i))
        if this_id == this.item0_id then
            set this.item1 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item1_id then
            set this.item2 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item2_id then
            set this.item3 = UnitItemInSlot(this.u, i)
        endif
        set i = i + 1
        exitwhen i >= bj_MAX_INVENTORY
    endloop
    if this.item1 != null and this.item2 != null and this.item3 != null then
        call RemoveItem(this.item1)
        call RemoveItem(this.item2)
        call RemoveItem(this.item3)
        call UnitAddItemById(this.u, this.item3_id)
        set this.item1 = null
        set this.item2 = null
        set this.item3 = null
        set this.u = null
    endif
    endmethod
endstruct

function RecipeInit takes nothing returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.u = GetTriggerUnit()
    call IS.CheckItems()
endfunction

function Conditions takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I000' or GetItemTypeId(GetManipulatedItem()) == 'I001' or GetItemTypeId(GetManipulatedItem()) == 'I002'
endfunction

function RecipeSystem takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function RecipeInit )
    call TriggerAddCondition(t, Condition(function Conditions))
    
endfunction

endscope
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
Well I tried my script on another map, for some reason I added units to the map with custom triggers and items but it was saving it as a .w3m now that it was in a .w3x map it worked, I guess it was a bug using NewGen?

Now It works: Here it is

JASS:
scope RecipeMix

struct RecipeItems
    integer item0_id = 'rde1'
    integer item1_id = 'rde2'
    integer item2_id = 'rde3'
    integer item3_id = 'brac'
    unit u
    item item1 
    item item2
    item item3
    
    method CheckItems takes nothing returns nothing
        local integer this_id
        local integer i = 0
            loop
        set this_id = GetItemTypeId(UnitItemInSlot(this.u, i))
        if this_id == this.item0_id then
            set this.item1 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item1_id then
            set this.item2 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item2_id then
            set this.item3 = UnitItemInSlot(this.u, i)
        endif
        set i = i + 1
        exitwhen i >= bj_MAX_INVENTORY
    endloop
    if this.item1 != null and this.item2 != null and this.item3 != null then
        call RemoveItem(this.item1)
        call RemoveItem(this.item2)
        call RemoveItem(this.item3)
        call UnitAddItemById(this.u, this.item3_id)
        set this.item1 = null
        set this.item2 = null
        set this.item3 = null
        set this.u = null
    endif
    endmethod
endstruct

private function Actions takes nothing returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.u = GetManipulatingUnit()
    call IS.CheckItems()
endfunction

public function InitTrig takes nothing returns nothing    
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function Actions )
endfunction

endscope
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
Thank you everyone for their help. Especially you AceHart :D

Here is what I have: Do I use

JASS:
call RecipeItems.destroy(IS)


or

JASS:
call IS.destroy()


JASS:
scope RecipeMix

struct RecipeItems
    integer item0_id = 'rde1'
    integer item1_id = 'rde2'
    integer item2_id = 'rde3'
    integer item3_id = 'brac'
    unit u
    item item1 = null
    item item2 = null
    item item3 = null
    
    method CheckItems takes nothing returns nothing
        local integer this_id
        local integer i = 0
            loop
        set this_id = GetItemTypeId(UnitItemInSlot(this.u, i))
        if this_id == this.item0_id then
            set this.item1 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item1_id then
            set this.item2 = UnitItemInSlot(this.u, i)
        endif
        if this_id == this.item2_id then
            set this.item3 = UnitItemInSlot(this.u, i)
        endif
        set i = i + 1
        exitwhen i >= bj_MAX_INVENTORY
    endloop
    if this.item1 != null and this.item2 != null and this.item3 != null then
        call RemoveItem(this.item1)
        call RemoveItem(this.item2)
        call RemoveItem(this.item3)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",this.u,"overhead"))
        call UnitAddItemById(this.u, this.item3_id)
        set this.item1 = null
        set this.item2 = null
        set this.item3 = null
        set this.u = null
    endif
    endmethod
endstruct

private function Actions takes nothing returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.u = GetManipulatingUnit()
    call IS.CheckItems()
    call IS.destroy()
endfunction

public function InitTrig takes nothing returns nothing    
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function Actions )
endfunction

endscope
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
> Do I use ...

Personal preference.
I use the second one...

Ok, I thought they did different things. I guess I'm getting hang of structs and methods, now to implement structs with kattana's handle vars.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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