Snippet Recipe Items

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
Damn, this is so cool... Just a last question, because I don't know really well JASS... I make a new trigger and put the script there and don't bother to put it anywhere no more, OR do I have to put it on every trigger I create for a recipe?

/what's OTRS?/
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
After you have copied the following JASS Trigger:
JASS:
//===========================================================================
//  OTRS (Orc_Tamer's Recipe System)
//  Recipe System that allows you to make recipe items for you easier.
//  Author: Orc_Tamer
//  Date: 01.December.2007
//
//  How to implement:
//  Requires JASS NewGen World Editor
//  Just copy this trigger to your map.
//===========================================================================
library RecipeFunction

struct RecipeItems
    integer item0_id  
    integer item1_id  
    integer item2_id 
    integer item3_id  
    integer item4_id
    integer item5_id
    integer item6_id
    integer item7_id
    unit u
    item item1 = null
    item item2 = null 
    item item3 = null 
    item item4 = null
    item item5 = null
    item item6 = null
    
    method CheckItems2 takes nothing returns nothing
        local integer this_id
        local integer i = 0 
        loop
        set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) 
        if this_id == .item0_id then 
            set .item1 = UnitItemInSlot(.u, i) 
        elseif this_id == .item1_id then 
            set .item2 = UnitItemInSlot(.u, i) 
        endif
        set i = i + 1
        exitwhen i >= bj_MAX_INVENTORY
        endloop
        if .item1 != null and .item2 != null then 
            call RemoveItem(.item1)
            call RemoveItem(.item2) 
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead"))
            call UnitAddItemById(.u, .item2_id)
            set .item1 = null 
            set .item2 = null
            set .u = null
        endif
    endmethod
    
    method CheckItems3 takes nothing returns nothing
        local integer this_id 
        local integer i = 0 
        loop
        set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) 
        if this_id == .item0_id then 
            set .item1 = UnitItemInSlot(.u, i)
        elseif this_id == .item1_id then 
            set .item2 = UnitItemInSlot(.u, i) 
        elseif this_id == .item2_id then 
            set .item3 = UnitItemInSlot(.u, i) 
        endif
        set i = i + 1 
        exitwhen i >= bj_MAX_INVENTORY 
        endloop
        if .item1 != null and .item2 != null and .item3 != null then
            call RemoveItem(.item1) 
            call RemoveItem(.item2)
            call RemoveItem(.item3) 
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) //adds a special effect
            call UnitAddItemById(.u, .item3_id)
            set .item1 = null 
            set .item2 = null 
            set .item3 = null 
            set .u = null
        endif
    endmethod
    
    method CheckItems4 takes nothing returns nothing
        local integer this_id 
        local integer i = 0
        loop
        set this_id = GetItemTypeId(UnitItemInSlot(.u, i))
        if this_id == .item0_id then 
            set .item1 = UnitItemInSlot(.u, i)
        elseif this_id == .item1_id then 
            set .item2 = UnitItemInSlot(.u, i)
        elseif this_id == .item2_id then 
            set .item3 = UnitItemInSlot(.u, i)
        elseif this_id == .item3_id then
            set .item4 = UnitItemInSlot(.u, i)
        endif
        set i = i + 1 
        exitwhen i >= bj_MAX_INVENTORY 
        endloop
        if .item1 != null and .item2 != null and .item3 != null and .item4 != null then 
            call RemoveItem(.item1) 
            call RemoveItem(.item2) 
            call RemoveItem(.item3)
            call RemoveItem(.item4)
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) 
            call UnitAddItemById(.u, .item4_id)
            set .item1 = null 
            set .item2 = null 
            set .item3 = null 
            set .item4 = null
            set .u = null 
        endif
    endmethod
    
    method CheckItems5 takes nothing returns nothing
        local integer this_id 
        local integer i = 0
        loop
        set this_id = GetItemTypeId(UnitItemInSlot(.u, i))
        if this_id == .item0_id then 
            set .item1 = UnitItemInSlot(.u, i)
        elseif this_id == .item1_id then 
            set .item2 = UnitItemInSlot(.u, i)
        elseif this_id == .item2_id then 
            set .item3 = UnitItemInSlot(.u, i)
        elseif this_id == .item3_id then
            set .item4 = UnitItemInSlot(.u, i)
        elseif this_id == .item4_id then
            set .item5 = UnitItemInSlot(.u, i)
        endif
        set i = i + 1 
        exitwhen i >= bj_MAX_INVENTORY 
        endloop
        if .item1 != null and .item2 != null and .item3 != null and .item4 != null and .item5 != null then 
            call RemoveItem(.item1) 
            call RemoveItem(.item2) 
            call RemoveItem(.item3)
            call RemoveItem(.item4)
            call RemoveItem(.item5)
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) 
            call UnitAddItemById(.u, .item5_id)
            set .item1 = null 
            set .item2 = null 
            set .item3 = null 
            set .item4 = null
            set .item5 = null
            set .u = null 
        endif
    endmethod
    
    method CheckItems6 takes nothing returns nothing
        local integer this_id 
        local integer i = 0
        loop
        set this_id = GetItemTypeId(UnitItemInSlot(.u, i))
        if this_id == .item0_id then 
            set .item1 = UnitItemInSlot(.u, i)
        elseif this_id == .item1_id then 
            set .item2 = UnitItemInSlot(.u, i)
        elseif this_id == .item2_id then 
            set .item3 = UnitItemInSlot(.u, i)
        elseif this_id == .item3_id then
            set .item4 = UnitItemInSlot(.u, i)
        elseif this_id == .item4_id then
            set .item5 = UnitItemInSlot(.u, i)
        elseif this_id == .item5_id then
            set .item6 = UnitItemInSlot(.u, i)
        endif
        set i = i + 1 
        exitwhen i >= bj_MAX_INVENTORY 
        endloop
        if .item1 != null and .item2 != null and .item3 != null and .item4 != null and .item5 != null and .item6 != null then 
            call RemoveItem(.item1) 
            call RemoveItem(.item2) 
            call RemoveItem(.item3)
            call RemoveItem(.item4)
            call RemoveItem(.item5)
            call RemoveItem(.item6)
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) 
            call UnitAddItemById(.u, .item6_id)
            set .item1 = null 
            set .item2 = null 
            set .item3 = null 
            set .item4 = null
            set .item5 = null
            set .item6 = null
            set .u = null 
        endif
    endmethod
