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.
If you can find a better or more efficient way, please do tell.
JASS:
scope RecipeMix
struct RecipeItems
integer 0 = 039;I000039;
integer 1 = 039;I001039;
integer 2 = 039;I002039;
integer 3 = 039;I003039;
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.