• 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!

Lua Attempting to understand the Purse (TFS 1.4)

captcarl

New Member
Joined
Apr 3, 2022
Messages
11
Reaction score
3
Goal: I want a player to be able to always have a specific item in their purse which never moves. With this item, I'm going to setup an onUse script to pop-up a modalWindow for various things. This will function as a low effort custom menu within OTClient.

Issue: I'm not able to figure out how to create/place an item into a player's purse (my own or otherwise). For testing, I'm using a talk action registered with this lua script

Lua:
function onSay(player, words, param)
        local purse = player:getSlotItem(CONST_SLOT_PURSE)
        if purse then
            purse:addItem(1949, 100)
        end
end

XML:
<talkaction words="/scroll" separator=" " script="addscroll.lua" />

I don't think it can get any more bare bones for a test run, but this results in nothing happening and nothing being returned/errors in console.

Does anyone know the correct syntax/functions to best accomplish this?

PS. The 2nd bit I'll need help on is maintaining a static item which can't be moved/removed/deleted from every player's purse (if this is even possible)
 
Pretty sure the 'purse' acts the same as the store inbox.


Follow above functions, don't remove the 'storeItem' from the item, and put it in the purse, instead of the store inbox.
That will make it impossible to be removed from the purse.. with the exception of the depot.

To stop that, just make a simple onMove script
Lua:
local disabledItems = {1111, 2222, 3333}

local disableMovingItems = EventCallback

disableMovingItems.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if table.contains(disabledItems, item:getId()) then
        return false
    end
    return true
end

disableMovingItems:register()

Of course this will only force the item to be in the purse, and make it non-moveable.. but it won't stop other store items from pushing it further into the container..

I don't really have a good solution for that.. and it's probably overkill anyway.

as for the "can't be deleted".. there's really no stopping that.. but only your own scripts would delete the item.. so you're probably safe on that front.

Let me know if you need more help.
 
Goal: I want a player to be able to always have a specific item in their purse which never moves. With this item, I'm going to setup an onUse script to pop-up a modalWindow for various things. This will function as a low effort custom menu within OTClient.

Issue: I'm not able to figure out how to create/place an item into a player's purse (my own or otherwise). For testing, I'm using a talk action registered with this lua script

Lua:
function onSay(player, words, param)
        local purse = player:getSlotItem(CONST_SLOT_PURSE)
        if purse then
            purse:addItem(1949, 100)
        end
end

XML:
<talkaction words="/scroll" separator=" " script="addscroll.lua" />

I don't think it can get any more bare bones for a test run, but this results in nothing happening and nothing being returned/errors in console.

Does anyone know the correct syntax/functions to best accomplish this?

PS. The 2nd bit I'll need help on is maintaining a static item which can't be moved/removed/deleted from every player's purse (if this is even possible)

Did you consider accomplishing this task by adding a button widget to your OTC instead of using your proposed approach?
Since you're using OTC, there's no reason to be using this type of hacky approach.
 
Did you consider accomplishing this task by adding a button widget to your OTC instead of using your proposed approach?
Since you're using OTC, there's no reason to be using this type of hacky approach.
Adding a widget is definitely a much better solution. I'll probably abandon my other method for this as I've been beating my head against the wall trying to get the store inbox to work.. I'll eventually need to know how to manage the store inbox since I'll be making premmy items and a website store, but for my immediate need, a widget is perfect..

Now I just need to dive deep into OTC widgets and customization. Do you by chance have any links to helpful or relevant posts/articles for this?
 
Adding a widget is definitely a much better solution. I'll probably abandon my other method for this as I've been beating my head against the wall trying to get the store inbox to work.. I'll eventually need to know how to manage the store inbox since I'll be making premmy items and a website store, but for my immediate need, a widget is perfect..

Now I just need to dive deep into OTC widgets and customization. Do you by chance have any links to helpful or relevant posts/articles for this?

It's hard to find any documentation about OTC OTUI system out there, best bet is looking at existing implementations and diving deeper into their c++ source to find out how they work.

If you end up needing to understand how to communicate info from server-to-client and vice versa via opcodes, I wrote some extended material here which should still hold up.

To implement a new widget you need to write the OTUI code for the widget and then eventually hook it to an action in a script either using inline action binding like @onClick, or loading the widget through Lua code and saving it into a variable as an object, then binding to that object's lua events with connect.

Here is a sample OTUI for a button:

Code:
  Button
    id: closeButton
    !text: tr('Close')
    width: 64
    anchors.right: parent.right
    anchors.top: parent.top
    margin-right: 15
    @onClick: modules.game_somemodule.close()

The anchors/margin/size system and hierarchy of OTUI classes is something you're gonna need to look into for a bit in order to understand how the positioning and sizing of widgets works.
 
Last edited:
Back
Top