endstruct

function Recipe2 takes unit hero, integer i1, integer i2, integer ni returns nothing
    local RecipeItems IS=RecipeItems.create() 
    set IS.item0_id = i1 
    set IS.item1_id = i2 
    set IS.item2_id = ni 
    set IS.u = hero 
    call IS.CheckItems2() 
    call IS.destroy() 
endfunction

function Recipe3 takes unit hero, integer i1, integer i2, integer i3, integer ni returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.item0_id = i1 
    set IS.item1_id = i2 
    set IS.item2_id = i3 
    set IS.item3_id = ni 
    set IS.u = hero 
    call IS.CheckItems3() 
    call IS.destroy()
endfunction

function Recipe4 takes unit hero, integer i1, integer i2, integer i3, integer i4, integer ni returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.item0_id = i1 
    set IS.item1_id = i2 
    set IS.item2_id = i3 
    set IS.item3_id = i4 
    set IS.item4_id = ni
    set IS.u = hero 
    call IS.CheckItems4() 
    call IS.destroy()
endfunction

function Recipe5 takes unit hero, integer i1, integer i2, integer i3, integer i4, integer i5, integer ni returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.item0_id = i1 
    set IS.item1_id = i2 
    set IS.item2_id = i3 
    set IS.item3_id = i4
    set IS.item4_id = i5
    set IS.item5_id = ni
    set IS.u = hero 
    call IS.CheckItems5() 
    call IS.destroy()
endfunction

