• 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+ Gold Converter

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
Hello, I would like this script to detect and change money. It is possible?

I am using the TFS 1.1 engine.



XML:
<action itemid="11773" script="goldconverter.lua" />



Lua:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[target.itemid]
 
    if not coin then
        return false
    end
 
    local charges = item:getCharges()
        if coin.changeTo and target.type == 100 then
        target:remove()
        player:addItem(coin.changeTo, 1)
        item:transform(item:getId(), charges -1)
    elseif coin.changeBack then
        target:transform(target.itemid, target.type - 1)
        player:addItem(coin.changeBack, 100)
        item:transform(item:getId(), charges -1)
        else
        return false
    end
    if charges == 0 then
    item:remove()
    end
    return true
end
 
Solution
@Xikini

[...]
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Saving server...

Lee has logged out.
Gold Converter - target.itemid = 0
Gold Converter - target.itemid = 0
So that tells me that you aren't using the gold converter on a stack of coins.

Use with -> click on coins
OP
OP
Kownikuzyt

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
@Evil Puncker

There is no error in the console :(

screenlog.0


Gumis-Real 10.90 - Version Beta
Compiled with GNU C++ version 5.4.0 20160609
Compiled on Feb 10 2021 19:42:44 for platform x64

A server developed by Quennter
Visit our forum for updates, support, and resources: OTLand (http://otland.net/).

Loading config
Establishing database connection... MySQL 5.7.33
Running database manager
Loading vocations
Loading items
Loading script systems
Loading monsters
Loading outfits
Checking world type... PVP
Loading map
Map size: 34143x33812.
Map loading time: 38.066 seconds.
Loaded house items in: 0.046 s
Initializing gamestate
Loaded all modules, server starting up...
Gumis-Real Server Online!

[CM] Quennter has logged in.
[CM] Quennter has logged out.
Silvuple has logged in.
Itto Shura has logged in.
Handstand has logged in.
Rangers has logged in.
[CM] Quennter has logged in.
[CM] Quennter has logged out.
[CM] Quennter has logged in.
Lee has logged in.
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Processing type 1: itemids
Intrepido has logged in.
Intrepido has logged out.
Fannullone has logged in.
Saving server...
Saved house items in: 1.538 s
Player: Silvuple triggered !shop talkaction.
Processing type 6: Mounts
Processing type 1: itemids
Processing type 1: itemids
Processing type 1: itemids
Processing type 1: itemids
Player: Silvuple triggered !shop talkaction.
Processing type 1: itemids
Processing type 1: itemids
Silvuple has logged out.
Silvuple has logged in.
Player: Silvuple triggered !shop talkaction.
Player: Silvuple triggered !shop talkaction.
Processing type 1: itemids
Saving server...
Saved house items in: 0.663 s
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Broadcasted message: "[BattleField] A teleport was created in the Thais temple, just 10 players can enter, to be divided into 5 VS 5.".
Broadcasted message: "[BattleField] Faltam 10 players for the event to begin.".
Broadcasted message: "[BattleField] The event was not started because it did not reach the number of players.".
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
@Evil Puncker

There is no error in the console :(

screenlog.0


Gumis-Real 10.90 - Version Beta
Compiled with GNU C++ version 5.4.0 20160609
Compiled on Feb 10 2021 19:42:44 for platform x64

A server developed by Quennter
Visit our forum for updates, support, and resources: OTLand (http://otland.net/).


Map size: 34143x33812.
Map loading time: 38.066 seconds.
Loaded house items in: 0.046 s


[CM] Quennter has logged in.
[CM] Quennter has logged out.
Silvuple has logged in.
Itto Shura has logged in.
Handstand has logged in.
Rangers has logged in.
[CM] Quennter has logged in.
[CM] Quennter has logged out.
[CM] Quennter has logged in.
Lee has logged in.
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Processing type 1: itemids
Intrepido has logged in.
Intrepido has logged out.
Fannullone has logged in.
Saving server...
Saved house items in: 1.538 s
Player: Silvuple triggered !shop talkaction.
Processing type 6: Mounts
Processing type 1: itemids
Processing type 1: itemids
Processing type 1: itemids
Processing type 1: itemids
Player: Silvuple triggered !shop talkaction.
Processing type 1: itemids
Processing type 1: itemids
Silvuple has logged out.
Silvuple has logged in.
Player: Silvuple triggered !shop talkaction.
Player: Silvuple triggered !shop talkaction.
Processing type 1: itemids
Saving server...
Saved house items in: 0.663 s
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Broadcasted message: "[BattleField] A teleport was created in the Thais temple, just 10 players can enter, to be divided into 5 VS 5.".
Broadcasted message: "[BattleField] Faltam 10 players for the event to begin.".
Broadcasted message: "[BattleField] The event was not started because it did not reach the number of players.".
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
I've added a print.
Tell us what happens in console.
Lua:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[target.itemid]
    print("Gold Converter - target.itemid = " .. target.itemid)
    if not coin then
        return false
    end
   
    local charges = item:getCharges()
        if coin.changeTo and target.type == 100 then
        target:remove()
        player:addItem(coin.changeTo, 1)
        item:transform(item:getId(), charges -1)
    elseif coin.changeBack then
        target:transform(target.itemid, target.type - 1)
        player:addItem(coin.changeBack, 100)
        item:transform(item:getId(), charges -1)
    else
        return false
    end
    if charges == 0 then
        item:remove()
    end
    return true
end
 
OP
OP
Kownikuzyt

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
I've added a print.
Tell us what happens in console.
Lua:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[target.itemid]
    print("Gold Converter - target.itemid = " .. target.itemid)
    if not coin then
        return false
    end
  
    local charges = item:getCharges()
        if coin.changeTo and target.type == 100 then
        target:remove()
        player:addItem(coin.changeTo, 1)
        item:transform(item:getId(), charges -1)
    elseif coin.changeBack then
        target:transform(target.itemid, target.type - 1)
        player:addItem(coin.changeBack, 100)
        item:transform(item:getId(), charges -1)
    else
        return false
    end
    if charges == 0 then
        item:remove()
    end
    return true
end

@Xikini

[...]
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Saving server...
Saved house items in: 0.682 s
Lee has logged out.
Gold Converter - target.itemid = 0
Gold Converter - target.itemid = 0
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
@Xikini

[...]
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Player: Lee triggered !shop talkaction.
Processing type 1: itemids
Saving server...

Lee has logged out.
Gold Converter - target.itemid = 0
Gold Converter - target.itemid = 0
So that tells me that you aren't using the gold converter on a stack of coins.

Use with -> click on coins
 
Solution

Evil Puncker

prolonged absenteeism
TFS Developer
Joined
May 30, 2009
Messages
8,041
Solutions
215
Reaction score
3,880
@Xikini


The "Use with ..." option is missing. Can it be rewritten to the subject?

View attachment 54843
you need to edit both items.otb and client .dat/assets file in order to make an item have the "use with" option

or just use another item that have the "use with" option by default
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
26378 is the default item used for this, I believe.

The "Use with ..." option is missing. Can it be rewritten to the subject?

And yes, I could re-write it to 'search' your inventory for a stack of gold coins..
But it would be a royal pain in the butt, and possibly lag inducing.. if someone has a 1000 bags in their inventory, for example.

It's much easier to just find another item that has the 'use with' capability.
 
OP
OP
Kownikuzyt

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
26378 is the default item used for this, I believe.



And yes, I could re-write it to 'search' your inventory for a stack of gold coins..
But it would be a royal pain in the butt, and possibly lag inducing.. if someone has a 1000 bags in their inventory, for example.

It's much easier to just find another item that has the 'use with' capability.

@Xikini i @Evil Puncker

Thank you for solving the problem. This was due to an item without the "Use with..." option. Everything works correctly :)

If this is not a problem for you ( @Xikini ), I will be happy to test how you write such a script. If you can and you have time :)


Gold Converter - target.itemid = 2148
Gold Converter - target.itemid = 2152
Gold Converter - target.itemid = 2148
Gold Converter - target.itemid = 2152
Gold Converter - target.itemid = 2148
Gold Converter - target.itemid = 2148
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
@Xikini i @Evil Puncker

Thank you for solving the problem. This was due to an item without the "Use with..." option. Everything works correctly :)

If this is not a problem for you ( @Xikini ), I will be happy to test how you write such a script. If you can and you have time :)


