-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature for lua commands in-game, interesting for DEV's. Function by Gesior, found here: https://otland.net/threads/tfs-1-x-luajit-debug-lua-scripts-with-talkaction.260910/
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function sendToPlayerLuaCallResult(player, ...) | ||
local n = select('#', ...) | ||
local result = setmetatable({ ... }, { | ||
__len = function() | ||
return n | ||
end, | ||
}) | ||
|
||
local t = {} | ||
for i = 2, #result do | ||
local v = tostring(result[i]) | ||
if v:len() > 0 then | ||
table.insert(t, v) | ||
end | ||
end | ||
|
||
if #t > 0 then | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, table.concat(t, ', ')) | ||
end | ||
end | ||
|
||
|
||
local talk = TalkAction("/lua") | ||
function talk.onSay(player, words, param) | ||
if player:getGroup():getId() < 6 then | ||
return false | ||
end | ||
|
||
if player:getAccountType() < ACCOUNT_TYPE_GOD then | ||
return false | ||
end | ||
|
||
sendToPlayerLuaCallResult(player, pcall(loadstring( | ||
'local cid = ' .. player:getId() .. ' ' .. | ||
'local player = Player(cid) ' .. | ||
'local pos = player:getPosition() ' .. | ||
'local position = pos ' .. | ||
param | ||
))) | ||
|
||
return false | ||
end | ||
|
||
talk:separator(" ") | ||
talk:register() |