• 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+ Crowbar in Mailbox <3 tfs 1.5

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
928
Solutions
7
Reaction score
127
Location
Brazil
YouTube
caruniawikibr
hello I'm trying to do a postman mission, when using the crowbar in the mailbox I get the storage and the message. but I couldn't. it works just by using the mailbox directly without needing the crowbar. can anybody help me? :)

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)

local mailuid = 10168
local storage = 100171
local getstorage = getPlayerStorageValue(cid, storage)

    if(getstorage == 7) then
        setPlayerStorageValue(cid, 100168, 6)
        setPlayerStorageValue(cid, 100169, 1)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
        else
        setPlayerStorageValue(cid, 100168, 6)
        setPlayerStorageValue(cid, 10169, 1)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_BLUE)
    return true
end
end
 
I have made something similar that should be possible to use here. I have modified it to suit your needs.

Lua:
local crowbarMailboxQuest = Action()

function crowbarMailboxQuest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local mailuid = 10168
   local storage = 100171
   local getstorage = player:getStorageValue(storage)
    if (target.uid == mailuid) and (getstorage == 7) then
      --Execute your code here
    else
        --Do your else statement here. I think you should concider making some changes to your things here.
        -- (Are you sure you wish to set the storagevalue to 6 both if the storage is 7 and if it isn't? Then what good is the if-statement?)
        -- (Also, a player could spam the mailbox with the crowbar and get repeated questlog updates every time, which would be weird...)
    end
  
    return true
end

crowbarMailboxQuest:id(2416)
crowbarMailboxQuest:register()

A last thing. You probably have to make some changes to the crowbar.lua file, otherwise you would have two different scripts running from the same itemid, which is problematic.


Actually, you could just edit your crowbar.lua script. I'm going to leave the first code thing anyway, because that is how you usually solve these kinds of things: with a revscript.

But right now, you can change crowbar.lua into:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local mailuid = 10168
    local mailboxitemid = 2416 -- Set the itemid of the mailbox you are using here!!
    if (item.itemid == mailboxitemid) and (item.uid == mailuid) then
        local storage = 100171
        local getstorage = player:getStorageValue(storage)
        if(getstorage == 7) then
            player:setStorageValue(100168, 6)
            player:setStorageValue(100169, 1)
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
        else
            player:setStorageValueStorageValue(cid, 100168, 6)
            player:setStorageValueStorageValue(cid, 10169, 1)
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_BLUE)
        end
    end
    return onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
end


But once again, if you use the second code, you should revise whether you really want essentially the same thing happening no matter what the player storageid is...
This code is not tested, but should work :rolleyes:
 
ty i will test <3

there's another one that also needs to use an item, but I don't know how it would look because it has storages with -1, could you say how it would look?

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStorageValue(cid, 10174) == -1 and doPlayerTakeItem(cid, 2330, 1) then
            setPlayerStorageValue(cid, 10174, 1)
            setPlayerStorageValue(cid, 100168, 37)
            doPlayerRemoveItem(cid, 2330, 1)
            doPlayerAddItem(cid, 1993, 1)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You send mails.")
    return true
    end
    if getPlayerStorageValue(cid, 10174) == 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have mails.")
    end
    return true
end
Post automatically merged:

ahhhh no work :/
 
Last edited:
Your problem description is unclear. I will try to describe what you have to do to activate a script with an item.

To activate a script using an item you have to register that item to run a script.
The original TFS mainly uses the actions.xml and movements.xml to register items to scripts.

If you look inside actions.xml you will find a row containing the itemid of the crowbar. Use the search function and search for "2416" or "crowbar" inside actions.xml to find this reference. This XML reference tells the game to run "data/actions/scripts/tools/crowbar.lua"when an item with itemid 2416 is used. If you wish to change how the game reacts when the crowbar is used, you must therefore change what happens in the crowbar.lua script, otherwise it will conflict with your script. This is the original crowbar.lua:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    return onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
end

So what you need to do is to edit ^this^ script so that it also contains your special script. <--- very important!

Now, you probably still want to preserve the original crowbar function. Because of this, you need to add a condition that describes the exact conditions of when your special code should be executed instead of the standard crowbar script. Your condition description needs to be exact and deterministic, to make sure it does not activate when it should not.

