• 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+ Item reference

czouski

Banned User
Joined
Nov 2, 2024
Messages
166
Solutions
1
Reaction score
64
I am trying to make unique item that is a lootbag for a player.
I want player to have max of 3 lootbags
I want to reference those lootbags in player storage somehow.
so that he cant create more than 3 but also if he has the 3 base storages full of items and they exist in game world ( engine memory) to prevent him from making more

tl;dr if impossible i will add a banishment for a day if player makes more than 10 in short time span to prevent griefers or some shit.
LUA:
local talkaction = TalkAction("!lootbag")

function talkaction.onSay(player, words, param)
    -- Get item in the player's left or right slot
    local itemLeft = player:getSlotItem(CONST_SLOT_LEFT)
    local itemRight = player:getSlotItem(CONST_SLOT_RIGHT)

    -- Check if either left or right slot has item 1987
    local item = itemLeft and itemLeft:getId() == 1987 and itemLeft or (itemRight and itemRight:getId() == 1987 and itemRight)
    print(item)
    -- If the player doesn't have the item in either slot, show a message
    if not item then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You need to have item 1987 in either the left or right slot to use this command.")
        return
    end

    -- Get the item description
    local description = item:getDescription():lower()  -- Convert description to lowercase
    local playerName = player:getName()  -- Get the player's name in lowercase

    -- Pattern to match "It weighs X.XX oz."
    local weightPattern = "it weighs %d+%.%d%d oz%."

    -- Check if description matches the weight pattern
    if string.find(description, weightPattern) then
        -- Find the part of the description after the weight pattern
        local postWeightText = description:match(weightPattern .. "(.*)"):gsub("^%s*(.-)%s*$", "%1")  -- Trim whitespace

        -- If there's no text after "oz.", add the player's name in the description
        if postWeightText == "" then
            -- Update the description with the player's name
            local newDescription = playerName
            item:setAttribute("description", newDescription)
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You are now protecting this bag.")
        elseif postWeightText == playerName then
            -- If the name matches the description, allow the item move (e.g., for looting or another action)
            player:sendTextMessage(MESSAGE_STATUS_INFO, "You are already a owner of this lootbag.")
        else
            -- If the name does not match the description, show a warning
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot loot this item because the description does not match your name.")
        end
    else
        -- If the description doesn't match the pattern, show a warning
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The item description doesn't have a valid weight pattern.")
    end
end

talkaction:register()
Post automatically merged:

another work aroudn im thinking is because i have event for moving it to save the items position when player moves it into his storage but there could be issues when its in depo or something
Post automatically merged:

I have the appropriate events in player.lua the else messages can be ignored
 
Last edited:
I dont fully understand your solution and i dont see storage values used there. (Is it like an autolooting to those bags) ?
But since you're using
LUA:
getSlotItem
that lootbag has to be in player's inventory slot ?
If so you can use movement script for ID 1987 to define custom onEquip onDeEquip functions
LUA:
function onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end
    --check current lootbags count in storage
    local currentLootbags = player:getStorageValue(LOOT_BAG_STORAGE)
    if (currentLootbags >= 3) then
        player:sendCancelMessage("You have reached the maximum amount of lootbags.")
        return false
    end
    player:setStorageValue(LOOT_BAG_STORAGE, currentLootbags + 1)
    return true
end
function onDeEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end
    local currentLootbags = player:getStorageValue(LOOT_BAG_STORAGE)
    player:setStorageValue(LOOT_BAG_STORAGE, currentLootbags - 1)
    return true
end
end
 
I want to be able to reference the item after server save and so on so if player has 3 of those items I want him not to be able to create more.
the bag can not be opened by other players ( onUse function is doing that)
the bag can not be moved by other players (events onMoveItem ) does that
now I want to restrict how many of them player can have.
 

Similar threads

V
Replies
2
Views
125
Back
Top