Sir Richard
New Member
I've been trying to come up with a solution for the following problem:
A player uses an item which is supposed to be transformed into a random item, but the used item is stackable, and when the action happens, the whole stack is transformed to the reward. e.g.: the player uses a stack of 'concentrated demonic blood', but all of it becomes the same item.
While I could be simply adding the item to the player (player:addItem), it should be transformed to the current place where the item stands, be it on a secondary backpack, the floor, the inside of a depot, etc...
My question is, how do I use item:transform in a way that it only transforms one item of the stack, into the desired reward (be it 1 ... n items), on the current position (ground, backpack, dp...)?
Alternatively, is there a way to use 'Game.createItem' as a solution? (I've attempted this, but if used inside of a container, no item is created inside of it, since to/fromPosition/item:getPosition()) onnly works outside of a container)
What I've attempted thus far:
Sorry it it's an easy one, but it's been a while since I worked on ots lol
A player uses an item which is supposed to be transformed into a random item, but the used item is stackable, and when the action happens, the whole stack is transformed to the reward. e.g.: the player uses a stack of 'concentrated demonic blood', but all of it becomes the same item.
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
item:getPosition():sendMagicEffect(CONST_ME_DRAWBLOOD)
item:transform(math.random(7588, 7589))
return true
end
While I could be simply adding the item to the player (player:addItem), it should be transformed to the current place where the item stands, be it on a secondary backpack, the floor, the inside of a depot, etc...
My question is, how do I use item:transform in a way that it only transforms one item of the stack, into the desired reward (be it 1 ... n items), on the current position (ground, backpack, dp...)?
Alternatively, is there a way to use 'Game.createItem' as a solution? (I've attempted this, but if used inside of a container, no item is created inside of it, since to/fromPosition/item:getPosition()) onnly works outside of a container)
What I've attempted thus far:
Code:
item:transform(itemId, count)
&
Game.createItem(itemId, count, toPosition)
Sorry it it's an easy one, but it's been a while since I worked on ots lol