• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vjass] ORTS - Orc_Tamer's Recipe System 2.0

Level 5
Joined
Jan 5, 2007
Messages
40
Here a basic script using structs and methods to combine items into 1.

Changelog:
Version: 2.0 (Added New Function Arguments and Optimized Coding)
Version: 1.0 (Fixed minor bug)

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

This is an example you can use:
GUI:
  • RecipeGUI
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Custom script: call Recipe2(GetTriggerUnit(),'rde1','rde2','rde3')
      • Custom script: call Recipe3(GetTriggerUnit(),'afac','spsh','ajen','bgst')
      • Custom script: call Recipe4(GetTriggerUnit(),'ratc','rat6','rat9','bspd','modt')
      • Custom script: call Recipe5(GetTriggerUnit(),'ofro','olig','oven','ocor','oslo','sor9')
      • Custom script: call Recipe6(GetTriggerUnit(),'pghe','pgma','pdiv','pomn','pres','pnvu','infs')
JASS:
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

Enjoy :)

Demo Map Added! Check It Out!
 

Attachments

  • RecipeSystem-V2.w3x
    20.4 KB · Views: 147
Level 40
Joined
Dec 14, 2005
Messages
10,532
There's no advantage to use structs here, and it will force people to get JassNewGen. (Maybe that last bit isn't so bad :p)

Also, you could do this easily with an item array, and always having 6 item-id parameters for the recipe function; let people leave unused ones as 0. (And write some wrappers if you're concerned newbs may not get it)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
This system is horriadly unefficent.
The ammount of opperations it runs is past exesive to do something which is simple enough to make oneself.

Basically, it will probably be more efficent (and so better) to use a simple if tree system as this might even hit the opt limate if used improperly.

I can not deny that it is a nice script, just it is not the most efficent for its task.
 
Top