• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction !commands for 1.0, 1.1, 1.2

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
I seen this thread for commands for 1.1
https://otland.net/threads/commands-for-tfs-1-1.239545/

Since @hellboy made a valid point that you shouldn't read the file every time you use the command I decided to write my own for 1.0, 1.1 & 1.2.

So here it is :p

This code goes in global.lua
Code:
talkactions_File = io.open("data/talkactions/talkactions.xml", "r")
commands = {}

function table.cmdInsert(t, v)
    t[v:sub(2, #v)] = v
    return t
end

for line in talkactions_File:lines() do
    local cmd = line:match('<%a+%s%a+="(.-)"')
    if cmd then
        table.cmdInsert(commands, cmd)
    end
end

function table.cmdconcat(d)
    local s = ''
    for _, v in pairs(commands) do
        s = s .. v .. d
    end
    return s
end

function isTalkaction(v)
    return commands[v] and true or false
end

function getTalkaction(v)
    return isTalkaction(v) and commands[v] or v ..' is not a talkaction command.'
end

function listTalkactions()
    local str = 'All available talkactions:' .. table.cmdconcat('\n')
    return str:sub(1, #str-4)
end

talkactions_File:close()

This goes in talkactions.xml
Code:
    <talkaction words="!commands" script="commands.lua"/>
talkactions/scripts/commands.lua

1.1 & 1.2
Code:
local itemid = 2160
function onSay(player, words, param)
    player:showTextDialog(itemid, listTalkactions())
    return true
end

1.0
Code:
local itemid = 2160
function onSay(cid, words, param)
    local player = Player(cid)
    player:showTextDialog(itemid, listTalkactions())
    return true
end
Code:
--[[
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
 
Last edited:
Does this only show commands that a player can use or everything in ur talkactions.xml?
 
In case of that you missed his post because you use the ignore function on him. :p
PVxhIQ9.png
 
In case of that you missed his post because you use the ignore function on him. :p
PVxhIQ9.png
No one is on my ignore list... i am trying to refrain from giving a negative response to those who don't deserve a response in general.
Basically if I have nothing nice to say I will try not to say anything at all... No promises tho :p
 
No one is on my ignore list... i am trying to refrain from giving a negative response to those who don't deserve a response in general.
Basically if I have nothing nice to say I will try not to say anything at all... No promises tho :p
Ah ok, sorry. :/, (Welcome back again x2) :D
 
Back
Top