Here is how I suggest that you can do this.
The script is unfinished, and contains some clues for you. Hopefully this will help you understand how to finish your script and tailor it to your preferences.

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local mailboxitemids = {2334, 2416, 2596, 3981, 26055, 26056, 26057, 26058} -- I added all kinds of mailboxed in a table, to make sure anything works. Remove whatever id you don't want to be able to run the script from.
    if table.contains(mailboxitemids, target.itemid) then
        local storage = 10174
        local getstorage = player:getStorageValue(storage)
        if(getstorage == -1) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You executed the script correctly!")
            --player:setStorageValue(storage, 1) -- Use this to make the game remember that the player has used it. For now, just send yourself messages to help yourself understand what works and what doesn't.
            --player:addItem(2330, 1) -- This gives the player a bunch of letters
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
        else
            -- This is what happens if the given conditions are not met.
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This players storage value is not -1. The storage value is " .. player:getStorageValue(storage) .. ".")
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_BLUE)
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The game did not register that the crowbar was used on a mailbox!")
    end
    return onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
end

Hope this will help you! I have added a bunch of player:sendTextMessage() functions, to send you error messages. These are obviously not needed for the final script to function, so remove them when you no longer need them. Good luck @bpm91 ! 😄
 
thank you very much friend, I will test your script <3 the crowbar I understand what you said. but it hadn't worked. I managed to fix it in a different way. I will try the Santa bag, thanks <3
Post automatically merged:

I tested it and it didn't work, the only way I could do it was like this.

<action itemid="2416" script="tools/crowbar.lua" />
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2593 and target.uid == 10168 then
        if player:getStorageValue(100171) == 8 then
            player:setStorageValue(10169, 1)
            player:setStorageValue(100168, 6)
            player:setStorageValue(100169, 1)
            player:setStorageValue(100171, 9)
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
            return true
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end
    return destroyItem(player, target, toPosition)
end


But now I'm having problems with Santa's letterbag mission. I've tried everything.

<action uniqueid="10174" script="postman quest actions/postmanQuestMail.lua" />
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local mailuid = 10174

    if target.itemid == 2334 and (item.uid == mailuid)  then
        if player:getStorageValue(10174) == -1 then
            player:setStorageValue(100168, 37)
            player:setStorageValue(10174, 1)
            player:addItem(1993, 1)
            item:remove(1)
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You send mails.")
            return true
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have mails.")
            return false
        end
    end
    return true
end

I need to use the letterbag on maibox id 2334 (santa box)
and aid 10174
but no work use on bag and after in box.
WhatsApp Image 2022-10-08 at 15.32.31.jpeg
 
Last edited:
thank you very much friend, I will test your script <3 the crowbar I understand what you said. but it hadn't worked. I managed to fix it in a different way. I will try the Santa bag, thanks <3
Post automatically merged:

I tested it and it didn't work, the only way I could do it was like this.

<action itemid="2416" script="tools/crowbar.lua" />
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2593 and target.uid == 10168 then
        if player:getStorageValue(100171) == 8 then
            player:setStorageValue(10169, 1)
            player:setStorageValue(100168, 6)
            player:setStorageValue(100169, 1)
            player:setStorageValue(100171, 9)
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
            return true
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end
    return destroyItem(player, target, toPosition)
end


But now I'm having problems with Santa's letterbag mission. I've tried everything.

<action uniqueid="10174" script="postman quest actions/postmanQuestMail.lua" />
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local mailuid = 10174

    if target.itemid == 2334 and (item.uid == mailuid)  then
        if player:getStorageValue(10174) == -1 then
            player:setStorageValue(100168, 37)
            player:setStorageValue(10174, 1)
            player:addItem(1993, 1)
            item:remove(1)
            doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You send mails.")
            return true
        else
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have mails.")
            return false
        end
    end
    return true
end

I need to use the letterbag on maibox id 2334 (santa box)
and aid 10174
but no work use on bag and after in box.
View attachment 71043
You should have all the functions and syntax you need to make this happen. Just take it one step at a time and make sure that every single step works the way you want. Don't use the player:setStorageValue() function until you are 100% certain that it works. Instead, use the player:sendTextMessage() to make sure that the values are what you expect.

Another thing I have noticed with your code is that you are trying to use the parameter cid, this won't work because you have the parameter player in your main function
( function onUse(player, item, fromPosition, target, toPosition, isHotkey)

Make sure that you read the error messages and figure out the code one step at a time and you should be able to work this out! I've got faith in you buddy! Good luck!
 
Back
Top