Quote:
Originally Posted by zer0.de
need help with this func.
Code:
;Global VAR
Global $GiftsID[2] = [21491,28434]
;helper
Func IDofItem($bagid, $slotid)
Return DllStructGetData(getitembyslot($bagid, $slotid), "ID")
EndFunc
Func IDofModel($bagid, $slotid)
Return DllStructGetData(getitembyslot($bagid, $slotid), "ModelID")
EndFunc
Func QuantityofItem($bagid, $slotid)
Return DllStructGetData(getitembyslot($bagid, $slotid), "Quantity")
EndFunc
;func with bug/error?
Func OpenGifts()
For $gifts = 0 to 2
For $i = 1 to $bags
For $j = 0 to $slots
$itemmodel = IDofModel($i, $j)
If $itemmodel = $GiftsID[$gifts] Then
$itemquantity = QuantityofItem($i, $j)
For $u = 1 to $itemquantity
$itemID = IDofItem($i, $j)
UseItem($itemID)
Next
Else
ExitLoop 4
EndIf
Next
Next
Next
EndFunc
The bot closes without an error.
I want to open all gifts in the bag. what is wrong with that?
Or is there a easy way to do that?
|
Your code literally says exit all loops (aka stop opening gifts) as soon as item in bag i and slot j is not a gift (aka ExitLoop 4)
See :
[Only registered and activated users can see links. Click Here To Register...]
I suspect that your item[1][1] is not a gift, that would explain the fact your bot does nothing.
Another important point, you need to put some Sleep between each UseItem() to let the server deal with your "command".
Last point, instead of using a for loop, I would have used a "Do Until" or a "While" to loop on gifts left quantity. That way, if a UseItem fail somehow, quantity will not decrease and your loop will still catch up.
In code, it should look something like this.
Code:
;func with bug/error?
If $itemmodel = $GiftsID[$gifts] Then
While QuantityofItem($i, $j) > 0
$itemID = IDofItem($i, $j)
UseItem($itemID)
Sleep(GetPing()+250)
WEnd
; No more ExitLoop since you still want to test the next item (item[i][j+1]
EndIf
Last point, assuming there are indeed 2 modelId for gifts (which I doubt), instead of doing a for loop "For $gifts = 0 to 2", you may take a look at the function _ArraySearch and do something like this "If _ArraySearch($GiftsID, $itemmodel) > 0 Then".
Code will be cleaner and "faster" since you will no longer parse your inventory twice.
[Only registered and activated users can see links. Click Here To Register...]