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

TalkAction Trade System

Master-m

Need help? Just ask!
Senator
Joined
May 28, 2007
Messages
4,338
Reaction score
16
Location
The Netherlands
Credits:
Nahruto
Remere for his function

How to use


  1. To turn your trade system on simply say ' !trade system "on '
  2. To invite someone to a trade simply say ' !invite "PLAYERNAME '
  3. After that, the player you invited will receive a pop-up message saying "xxxx wants to trade with you"
  4. Now you can begin trading.
  5. But an item in your right hand then say ' !trade "TradePrice '
  6. Then you say ' !trade accept '

Add this to the end of your global.lua file.
Code:
_warpzone = 2147483648 -- start storing strings here (THIS IS THE ABSOLUTE MAXIMUM VALUE FOR THIS)
_maxlength = 1024 -- multiply by 3 to get the true length.
 
setPlayerStorageInteger = setPlayerStorageValue
getPlayerStorageInteger = getPlayerStorageValue
 
function setPlayerStorageString(cid, key, value)
    if #value > (_maxlength-1) * 3 - 1 then -- Last word is reserved for 0 termination of the string.
        error("Storage string is too long")
    end
    if key > _warpzone / _maxlength then
        error("Storage string key is too large (" .. key .. ")")
    end
    key = _warpzone + key * _maxlength
 
    local word = 0
    local wordwrap = 0
    local wordcount = 0
    local i = 1
    while i <= #value do
        local byte = string.byte(string.sub(value, i, i))
        word = bit.bor(word, bit.lshift(byte, wordwrap))
        wordwrap = wordwrap + 8
        if wordwrap == 24 then
            --[[
                In the ideal world we would be able to store 4 characters per word,
                however, as the default return value for getPlayerStorageValue is
                -1, we can't use the last bit.
            ]]--
            setPlayerStorageInteger(cid, key + wordcount, word)
            word = 0
            wordwrap = 0
            wordcount = wordcount + 1
        end
        i = i + 1
    end
    -- store the last word
    setPlayerStorageInteger(cid, key + wordcount, word)
end
 
function getPlayerStorageString(cid, key)
    if key > _warpzone / _maxlength then
        error("Storage string key is too large (" .. key .. ")")
    end
    key = _warpzone + key * _maxlength
 
    local wordcount = 0
    local str = ""
    while true do
        if wordcount >= _maxlength then
            break
        end
        local word = getPlayerStorageInteger(cid, key + wordcount)
        if word == -1 then
            -- end of string
            break
        else 
            -- Extract the 3 characters from the value
            byte = bit.band(word, 255)
            if byte == 0 then break else str = str .. string.char(byte) end
            byte = bit.rshift(bit.band(word, 65280), 8)
            if byte == 0 then break else str = str .. string.char(byte) end
            byte = bit.rshift(bit.band(word, 16711680), 16)
            if byte == 0 then break else str = str .. string.char(byte) end
        end
        wordcount = wordcount + 1
    end
    return str
end

talkactions.xml
Code:
    <talkaction words="!trade" script="trade.lua"/>
    <talkaction words="!invite" script="trade.lua"/>
    <talkaction words="!trade system" script="trade.lua"/>
    <talkaction words="!accept" script="trade.lua"/>
    <talkaction words="!trade accept" script="trade.lua"/>

/scripts/trade.lua

Code:
local SLOT = 5 --5 left hand, or 6 right hand.
local TradeON = 35210
local invited = 35211
local Trading = 35212
local Accepted = 35213
local offered = 35214
local TrItem = {id=35215, count=35216, prize=35217}
 
local function ResetStorages(cid, t)
    for i = 1, #t do
        setPlayerStorageValue(cid, t[i], 0)
    end