Gold Converter - target.itemid = 2148
Gold Converter - target.itemid = 2152
Gold Converter - target.itemid = 2148
Gold Converter - target.itemid = 2152
Gold Converter - target.itemid = 2148
Gold Converter - target.itemid = 2148

bandicam-2021-02-10-20-39-43-437.gif

Tested with an amulet of loss, but script below has it set to your item 11773
Lua:
local goldCoin = 2148
local platCoin = 2152
local crysCoin = 2160

local actions_test_script = Action()

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local charges, chargesRemoved = item:getCharges(), 0
    local goldCount, goldRemoved = player:getItemCount(goldCoin), 0
    local platCount, platRemoved = player:getItemCount(platCoin), 0
   
    goldCount = math.floor(goldCount/100)
    while charges > 0 and goldCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        goldCount = goldCount - 1
        goldRemoved = goldRemoved + 1
        platCount = platCount + 1
    end
   
    platCount = math.floor(platCount/100)
    while charges > 0 and platCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        platCount = platCount - 1
        platRemoved = platRemoved + 1
    end
   
    local chargesRemaining = item:getCharges()
    item:transform(item:getId(), chargesRemaining - chargesRemoved)
   
    if goldRemoved > 0 then
        player:removeItem(goldCoin, goldRemoved * 100)
        player:addItem(platCoin, goldRemoved)
    end
   
    if platRemoved > 0 then
        player:removeItem(platCoin, platRemoved * 100)
        player:addItem(crysCoin, platRemoved)
    end
   
    local text = "No stacks of coins needed to be converted."
    if chargesRemoved > 0 then
        text = (chargesRemaining - chargesRemoved) .. " charges remaining."
        text = text .. (goldRemoved == 0 and "" or " Converted " .. goldRemoved .. " stack" .. (goldRemoved > 0 and "s" or "") .. " of gold coins.")
        text = text .. (platRemoved == 0 and "" or " Converted " .. platRemoved .. " stack" .. (platRemoved > 0 and "s" or "") .. " of platinum coins.")
        fromPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    player:sendTextMessage(MESSAGE_DAMAGE_RECEIVED, text)
    return true
