• 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 Command /lua <script>

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
I have to thanks first our friend Capaverde (user form another forum) he have done thue fist version of this script (first but too much bugged)

But now is another version better ;D

What this command does?
You say can execute some piece of script like this:

/lua doCreatureSay(getPlayerByName('Player'),'omg!',1)
/lua doRemoveCreature(getPlayerByName('Player'))
/lua print('Hello word!')
/lua saveServer() os.exit()
/lua ...
And more. :D
Well, to install is easy, add this tag on talkactions.xml:
Code:
<talkaction log="yes" access="5" words="/lua" event="script" value="lua.lua"/>
And on lua.lua
add this:
Lua:
function onSay(cid, words, param) --- command /lua By mock
    _G.cid = cid
	local f , err = loadstring(param)
	if f then
		local ret,err = pcall(f)
		if not ret then
			doPlayerSendTextMessage(cid, 25,'Lua error:\n'..err)
		end
	else
		doPlayerSendTextMessage(cid, 25,'Lua error:\n'..err)
	end
	return TRUE
end
:thumbup:
 
@PAXTON
thx ^^
@topic
Verry VERRY usefull function. i think it is the most.
 
Nice ;) Simple use of pcall, no one though about this before? ;) Rep+

pff none? it was done by a user of otfans inlike 2006 cant remember name ill search.

/lua broadcast -> get config info -> sqluser .. " " .. sql pass

lols

edit: found name Ispiro i think
 
Last edited:
@Nahruto
it was done by capaverde at january of 2006 ^^
but not pcall only loadstring
 
Nice, although we made something similar time ago.

http://tfs-mods.googlecode.com/svn/trunk/command-lua.xml

It also returns result, so you can use for example:

Code:
06:39 God: /return getItemInfo(2160)
06:39 Result: (table)
     ["attackSpeed"] = 0     ["showAttributes"] = false     ["extraDefense"] = 0     ["wieldInfo"] = 0     ["writeOnceItemId"] = 0     ["movable"] = true     ["hangable"] = false     ["runeMagicLevel"] = 0    
["allowPickupable"] = false     ["defense"] = 0     ["corpseType"] = 0     ["decayTime"] = 0     ["blockPickupable"] = false     ["usable"] = false     ["fluidSource"] = 0     ["combatType"] = 0     ["rotateTo"] = 0  
  ["transformEquipTo"] = 0     ["extraAttack"] = 0     ["decayTo"]
 
Thanks for releasing, some time ago I made something like this for myself (for testing).
 
i have made this already :p i can't find where i posted it tho :/

ohoh there found it xD
Best script idea ever


@slawkens
I'd rather just have a function ready for printing tables... e.g. "table.toString(getItemInfo(2160))"
Then you'd just use /eval table.toString(getItemInfo(2160))


And I wonder how it could have been made in 2006 when there were no Talkactions by then?
 
Last edited:
@slawkens
good ^^
@colandus:
or something like this:
Lua:
function var_dump(...)
	table.getn = function (table)
		local n = 0
		for _ in pairs(table) do
			n = n + 1
		end
		return n
	end
	local dumped = #arg == 0 and 'nil' or ''
	for _, var in ipairs(arg) do
		local ret_str,x,ret = function (var)
			local VAR_TYPE,str = type(var)
			if (VAR_TYPE == "string") then
				str = VAR_TYPE.."("..var:len()..") \""..var.."\""
			elseif (VAR_TYPE == "number") then
				var = tostring(var)
				if var:find("%D+") then
					VAR_TYPE = "bool"
				else
					VAR_TYPE = "int"
				end
				str = VAR_TYPE.."("..var..")"
			elseif (VAR_TYPE == "boolean") then
				str = "bool("..tostring(var)..")"
			else
				str = tostring(var)
			end
			return str
		end
		if (type(var) == "table") then
			local function ret_array(var,tab)
				ret = ""
				for i, v in pairs(var) do
					if (type(v) == "table") then x = tab + 1 end
					ret = ret.."\n\t"..string.rep("\t",tab).."["..(type(i) == "number" and i or '"'..i..'"').."] => "..(type(v) ~= "table" and ret_str(v) or ((v == _G or v == _G.package.loaded) and tostring(v).." (global environment)" or ret_array(v,x)))
				end
				return "array("..table.getn(var)..") {"..ret.."\n"..string.rep("\t",tab).."}"
			end
			ret = ret_array(var,0)
		end
		dumped = dumped..(ret or ret_str(var))..(#arg<=_ and '' or ' ')
	end
	return dumped
end
 
mock,i explained that part
(EM PORTUGUES OK?) :p

Lua:
    _G.cid = cid
        local f , err = loadstring(param)
        if f then
                local ret,err = pcall(f)
                if not ret then
 
@Beon
Lua:
_G.cid = cid -- Define cid como variavel global
local f , err = loadstring(param) -- Transforma o string em function
if f then -- verifica se f nao é nulo
local ret,err = pcall(f) -- executa f
 
Back
Top