- Joined
- Mar 10, 2009
- Messages
- 5,016
I've been working on an item charges merger...I have tested it and it's OK but Im just posting it here to have some feedbacks if my tests are true...
JASS:
//System Name: Item Charges Merger
//Made by: Mckill2009
//REQUIRED VARIABLES:
//- HASH = hashtable (already initialize)
//INSTRUCTIONS:
//- Make a new trigger and convert to custom text
//- Copy ALL these codes and overwrite ALL existing text in the custom text
//- Make necessary changes of item type raw code
//===CONFIGURABLES:
constant function floatingtxt takes nothing returns string
return "Item type already full!" //Sets the floating text
endfunction
constant function maxItem takes nothing returns integer
return 10 //Max Item stack
endfunction
constant function item1 takes nothing returns integer
return 'wlsd' //Default Lightning Shield with 3 charges
endfunction
constant function item2 takes nothing returns integer
return 'will' //Default Wand of Illusion with 3 charges
endfunction
constant function item3 takes nothing returns integer
return 'wcyc' //Default Wand of the Wind with 3 charges
endfunction
//constant function item4 takes nothing returns integer
// return 'ANOTHER ITEM HERE' //Optional description
//endfunction
//===END OF CONFIGURABLES:
function onPick takes nothing returns nothing
local unit u = GetTriggerUnit()
local item it = GetManipulatedItem()
local item mainitem
local integer charges = GetItemCharges(it)
local integer i = 0
local integer id = GetHandleId(u)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local texttag tag
if GetItemCharges(it) > 0 then
//Saving the charges for Item 1
if GetItemTypeId(it)==item1() then
if not HaveSavedHandle(udg_HASH, id, 1) and GetItemTypeId(it)==item1() then
call SaveItemHandle(udg_HASH, id, 1, it)
elseif GetItemTypeId(it)==item1() and charges <= maxItem() then
set mainitem = LoadItemHandle(udg_HASH, id, 1)
if GetItemCharges(mainitem) <= maxItem() then
call SetItemCharges(mainitem, GetItemCharges(mainitem)+charges)
call SetItemCharges(it, 0)
else
call UnitDropItemPoint(u, it, x, y)
endif
else
call UnitDropItemPoint(u, it, x, y)
endif
endif
//Saving the charges for Item 2
if GetItemTypeId(it)==item2() then
if not HaveSavedHandle(udg_HASH, id, 2) and GetItemTypeId(it)==item2() then
call SaveItemHandle(udg_HASH, id, 2, it)
elseif GetItemTypeId(it)==item2() and charges <= maxItem() then
set mainitem = LoadItemHandle(udg_HASH, id, 2)
if GetItemCharges(mainitem) <= maxItem() then
call SetItemCharges(mainitem, GetItemCharges(mainitem)+charges)
call SetItemCharges(it, 0)
else
call UnitDropItemPoint(u, it, x, y)
endif
else
call UnitDropItemPoint(u, it, x, y)
endif
endif
//Saving the charges for Item 3
if GetItemTypeId(it)==item3() then
if not HaveSavedHandle(udg_HASH, id, 3) and GetItemTypeId(it)==item3() then
call SaveItemHandle(udg_HASH, id, 3, it)
elseif GetItemTypeId(it)==item3() and charges <= maxItem() then
set mainitem = LoadItemHandle(udg_HASH, id, 3)
if GetItemCharges(mainitem) <= maxItem() then
call SetItemCharges(mainitem, GetItemCharges(mainitem)+charges)
call SetItemCharges(it, 0)
else
call UnitDropItemPoint(u, it, x, y)
endif
else
call UnitDropItemPoint(u, it, x, y)
endif
endif
//Add another if/then here if you have more items
//This line removes the empty item
if GetItemCharges(it) < 1 then
call UnitDropItemPoint(u, it, x, y)
endif
if GetItemCharges(mainitem) >= maxItem() then
set tag = CreateTextTag()
call SetTextTagPos(tag, x, y, 150)
call SetTextTagText(tag, floatingtxt(), 0.025)
call SetTextTagPermanent(tag, false)
call SetTextTagVelocity(tag, 0.03, 0.03)
call SetTextTagLifespan(tag, 3)
call SetTextTagFadepoint(tag, 0.01)
endif
else
//Drops item automatically if empty
call UnitDropItemPoint(u, it, x, y)
endif
set u = null
set it = null
set mainitem = null
endfunction
function onDrop takes nothing returns nothing
local unit u = GetTriggerUnit()
local item it = GetManipulatedItem()
local integer id = GetHandleId(u)
if it==LoadItemHandle(udg_HASH, id, 1) then
call RemoveSavedHandle(udg_HASH, id, 1)
elseif it==LoadItemHandle(udg_HASH, id, 2) then
call RemoveSavedHandle(udg_HASH, id, 2)
elseif it==LoadItemHandle(udg_HASH, id, 3) then
call RemoveSavedHandle(udg_HASH, id, 3)
//elseif it==LoadItemHandle(udg_HASH, id, 4) then
//call RemoveSavedHandle(udg_HASH, id, 4)
endif
set u = null
endfunction
function onCond takes nothing returns boolean
local item it = GetManipulatedItem()
return GetItemTypeId(it)==item1() or GetItemTypeId(it)==item2() or GetItemTypeId(it)==item3()
endfunction
function InitTrig_ItemChargesMerger takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t1, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddCondition(t1, Condition(function onCond))
call TriggerAddAction(t1, function onPick)
call TriggerAddAction(t2, function onDrop)
set udg_HASH = InitHashtable()
set t1 = null
set t2 = null
endfunction