end

actions_test_script:id(11773)
actions_test_script:register()
 
OP
OP
Kownikuzyt

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
View attachment 54865

Tested with an amulet of loss, but script below has it set to your item 11773
Lua:
local goldCoin = 2148
local platCoin = 2152
local crysCoin = 2160

local actions_test_script = Action()

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local charges, chargesRemoved = item:getCharges(), 0
    local goldCount, goldRemoved = player:getItemCount(goldCoin), 0
    local platCount, platRemoved = player:getItemCount(platCoin), 0
  
    goldCount = math.floor(goldCount/100)
    while charges > 0 and goldCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        goldCount = goldCount - 1
        goldRemoved = goldRemoved + 1
        platCount = platCount + 1
    end
  
    platCount = math.floor(platCount/100)
    while charges > 0 and platCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        platCount = platCount - 1
        platRemoved = platRemoved + 1
    end
  
    local chargesRemaining = item:getCharges()
    item:transform(item:getId(), chargesRemaining - chargesRemoved)
  
    if goldRemoved > 0 then
        player:removeItem(goldCoin, goldRemoved * 100)
        player:addItem(platCoin, goldRemoved)
    end
  
    if platRemoved > 0 then
        player:removeItem(platCoin, platRemoved * 100)
        player:addItem(crysCoin, platRemoved)
    end
  
    local text = "No stacks of coins needed to be converted."
    if chargesRemoved > 0 then
        text = (chargesRemaining - chargesRemoved) .. " charges remaining."
        text = text .. (goldRemoved == 0 and "" or " Converted " .. goldRemoved .. " stack" .. (goldRemoved > 0 and "s" or "") .. " of gold coins.")
        text = text .. (platRemoved == 0 and "" or " Converted " .. platRemoved .. " stack" .. (platRemoved > 0 and "s" or "") .. " of platinum coins.")
        fromPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    player:sendTextMessage(MESSAGE_DAMAGE_RECEIVED, text)
    return true
end

actions_test_script:id(11773)
actions_test_script:register()

@Xikini

I have a problem in the console:


Lua Script Error: [Test Interface]
data/actions/scripts/goldconverter.lua
data/actions/scripts/goldconverter.lua:5: attempt to call global 'Action' (a nil value)
stack traceback:
[C]: in function 'Action'
data/actions/scripts/goldconverter.lua:5: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/goldconverter.lua
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
@Xikini

I have a problem in the console:


Lua Script Error: [Test Interface]
data/actions/scripts/goldconverter.lua
data/actions/scripts/goldconverter.lua:5: attempt to call global 'Action' (a nil value)
stack traceback:
[C]: in function 'Action'
data/actions/scripts/goldconverter.lua:5: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/goldconverter.lua
Ah you're using tfs 1.1 not tfs 1.3