function Recipe6 takes unit hero, integer i1, integer i2, integer i3, integer i4, integer i5, integer i6, integer ni returns nothing
    local RecipeItems IS=RecipeItems.create()
    set IS.item0_id = i1 
    set IS.item1_id = i2 
    set IS.item2_id = i3 
    set IS.item3_id = i4
    set IS.item4_id = i5
    set IS.item5_id = i6
    set IS.item6_id = ni
    set IS.u = hero 
    call IS.CheckItems6() 
    call IS.destroy()
endfunction

endlibrary

Also copy this one:
JASS:
function Trig_RecipeChecking_Actions takes nothing returns nothing
    call Recipe2(GetTriggerUnit(),'rde1','rde2','rde3')
    call Recipe3(GetTriggerUnit(),'afac','spsh','ajen','bgst')
    call Recipe4(GetTriggerUnit(),'ratc','rat6','rat9','bspd','modt')
    call Recipe5(GetTriggerUnit(),'ofro','olig','oven','ocor','oslo','sor9')
    call Recipe6(GetTriggerUnit(),'pghe','pgma','pdiv','pomn','pres','pnvu','infs')
endfunction

function InitTrig_RecipeJASS takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function Trig_RecipeChecking_Actions )
endfunction


Recipe# = The number of items needed to make another one. So if ItemA + ItemB = ItemC, then you will use "call Recipe2(GetTriggerUnit(),'RAW1','RAW2','RAW3')

Where RAW is the Raw code of the item. RAW1 and RAW2 are the items needed to make RAW3.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
When I copy the code and save my map gives me hundreds of errors... How can I fix that? :/
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
Do you have JASS Newgen World Editor?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Good job Orc_Tamer. Kinda reminds me my recipe system a I did a while ago. I think you can try to do it all in 2 function if you'll pass the number of items taken, it will make the system more flexible as well.
 
Reaction score
333
I think this could be optimized a lot if you used loops and arrays rather than separate variables for each item, etc.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
I think this could be optimized a lot if you used loops and arrays rather than separate variables for each item, etc.
I am working on that at the moment and will be released on V3. I quickly released V2 in order to make it capable of being used with any possible item recipe.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
> Do you have JASS Newgen World Editor?
Uh, yes.. But it's showing me stuff like statement outside function for every line...
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
If it's TESH than its ok, I don't know why it does that :confused:
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
MAYBE, just MAYBE it has to do with your settings? >_<

examplesq7.png

(Screenshot is courtesy of Orc_Tamer)

Happened to me.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
Well, I have enabled only "Enable JassHelper" and "Enable object editor hack" X_X. Should I enable the other stuff u showed in the pic?
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
589
Make your options match the ones shown in the image.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
> Make your options match the ones shown in the image.
Oh, ok then.
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
Hmm, I have a question. How can you combine this to add limits? As in 1 item type per unit? I don't know JASS so that's why I'm asking.

NM, I can just use GUI lol. Silly me.
 

waaaks!

Zinctified
Reaction score
255
does this stack with 2 with the same components?

like if u combine 2 claws of attack to 1 claws of attack?

because a basic item recipe trigger only combine items that dont have the same component

and also a question
rheias made a recipe system....
so whats the difference between urs and rheias?
 

NetherHawk

New Member
Reaction score
26
i think you should modify your call Recipe function. be it 2 3 4 5 or 6 items, just use 1 function. if there are only 2 items in the recipe, the rest of the item id's can be entered as ' ', a null kind of thing?
 

Jesus4Lyf

Good Idea™
Reaction score
397
The right way to do this is define the recipes on map init, attach to each item type each recipe it can be used in using a hashtable and linked list, and then internally set up the event for unit picking up an item, load the list from the hashtable, and check only the right recipes with blinding speed. :thup:

So, same interface, but run once on map init instead of put in when an item is acquired. ;)

Of course, this is two years old and GY'd, lol.
 

pastuh

New Member
Reaction score
0
How convert Jass script into normal editor view?
I want see not text, but near code icons..
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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