| 01-15-2010, 12:21 PM | #1 |
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 |
There is a native GetItemCharges(myItem). You simply do the following: JASS:call SetItemCharges(Item3, GetItemCharges(Item1)+GetItemCharges(Item2)) Also, moved to the proper forum. |
| 01-16-2010, 05:25 PM | #3 |
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 |
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 |
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 |
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 |
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
endifCode:
if(condition1)then
//some code
if(condition2)then
//some more code
if(condition3)then
//even more code
endif
endif
endifHowever here's the code. JASS:function Trig_Item2_Actions takes nothing returns nothing //Configuration part, can be done way better like anything with JNGP local integer MAX_CHARGES = 2 //Generic used variables //Unit picking up the item local unit u = GetTriggerUnit() //Picked up item local item picked_item = GetManipulatedItem() //Item in slot x local item slot_item = null //Item Id of picked item local integer picked_item_id = GetItemTypeId(picked_item) //Charges of the picked item local integer charges_source = GetItemCharges(picked_item) //Charges of Item in Slot x local integer charges_target = 0 //Loop integer to get all items //NOTICE: JASS Slots are most likely starting with 0 instead 1 local integer i = 0 //Checking for valid id, may be extended by the usage of or conditions if(picked_item_id=='I000')then //Looping through all item slots loop //Breaking loop when max slot is reached or no more charges can be transfered exitwhen i > 5 or charges_source <= 0 //Assigning item in slot to variable set slot_item = UnitItemInSlot(u,i) //Assigning current charges set charges_target = GetItemCharges(slot_item) //Is the item type in slot x equal to the picked up item //And don't have max charges already if (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then //If the addition of both charges is greater than the max allowed charges if(charges_target+charges_source>MAX_CHARGES)then //Set Charges to max allowed charges call SetItemCharges(slot_item,MAX_CHARGES) //And reduce the charge counter of the source item corresponding set charges_source = charges_source - (MAX_CHARGES - charges_source) //Else the charges from the picked up item can be transfered to the slot item completly else //Adding charges to slot item call SetItemCharges(slot_item,charges_target+charges_source) //No more charges left on the picked up item set charges_source = 0 endif endif //Increasing counter for the next item slot set i = i + 1 endloop //If the picked item has no more charges if charges_source == 0 then //Destroy the picked item call RemoveItem(picked_item) else //Else set the charges call SetItemCharges(picked_item,charges_source) endif endif //Cleaning up variables set picked_item = null set u = null set slot_item = null endfunction |
| 01-17-2010, 11:36 PM | #8 |
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 |
Ahh, my fault ... change this line JASS:if (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then JASS:if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then 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 JASS:set charges_source = charges_source - (MAX_CHARGES - charges_source) 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. JASS:function Trig_Item2_Actions takes nothing returns nothing //Configuration part, can be done way better like anything with JNGP local integer MAX_CHARGES = 2 //Generic used variables //Unit picking up the item local unit u = GetTriggerUnit() //Picked up item local item picked_item = GetManipulatedItem() //Item in slot x local item slot_item = null //Item Id of picked item local integer picked_item_id = GetItemTypeId(picked_item) //Charges of the picked item local integer charges_source = GetItemCharges(picked_item) //Charges of Item in Slot x local integer charges_target = 0 //Loop integer to get all items //NOTICE: JASS Slots are most likely starting with 0 instead 1 local integer i = 0 //Checking for valid id, may be extended by the usage of or conditions if(picked_item_id=='I000')then //Looping through all item slots loop //Breaking loop when max slot is reached or no more charges can be transfered exitwhen i > 5 or charges_source <= 0 //Assigning item in slot to variable set slot_item = UnitItemInSlot(u,i) //Assigning current charges set charges_target = GetItemCharges(slot_item) //Is the item type in slot x equal to the picked up item //And don't have max charges already if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then //If the addition of both charges is greater than the max allowed charges if(charges_target+charges_source>MAX_CHARGES)then //Set Charges to max allowed charges call SetItemCharges(slot_item,MAX_CHARGES) //And reduce the charge counter of the source item corresponding set charges_source = charges_source-(MAX_CHARGES-charges_target) //Else the charges from the picked up item can be transfered to the slot item completly else //Adding charges to slot item call SetItemCharges(slot_item,charges_target+charges_source) //No more charges left on the picked up item set charges_source = 0 endif endif //Increasing counter for the next item slot set i = i + 1 endloop //If the picked item has no more charges if charges_source == 0 then //Destroy the picked item call RemoveItem(picked_item) else //Else set the charges call SetItemCharges(picked_item,charges_source) endif endif //Cleaning up variables set picked_item = null set u = null set slot_item = null endfunction |
| 01-18-2010, 10:53 AM | #10 |
Very fast written function, but it should work. Stacks everything automaticly. 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 |
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: JASS:if(picked_item_id=='I000')then 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 ! |
