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
This code goes in global.lua
This goes in talkactions.xml
talkactions/scripts/commands.lua
1.1 & 1.2
1.0
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
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"/>
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: