- Joined
- Sep 26, 2009
- Messages
- 9,534
In all my years working with JassHelper, I have never seen set.var = val syntax. Isn't that throwing a syntax error? There are way too many dots in your map and in your examples
//Learn by: https://www.hiveworkshop.com/threads/item-stacking-system.139336/
struct ItemEvent
//Setting charge limit below here
static integer charge_limit = 12
private static method PickUpEvent takes nothing returns nothing
local item Item = GetManipulatedItem()
local integer ItemID = GetItemTypeId(GetManipulatedItem())
local unit u = GetTriggerUnit()
local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())
local item ItemSlot = null
local integer n = 1
// Stack Charge
if GetItemType(Item) == ITEM_TYPE_CHARGED then
set n = 1
loop
exitwhen n > UnitInventorySize(u)
set ItemSlot = UnitItemInSlotBJ(u, n)
if GetItemTypeId(ItemSlot) == ItemID and GetItemCharges(ItemSlot) <.charge_limit and ItemSlot != Item then
call SetItemCharges(ItemSlot, (GetItemCharges(ItemSlot)) + GetItemCharges(Item))
call RemoveItem(Item)
// //Limit Item
if GetItemCharges(ItemSlot) >.charge_limit then
set bj_lastCreatedItem = CreateItem(ItemID, x, y)
call SetItemCharges(bj_lastCreatedItem, GetItemCharges(ItemSlot) -.charge_limit)
call UnitAddItemSwapped(bj_lastCreatedItem, u)
call SetItemCharges(ItemSlot,.charge_limit)
set bj_lastCreatedItem = null
endif
endif
set ItemSlot = null
set n = n + 1
endloop
endif
//End Stack Charge
set Item = null
endmethod
private static method OrderItemEvent takes nothing returns nothing
local integer OrderID = GetIssuedOrderId()
local unit OrderUnit = GetOrderedUnit()
local real x = GetUnitX(GetOrderedUnit())
local real y = GetUnitY(GetOrderedUnit())
local item OrderItem = GetOrderTargetItem()
//Split Charge Feature (Only working with item charge)
if OrderID >= 852002 and OrderID <= 852007 and OrderItem == UnitItemInSlotBJ(OrderUnit, (OrderID - 852001)) and GetItemCharges(OrderItem) > 1 and GetItemType(OrderItem) == ITEM_TYPE_CHARGED then
call SetItemCharges(OrderItem, (GetItemCharges(OrderItem) -1))
set bj_lastCreatedItem = CreateItem(GetItemTypeId(OrderItem), x, y)
call SetItemCharges(bj_lastCreatedItem, 1)
set bj_lastCreatedItem = null
endif
set OrderUnit = null
set OrderItem = null
endmethod
private static method onInit takes nothing returns nothing
local trigger PickUp = CreateTrigger()
local trigger OrderItem = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(PickUp, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(PickUp, function thistype.PickUpEvent)
call TriggerRegisterAnyUnitEventBJ(OrderItem, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddAction(OrderItem, function thistype.OrderItemEvent)
endmethod
endstruct
struct ItemCommbine
integer CombineID = 0
integer RecipeID = 0
integer Charge = 0
ItemRecipe array Items[6]
method Match takes nothing returns boolean
local integer n = 1
loop
exitwhen n > bj_MAX_INVENTORY
if .Items[n].IDReq != 0 and.Items[n].Require == false then
return false
endif
set n = n + 1
endloop
return true
endmethod
method Setup takes nothing returns nothing
local integer n = 1
loop
exitwhen n > bj_MAX_INVENTORY
set .Items[n] = ItemRecipe.create()
set n = n + 1
endloop
endmethod
method Reset takes nothing returns nothing
local integer n = 1
loop
exitwhen n > bj_MAX_INVENTORY
call .Items[n].Reset()
set n = n + 1
endloop
endmethod
method GiveCombineItem takes unit u returns nothing
local integer n = 1
loop
exitwhen n > UnitInventorySize(u)
if .Items[n].IDReq != 0 then
call .Items[n].Remove(u)
endif
set n = n + 1
endloop
set bj_lastCreatedItem = CreateItem(CombineID, GetUnitX(u), GetUnitY(u))
call SetItemCharges(bj_lastCreatedItem, .Charge)
call UnitAddItemSwapped(bj_lastCreatedItem, u)
set bj_lastCreatedItem = null
endmethod
endstruct
struct ItemRecipe
integer ChargeReq = 0
integer IDReq = 0
boolean Require = false
integer slot = 0
method Check takes integer ID, integer Charge, integer slot returns boolean
if ID == .IDReq and Charge >= .ChargeReq then
set .slot = slot
set .Require = true
return true
endif
return false
endmethod
method Remove takes unit u returns nothing
local integer charge = 0
local item Item = null
set Item = UnitItemInSlotBJ(u, .slot)
set charge = (GetItemCharges(Item) -.ChargeReq)
if charge <= 0 then
call RemoveItem(Item)
else
call SetItemCharges(Item, charge)
endif
endmethod
method Reset takes nothing returns nothing
set .slot = 0
set .Require = false
endmethod
endstruct
struct CombineSystem
static ItemCommbine array Combines
static integer i = 0
static integer size = 0
private static method CheckCombine takes nothing returns boolean
local item Item = GetManipulatedItem()
local integer ItemID = GetItemTypeId(GetManipulatedItem())
local unit u = GetTriggerUnit()
local integer n = 1
local integer i = 1
local ItemCommbine Combine
local item array Inv
local boolean array UsedSlot
//Put all recipe in powerup type item, and take it have skill: Check Ability 'C000'
if GetItemType(Item) == ITEM_TYPE_POWERUP and.Find(ItemID) != 0 then
// call BJDebugMsg("Check")
call .Find(ItemID).Reset()
set Combine =.Find(ItemID)
//
set n = 1
loop
exitwhen n > UnitInventorySize(u)
set Inv[n] = UnitItemInSlotBJ(u, n)
set UsedSlot[n] = false
set n = n + 1
endloop
//
set n = 1
loop
exitwhen n > bj_MAX_INVENTORY
if Combine.Items[n].IDReq != 0 then
set i = 1
loop
exitwhen i > UnitInventorySize(u)
if Inv[i] != null and UsedSlot[i] == false then
if Combine.Items[n].Check(GetItemTypeId(Inv[i]), GetItemCharges(Inv[i]), i) then
set UsedSlot[i] = true
exitwhen true
endif
endif
set i = i + 1
endloop
endif
set n = n + 1
endloop
if Combine.Match() then
// call BJDebugMsg("Match")
call Combine.GiveCombineItem(u)
// You can make call something here if combine is success
else
// call BJDebugMsg("Unmatch")
// You can make call something here if combine is fail
endif
set Combine = 0
endif
return false
endmethod
static method New takes nothing returns nothing
set .i =.i + 1
set .Combines[.i] = ItemCommbine.create()
call .Combines[.i].Setup()
set .size = 0
endmethod
static method CombineResult takes integer id , integer charge returns nothing
set .Combines[.i].CombineID = id
set .Combines[.i].Charge = charge
endmethod
static method RecipePowerUp takes integer id returns nothing
set .Combines[.i].RecipeID = id
endmethod
static method ItemRecipe takes integer id , integer charge returns nothing
set .size = .size + 1
set .Combines[.i].Items[size].IDReq = id
set .Combines[.i].Items[size].ChargeReq = charge
endmethod
private static method SetupEvent takes nothing returns nothing
set udg_EventSettingCombine = 1.00
call DestroyTimer(GetExpiredTimer())
endmethod
private static method Find takes integer recipeid returns ItemCommbine
local ItemCommbine Combine = 0
local integer n = 1
loop
exitwhen n >.i
if .Combines[n].RecipeID == recipeid then
return .Combines[n]
endif
set n = n + 1
endloop
return Combine
endmethod
private static method onInit takes nothing returns nothing
local trigger UseRecipe = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(UseRecipe, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(UseRecipe, function thistype.CheckCombine)
call TimerStart(CreateTimer(), 0, false, function thistype.SetupEvent)
endmethod
endstruct
// Put all constant ID Item here, use Ctrl + D in object manager to see it
globals
constant integer ORB_OF_FROST = 'I002'
constant integer STEEL_SWORD = 'I001'
constant integer Frostmune = 'I003'
//Charge
constant integer GREATER_HEALING = 'pghe'
constant integer GREATER_MANA = 'pgma'
constant integer Replenishment_Potion = 'rej3'
//Recipe
constant integer Replenishment_Potion_RECIPE = 'C000'
constant integer Frostmune_RECIPE = 'C001'
endglobals
struct WeaponCombine
private static method Update takes nothing returns nothing
//Add more item type Weapon here
call CombineSystem.New()
//Input ItemRecipeID
call CombineSystem.RecipePowerUp(Frostmune_RECIPE)
//input ItemID, Charge
call CombineSystem.ItemRecipe(ORB_OF_FROST,0) //0 Is Equipment
call CombineSystem.ItemRecipe(STEEL_SWORD,0)
//Input ItemID, Charge
call CombineSystem.CombineResult(Frostmune,0)
//New Item
call CombineSystem.New()
call CombineSystem.RecipePowerUp(Frostmune2_RECIPE)
call CombineSystem.ItemRecipe(ORB_OF_FROST2,0) //0 Is Equipment
call CombineSystem.ItemRecipe(STEEL_SWORD2,0)
call CombineSystem.CombineResult(Frostmune2,0)
endmethod
private static method onInit takes nothing returns nothing
local trigger Setting = CreateTrigger()
call TriggerRegisterVariableEvent( Setting, "udg_EventSettingCombine", EQUAL, 1.00 )
call TriggerAddAction( Setting, function thistype.Update )
// call TimerStart(CreateTimer(), 0, false, function thistype.SetupEvent)
endmethod
endstruct
struct ChargeCombineCombine
private static method Update takes nothing returns nothing
call CombineSystem.New()
call CombineSystem.RecipePowerUp(Replenishment_Potion_RECIPE)
call CombineSystem.ItemRecipe(GREATER_HEALING,1) //0 Is Equipment
call CombineSystem.ItemRecipe(GREATER_MANA,1)
call CombineSystem.CombineResult(Replenishment_Potion,1)
endmethod
private static method onInit takes nothing returns nothing
local trigger Setting = CreateTrigger()
call TriggerRegisterVariableEvent( Setting, "udg_EventSettingCombine", EQUAL, 1.00 )
call TriggerAddAction( Setting, function thistype.Update )
// call TimerStart(CreateTimer(), 0, false, function thistype.SetupEvent)
endmethod
endstruct