end
function onSay(cid, words, param)
    if words == "!trade system" then
        if param == "on" then
            if getPlayerStorageValue(cid, TradeON) ~= 1 then
                setPlayerStorageValue(cid, TradeON, 1)
                doPlayerSendTextMessage(cid,22,"Trade system is now on.")
            else
                doPlayerSendCancel(cid, "Your trade system is already on.")
            end
        elseif param == "off" then
            if getPlayerStorageValue(cid, TradeON) == 1 then
                ResetStorages(cid, {TradeON, invited, Accepted, TrItem.id, TrItem.count, TrItem.prize, offered})
                setPlayerStorageString(cid, Trading, "NOTHING LoL")
                doPlayerSendTextMessage(cid,22,"Trade system is now off.")
            else
                doPlayerSendCancel(cid, "Your trade system is already off.")
            end
        end    
    elseif words == "!invite" then
        if getPlayerStorageValue(cid, TradeON) == 1 then
            if param ~= "" then
                local TradingDude = getPlayerByName(param)
                if getPlayerStorageValue(TradingDude, TradeON) == 1 then
                    doPlayerPopupFYI(TradingDude, ""..getPlayerName(cid).." wants to trade with you.")
                    setPlayerStorageValue(cid, invited, 1)
                    setPlayerStorageValue(TradingDude, invited, 1)
                    setPlayerStorageString(cid, Trading, getPlayerName(TradingDude))
                    setPlayerStorageString(TradingDude, Trading, getPlayerName(cid))
                else
                    doPlayerSendCancel(cid, "This player is not trading.")
                end
            else
                doPlayerSendCancel(cid, "You should write a player name.")
            end
        else
            doPlayerSendCancel(cid, "Your trade system is off.")
        end
    elseif words == "!accept" then
        if getPlayerStorageValue(cid, invited) == 1 then
            local DudeName = getPlayerStorageString(cid, Trading)
            local Dude = getPlayerByName(DudeName)
            setPlayerStorageValue(cid, Accepted, 1)
            setPlayerStorageValue(Dude, Accepted, 1)
            doPlayerSendTextMessage(cid,22,"You have accepted the request to trade with "..DudeName..".")
            doPlayerSendTextMessage(Dude,22,""..getPlayerName(  cid).." accepted your request to trade.")
        end
    elseif words == "!trade" then
        if param ~= "" then
            local TradeItem = getPlayerSlotItem(cid, SLOT)
            if TradeItem.itemid > 0 then
                local prize = tonumber(param)
                local DudeName = getPlayerStorageString(cid, Trading)
                local Dude = getPlayerByName(DudeName)
                if TradeItem.type == 0 then
                    TradeItem.type = 1
                end
                doPlayerSendTextMessage(Dude,22,""..getPlayerName(  cid).." wants to trade "..TradeItem.type.." "..getItemName(TradeItem.itemid).." for "..prize..".")
                setPlayerStorageValue(Dude, TrItem.id, TradeItem.itemid)
                setPlayerStorageValue(Dude, TrItem.count, TradeItem.type)
                setPlayerStorageValue(Dude, TrItem.prize, prize)
                setPlayerStorageValue(Dude, offered, 1)
                setPlayerStorageValue(cid, offered, 1)
            else
                doPlayerSendCancel(cid, "Put the item to trade in your hand.")
            end
        else
            doPlayerSendCancel(cid, "You should write a prize.")
        end
    elseif words == "!trade accept" then
        local DudeName = getPlayerStorageString(cid, Trading)
        local Dude = getPlayerByName(DudeName)
        if getPlayerStorageValue(cid, offered) == 1 and getPlayerStorageValue(Dude, offered) == 1 then
            local Item_ = getPlayerStorageValue(cid, TrItem.id)
            local Count_ = getPlayerStorageValue(cid, TrItem.count)
            local Prize_ = getPlayerStorageValue(cid, TrItem.prize)
            if getPlayerMoney(cid) >= Prize_ then
                if doPlayerRemoveItem(Dude, Item_, Count_) == TRUE then
                    doPlayerRemoveMoney(cid, Prize_)
                    doPlayerAddMoney(Dude, Prize_)
                    doPlayerAddItem(cid, Item_, Count_)
                    doPlayerSendTextMessage(cid,22,"Trade completed.")
                    doPlayerSendTextMessage(Dude,22,"Trade completed.")
                    ResetStorages(cid, {TrItem.id, TrItem.count, TrItem.prize, offered})
                    ResetStorages(Dude, {TrItem.id, TrItem.count, TrItem.prize, offered})
                end                
            else
                doPlayerSendCancel(cid, "You dont have enough money.")
            end
        else
            doPlayerSendCancel(cid, "The player is not trading.")
        end
    end
end
 
function getPlayerMoney(cid)
return getPlayerItemCount(cid,2148) + (getPlayerItemCount(cid,2152)*100) + (getPlayerItemCount(cid,2160)*10000)
end
 
Well this isnt like rl tibia trade system ^^ its even better, that means you can trade with the person you want from every place you want to.
for example you are in Venore and a guy who wants buy items from you is in Thais, Noone of you need to travel and you can simply trade with him with help of this script ^^
 
it's show an item which I want trade? IF i want trade backpack with items? it's work?

p.s. can't test it right now ;(
 
PHP:
[08/10/2008  06:31:02] Lua Script Error: [TalkAction Interface] 
[08/10/2008  06:31:02] data/talkactions/scripts/trade.lua:onSay

[08/10/2008  06:31:02] luaGetItemName(). Item not found

I can not see the error. Who knows?
 
hm, it's too bad, cause ppl can exp 24/7 without going to the city to sell loot and without going back for potions.. weird

but the idea was great!
 
hm, it's too bad, cause ppl can exp 24/7 without going to the city to sell loot and without going back for potions.. weird

but the idea was great!

You can just fix it by finding both player pos and only allowing the trade if x and y is =, +4, -4 of the second player and z must be the same.
 
sorry for bumpiing, i didnt knew it was here, ill post the updae code later.
 
Well, I think this script is cool but, if you are out hunting, and your friend or noobchar is in city, you can just continue hunting.. :S (or botting)
 
Back
Top