• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X Use all stackable itens in action

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Hi guys, how are you?

I have an action who i use an item and it give 1 premium point to me. There is a way to use all stackable itens? When i click on pile with 100 itens, it use only one, i want to use all itens in a stack and add all points referent a stack. My action:

Lua:
function onUse(cid, item, frompos, item2, topos)
local points = 1
doAccountAddPoints(cid, points)
doRemoveItem(item.uid, 1)
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You received "..points.." premium points.")
end
 
Solution
Hi guys, how are you?

I have an action who i use an item and it give 1 premium point to me. There is a way to use all stackable itens? When i click on pile with 100 itens, it use only one, i want to use all itens in a stack and add all points referent a stack. My action:

Lua:
function onUse(cid, item, frompos, item2, topos)
local points = 1
doAccountAddPoints(cid, points)
doRemoveItem(item.uid, 1)
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You received "..points.." premium points.")
end
item.type get's the count of the stackable items.
There is a bit of nuance when using it, but in this situation, since we know the item being used is stackable (due to actions.xml itemid being used to direct it to...
mby this
Lua:
function onUse(cid, item, frompos, item2, topos)
    local count = item:getCount()
    doAccountAddPoints(cid, count)
    doRemoveItem(item.uid, count)
    return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. count .. " premium points.")
end
 
mby this
Lua:
function onUse(cid, item, frompos, item2, topos)
    local count = item:getCount()
    doAccountAddPoints(cid, count)
    doRemoveItem(item.uid, count)
    return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. count .. " premium points.")
end
got an error on console when try to use:

1635638755773.png
 
Last edited:
you need to transform the code to your tfs version, links was just an example of latest version
Post automatically merged:

not sure which version you use since it only says 0.x, but can also try if you have getPlayerItemCount
Lua:
function onUse(cid, item, frompos, item2, topos)
    local count = getPlayerItemCount(cid, item.itemid)
    doAccountAddPoints(cid, count)
    doRemoveItem(item.uid, count)
    return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. count .. " premium points.")
end
 
Last edited:
you need to transform the code to your tfs version, links was just an example of latest version
Post automatically merged:

not sure which version you use since it only says 0.x, but can also try if you have getPlayerItemCount
Lua:
function onUse(cid, item, frompos, item2, topos)
    local count = getPlayerItemCount(cid, item.itemid)
    doAccountAddPoints(cid, count)
    doRemoveItem(item.uid, count)
    return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. count .. " premium points.")
end
Thanks my friend, it worked but I found a bug: if I have a single stack with 100, it uses and disappears. But if I have two stacks of 100 and I use one, it adds 200 points and doesn't remove any of the stacks. Or if 1 have one stack of 20 and another one of 80, it uses 100 and remove no one os stacks.

1635641830003.png
 
Last edited:
ye its not the best function to use since it counts all items in your inventory.
can link the distro that you are using?
 
function onUse(cid, item, frompos, item2, topos)
local count = getPlayerItemCount(cid, item.itemid)
If count > 100 then count = 100 end
doAccountAddPoints(cid, count)
doRemoveItem(item.uid, count)
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. count .. " premium points.")
end
 
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local pointsCount = getPlayerItemCount(cid, item.itemid)
    doPlayerRemoveItem(cid, item.itemid, pointsCount)
    doAccountAddPoints(cid, pointsCount)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You received "..pointsCount.." premium points.")
    return true
end
 
Hi guys, how are you?

I have an action who i use an item and it give 1 premium point to me. There is a way to use all stackable itens? When i click on pile with 100 itens, it use only one, i want to use all itens in a stack and add all points referent a stack. My action:

Lua:
function onUse(cid, item, frompos, item2, topos)
local points = 1
doAccountAddPoints(cid, points)
doRemoveItem(item.uid, 1)
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You received "..points.." premium points.")
end
item.type get's the count of the stackable items.
There is a bit of nuance when using it, but in this situation, since we know the item being used is stackable (due to actions.xml itemid being used to direct it to this script) we don't need to do further checks.
For future, you can see me using this method in this example function
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local points = item.type
    doAccountAddPoints(cid, points)
    doRemoveItem(item.uid)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You received " .. points .. " premium points.")
    return true
end
 
Solution
item.type get's the count of the stackable items.
There is a bit of nuance when using it, but in this situation, since we know the item being used is stackable (due to actions.xml itemid being used to direct it to this script) we don't need to do further checks.
For future, you can see me using this method in this example function
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local points = item.type
    doAccountAddPoints(cid, points)
    doRemoveItem(item.uid)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You received " .. points .. " premium points.")
    return true
end
Worked, thank you Xiki!
 
Back
Top