1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vjass] ORTS - Orc_Tamer's Recipe System 2.0

Discussion in 'Graveyard' started by Orc_Tamer, Dec 30, 2007.

  1. Orc_Tamer

    Orc_Tamer

    Joined:
    Jan 5, 2007
    Messages:
    41
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    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)

    Code (vJASS):
    //===========================================================================
    //  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:
    Code (vJASS):

    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!
     

    Attached Files:

  2. Oninuva

    Oninuva

    Joined:
    Oct 26, 2006
    Messages:
    47
    Resources:
    2
    Maps:
    1
    Tutorials:
    1
    Resources:
    2
    Nice. Me Likey.
     
  3. WildField

    WildField

    Joined:
    Dec 18, 2007
    Messages:
    43
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Too complex system.....
     
  4. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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)
     
  5. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
  6. Matrix

    Matrix

    Joined:
    Jan 18, 2007
    Messages:
    58
    Resources:
    2
    Maps:
    2
    Resources:
    2
    +1

    I just dont get why u use vjass if it can be done without it.
    And i think it not worth to get it unless u have less then 50 recipe items.

    But still gj
     
  7. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,716
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  8. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Graveyarded due to lack of activity on the part of the author.