HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to combine Charges on item with a limite?

01-15-2010, 12:21 PM#1
GolluM[KoMe]
I don't manage to combine item charges: (with (x) as the charge of the SAME kind of item)

By exemple for an item with a limite of 3 :
item(1) +item(1) = item(2)
item(2) +item(1) = item(3)
item(3) +item(1) = item(3) + item(1)
item(3) + item(1) + item(1)= item(3) + item(2) Etc...

Can anyone help me ?

PS : i just suck in JASS ...
01-15-2010, 02:32 PM#2
Rising_Dusk
There is a native GetItemCharges(myItem). You simply do the following:
Collapse JASS:
call SetItemCharges(Item3, GetItemCharges(Item1)+GetItemCharges(Item2))

Also, moved to the proper forum.
01-16-2010, 05:25 PM#3
GolluM[KoMe]
Hum in fact you might have not understood my problem, I shouldn't have express it well.
I wanna make a trigger that when a unit picks up a charged item(1) (with (1) as the charge of the item) and if he already had an item(1) of the same kind, it removes the new item and give a second charge to the second.

In fact I want to do the condition :
"If the unit has 2 items of type X with both a charge of 1"

It's absolutely impossible in GUI and I tried in JASS (by searching the functions/natives) in Jass Shop Pro, but I just suck :) (I don't know how to combine conditions in one).
01-16-2010, 11:47 PM#4
TEC_Ghost
You'll have to check his inventory each time and see if he has a matching Item, then remove item if all of it's charges get transferred to the other item, otherwise just set it's charges to the remaining.


Unit Acquires an Item > Inventory Check > Actions
01-17-2010, 07:13 PM#5
GolluM[KoMe]
Thx for the replies, but you know, I rlly suck in JASS ...
Is doing it that way would work ? :

unit get a new item

IF itemId of manipulated item = X and number of charge of manipulated item = 1 then
local integer a=0
If triggerUnit has in slot 1 a item matching (itemId of matching item = itemId of manipulatedItem + number of charge of matching item = 1) then
set integer a=a+1
endif
If triggerUnit has in slot 2 a item matching (itemId of matching item = itemId of manipulatedItem + number of charge of matching item = 1) then
set integer a=a+1
endif
....etc in each slots
If a=2 then
(Then remove all items of type X with a charge of 1 from each slot
create a item of type X with 2 charges for the unit)
ENDIF


Plz if you know how, tell me how do we do that , it would be sooo helpful !
Thank you in advance !!!
01-17-2010, 08:47 PM#6
GolluM[KoMe]
Collapse JASS:
function Trig_Item2_Actions takes nothing returns nothing

if ((GetItemTypeId(GetManipulatedItem()) == 'I000' ) And (GetItemCharges(GetManipulatedItem())=1 )) then
   local integer a=0
  if (GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), 1)) == GetItemTypeId(GetManipulatedItem())) And GetItemCharges(UnitItemInSlot(GetTriggerUnit(), 1))=1 then
    set a=a+1
    call UnitRemoveItemFromSlot(GetTriggerUnit(), 1)
  endif
  if (GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), 2)) == GetItemTypeId(GetManipulatedItem())) And GetItemCharges(UnitItemInSlot(GetTriggerUnit(), 2))=1 then
    set a=a+1
    call UnitRemoveItemFromSlot(GetTriggerUnit(), 2)
  endif
  if (GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), 3)) == GetItemTypeId(GetManipulatedItem())) And GetItemCharges(UnitItemInSlot(GetTriggerUnit(), 3))=1 then
    set a=a+1
    call UnitRemoveItemFromSlot(GetTriggerUnit(), 3)
  endif
  if (GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), 4)) == GetItemTypeId(GetManipulatedItem())) And GetItemCharges(UnitItemInSlot(GetTriggerUnit(), 4))=1 then
    set a=a+1
    call UnitRemoveItemFromSlot(GetTriggerUnit(), 4)
  endif
  if (GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), 5)) == GetItemTypeId(GetManipulatedItem())) And GetItemCharges(UnitItemInSlot(GetTriggerUnit(), 5))=1 then
    set a=a+1
    call UnitRemoveItemFromSlot(GetTriggerUnit(), 5)
  endif
  if (GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), 6)) == GetItemTypeId(GetManipulatedItem())) And GetItemCharges(UnitItemInSlot(GetTriggerUnit(), 6))=1 then
    set a=a+1
    call UnitRemoveItemFromSlot(GetTriggerUnit(), 6)
 endif
   if a==1 then
    call UnitAddItemById(GetTriggerUnit(), 'I000' )
   endif
   if a==2 then
    call UnitAddItemById(GetTriggerUnit(), 'I000' )
    call SetItemCharges(GetLastCreatedItem(), 2 )
   endif
