• 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 1.x] Player:addItemFromUsedItemContainer

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
based on this request
This would be good in case you have to do something like obsidian knife where you want to add a new item to the player depending where the knife is located, so if the knife is on container it would be added to that container, else it will be given to the player to another container. If the obsidian knife is used on the floor is added to that position

Code:
function Player:addItemFromUsedItemContainer(item, fromPos, addItemId, amount) --lol name
    if (not item or not item:isItem())  then return false end
    if (not ItemType(addItemId)) then return false end

    if (fromPos.x == CONTAINER_POSITION) then --check if is from container
       if (not item:getParent():addItem(addItemId, amount)) then --check if could be added to that container where the item is located
           self:addItem(addItemId, amount) --add to player if couldn't be added to that container
       end
    else
       Game.createItem(addItemId, amount, fromPos) --item is on the ground, is created there
    end
end
 
i think it would be better this name "Player:addItemOnUsedItemContainer" but i can't edit post, so...
 
This is great! I will use it in my fishing and potions script!
I hate it, that you always get the empty potion in your main backpack, when the potions are located somewhere else. Even if you drink out of a corpse
 
Back
Top