Snippet Recipe Items

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
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:
Code:
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: 508

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
Good job ;) So... This script only works for only 1 recipe, right? And where do I have to put it - in a new trigger, or in map script, or in a library?
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
It's just for one recipe check...

Well I can optimize it so it will work using arguments.



Edit: I just remade the whole thing so you can use arguments!
 

mase

____ ___ ____ __
Reaction score
154
Very nice. Seems simple too.
 

Sim

Forum Administrator
Staff member
Reaction score
534
What's different between this and other recipe systems?
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
I just felt like making the system since I made a tutorial about recipe, and I said to myself "Hey, I should make a system!"
 

Hatebreeder

So many apples
Reaction score
381
I just felt like making the system since I made a tutorial about recipe, and I said to myself "Hey, I should make a system!"

Hey,
This System is real nice! Well, at least in GUI, you can save up 15+ Lines when writing a Recipie.
Just a short Question: Recipie(GetTriggeringUnit(), Rde1, Rde2, Rde3, Brac)
"Rde1" And the other Codes are Rawcodes, right?
*Looks at one self, and thinks, man I'm good xD*
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
Yes they are,

its

call (unit,item1,item2,item3,newitem) where item[#] is the rawcode
 

Hatebreeder

So many apples
Reaction score
381
Yes they are,

its

call (unit,item1,item2,item3,newitem) where item[#] is the rawcode

That's absoulutly cool !!!
It makes things much easier, IMO. So... Will we be awaiting other Custom JASS Functions in future?
Like, Custom Color Codes... call Red(...) ?
Or Custom Floating Text... call CustText(3,"...",2,90)
Lifespan, Text, Fade, Velocity
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
If you want, I can make them for you (and others) just be more specific :)
 

Hatebreeder

So many apples
Reaction score
381
I realy could need that Floating Text one...
So, i mustn't always use about 5 lines of GuI to make a certain text, like Damage, show up.
In floating Text, there are Life Span, Fade Age, Text, Velocity, and most importantly, how they show up (On Unit, or at some Location).
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
You can use this one made by Blade.dk

JASS:
function AddFadingTextTag takes string text, real x, real y, integer red, integer green, integer blue, integer alpha returns nothing
    local texttag t = CreateTextTag()
    call SetTextTagText(t, text, 0.025)
    call SetTextTagPos(t, x, y, 0.00)
    call SetTextTagColor(t, red, green, blue, alpha)
    call SetTextTagVelocity(t, 0, 0.03)
    call SetTextTagVisibility(t, true)
    call SetTextTagFadepoint(t, 2)
    call SetTextTagLifespan(t, 3)
    call SetTextTagPermanent(t, false)
    set t = null
endfunction

function AddFadingTextTagLoc takes string text, location where, integer red, integer green, integer blue, integer alpha returns nothing
    call AddFadingTextTag(text, GetLocationX(where), GetLocationY(where), red, green, blue, alpha)
endfunction


Here is an example

Code:
FloatingText
    Events
        Unit - A unit dies
    Conditions
    Actions
        Custom script:   call AddFadingTextTagLoc("Died!", GetLocationX(GetTriggerUnit()), GetLocation(GetTriggerUnit()), 100, 0, 0, 100)

It will add a red "Died" floating text on top of the dead unit.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
if you have NewGen you can use instead of putting it in your header.

JASS:

library something
endlibrary
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
Looks really nice, and probably easy to use. I might use it once I can fully understand it.

Sorry about the empty Rep Comment, pressed Enter by accident >_<

EDIT: Tested the map, and checked the triggers, and wow, it is SOOO Simple!!! The 2 days you took making the script will save MANY people HOURS AND HOURS!!! Thanks!
(Omg, so many capitals and Exclamation marks :p)
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
New Version Released (OTRS V2)

Now you can use it on how you want your recipe to be made, if you want only 2 items or 6!
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
That's one damn Secksy System! I will definately use it in my map. It is SOOOO Easy to use! And easy to add more recipes.
You can tell hard work was dedicated to it.

Say goodbye to copy and pasting triggers! And to waiting and eventually drifting off/getting off topic while doing the recipe triggers in GUI.

Thank you Very Much! :D
 
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