here
Lua:
local goldCoin = 2148
local platCoin = 2152
local crysCoin = 2160

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local charges, chargesRemoved = item:getCharges(), 0
    local goldCount, goldRemoved = player:getItemCount(goldCoin), 0
    local platCount, platRemoved = player:getItemCount(platCoin), 0
    
    goldCount = math.floor(goldCount/100)
    while charges > 0 and goldCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        goldCount = goldCount - 1
        goldRemoved = goldRemoved + 1
        platCount = platCount + 1
    end
    
    platCount = math.floor(platCount/100)
    while charges > 0 and platCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        platCount = platCount - 1
        platRemoved = platRemoved + 1
    end
    
    local chargesRemaining = item:getCharges()
    item:transform(item:getId(), chargesRemaining - chargesRemoved)
    
    if goldRemoved > 0 then
        player:removeItem(goldCoin, goldRemoved * 100)
        player:addItem(platCoin, goldRemoved)
    end
    
    if platRemoved > 0 then
        player:removeItem(platCoin, platRemoved * 100)
        player:addItem(crysCoin, platRemoved)
    end
    
    local text = "No stacks of coins needed to be converted."
    if chargesRemoved > 0 then
        text = (chargesRemaining - chargesRemoved) .. " charges remaining."
        text = text .. (goldRemoved == 0 and "" or " Converted " .. goldRemoved .. " stack" .. (goldRemoved > 0 and "s" or "") .. " of gold coins.")
        text = text .. (platRemoved == 0 and "" or " Converted " .. platRemoved .. " stack" .. (platRemoved > 0 and "s" or "") .. " of platinum coins.")
        fromPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    player:sendTextMessage(MESSAGE_DAMAGE_RECEIVED, text)
    return true
end
 
OP
OP
Kownikuzyt

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
Ah you're using tfs 1.1 not tfs 1.3

here
Lua:
local goldCoin = 2148
local platCoin = 2152
local crysCoin = 2160

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local charges, chargesRemoved = item:getCharges(), 0
    local goldCount, goldRemoved = player:getItemCount(goldCoin), 0
    local platCount, platRemoved = player:getItemCount(platCoin), 0
   
    goldCount = math.floor(goldCount/100)
    while charges > 0 and goldCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        goldCount = goldCount - 1
        goldRemoved = goldRemoved + 1
        platCount = platCount + 1
    end
   
    platCount = math.floor(platCount/100)
    while charges > 0 and platCount > 0 do
        charges = charges - 1
        chargesRemoved = chargesRemoved + 1
        platCount = platCount - 1
        platRemoved = platRemoved + 1
    end
   
    local chargesRemaining = item:getCharges()
    item:transform(item:getId(), chargesRemaining - chargesRemoved)
   
    if goldRemoved > 0 then
        player:removeItem(goldCoin, goldRemoved * 100)
        player:addItem(platCoin, goldRemoved)
    end
   
    if platRemoved > 0 then
        player:removeItem(platCoin, platRemoved * 100)
        player:addItem(crysCoin, platRemoved)
    end
   
    local text = "No stacks of coins needed to be converted."
    if chargesRemoved > 0 then
        text = (chargesRemaining - chargesRemoved) .. " charges remaining."
        text = text .. (goldRemoved == 0 and "" or " Converted " .. goldRemoved .. " stack" .. (goldRemoved > 0 and "s" or "") .. " of gold coins.")
        text = text .. (platRemoved == 0 and "" or " Converted " .. platRemoved .. " stack" .. (platRemoved > 0 and "s" or "") .. " of platinum coins.")
        fromPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    player:sendTextMessage(MESSAGE_DAMAGE_RECEIVED, text)
    return true
end

@Xikini


Thank you for correcting the code, as I wrote earlier on which engine TFS works.

I still have a problem or I do not understand the operation of the Converter.

Let's assume that I was on the exp and I dropped 17x100 Gold Coins.

I am using the item ID "11773" and I am notifying me of "No stacks of coins needed to be converted." to receive 17 Platinum Coins.

goldconverter.png
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
@Xikini


Thank you for correcting the code, as I wrote earlier on which engine TFS works.

I still have a problem or I do not understand the operation of the Converter.

Let's assume that I was on the exp and I dropped 17x100 Gold Coins.

I am using the item ID "11773" and I am notifying me of "No stacks of coins needed to be converted." to receive 17 Platinum Coins.

View attachment 54887
The only way for that to happen, is if your gold converter doesn't have charges.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,672
Solutions
406
Reaction score
3,786
@Xikini

So I need to find an item with loads? Can I assign the ID "11773" to this? and the matter is settled?
Depends on what you want to do.

If you want to use that item, you'll need to give it charges.
If you want a permanent gold converter, we can remove the charges check from the script.
 
OP
OP
Kownikuzyt

Kownikuzyt

New Member
Joined
Feb 11, 2020
Messages
114
Solutions
1
Reaction score
3
Depends on what you want to do.

If you want to use that item, you'll need to give it charges.
If you want a permanent gold converter, we can remove the charges check from the script.

@Xikini

If you remove this parameter, can you convert 100 gold coins into 1 platinum coin and 100 platinum coin into 1 Crystal coins? If so, I will ask you to remove the redundant code.
 
Top