endif

endfunction

Well I made that ugly thing (don't laugh I learnt JASS yesterday (Many thanks to Vexorian btw)). It just doesnt work because of many reasons ... The big one is that we can't put an if into an other if ... but I don't know how to do else.
The other main problem is that we can't put an And beetween 2 things to check in a if/then.
I am also not sure about the GetLastCreatedItem to get the added item ....
Can anyone correct it ?
Thanks !
01-17-2010, 10:33 PM#7
Fireeye
Just a fast made rewrite of your function, don't have any syntax checker here atm.
I hope there are no errors and hopefully i wrote enough explanations.
About that And, write it small and you can do it like this:
Code:
if((condition1)and(condition2)and(condition3))then
    //some code
endif
You can also nest (i hope i'm not mistaken with 'nest', kinda sleepy) if's
Code:
if(condition1)then
    //some code
    if(condition2)then
        //some more code
        if(condition3)then
            //even more code
        endif
    endif
endif
GetLastCreatedItem() will refer as its name says to the last item created in game, but you need to refer to the item in slot x or the picked up item in this case.
However here's the code.
Expand JASS:
I hope you can learn something from it, could be way better written in vJASS, but you don't seem to have JNGP so i sticked with class JASS.
01-17-2010, 11:36 PM#8
GolluM[KoMe]
Wahow your function owns xD! But it has one problem: it works only if the unit already had one of this item in its inventory before. If it doesn't, the taken item is just destroyed xD. And it does the same if there is an empty slot before the item, it must be the same problem...
An other problem is that when the Max Charge is 2 by exemple and that when the unit has an Item(1) and get an item(2) it makes 2 items(2) in its inventory ... ^^
I'll try to fix it but if anyone can help me .... :)
Anyway very very well done ! + all these explanations ... I don't deserve that xD. + you teached me some basic ...
Thank you sooooo much fired skull !
01-18-2010, 10:40 AM#9
Fireeye
Ahh, my fault ...
change this line
Collapse JASS:
if (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
into this
Collapse JASS:
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
The reason is quite simple, when you pick up an item, it will even check up the picked item.
Therefore we need to make sure that the checked item is not equal to the picked item.

---EDIT---
And the second problem was a typo ...
replace
Collapse JASS:
set charges_source = charges_source - (MAX_CHARGES - charges_source)
with
Collapse JASS:
set charges_source = charges_source-(MAX_CHARGES-charges_target)

Here's the entire script again, i tested it and i should not have any problems anymore.
Expand JASS:
01-18-2010, 10:53 AM#10
Anachron
Very fast written function, but it should work.
Stacks everything automaticly.

Collapse JASS:
function stackItems takes unit u returns nothing
    local integer i = 0
    local item tmp = null
    local item cur = null
    
    loop
        set cur = UnitItemInSlot(u, i)
        exitwhen i >= 5 or cur == null
        
        if GetItemTypeId(cur) == GetItemTypeId(tmp) and GetItemCharges(cur) != 0 and cur != tmp then
            call SetItemCharges(cur, GetItemCharges(tmp) + GetItemCharges(cur))
            call RemoveItem(tmp)
        endif
        
        if cur != null then
            set tmp = cur
        endif
        
        set i = i +1
    endloop
endfunction
01-18-2010, 01:16 PM#11
GolluM[KoMe]
Ye Anachron it works really good ! But with your code, there are no limits ...
Thx man ! if once i need a unlimited item charge compilation, I'll take yours :)

Ow it works like hell , Sauron ! (fireeye ---> sauron ---> Hahaha, so funny).
But there is still a "bug": If Max Charge is 2 by exemple and that when the unit has an Item(1) and get an item(2) it makes 2 items(2) in its inventory ... ^^
Maybe should I just replace:
Collapse JASS:
    if(picked_item_id=='I000')then
By :
Collapse JASS:
    if ((picked_item_id=='I000') and (GetItemCharges(picked_item) < MAX_CHARGES )) then

Post edited: Yeeeee it woooorks :). I love u all guys; Huge Thx ! now I can tidy my Precious !