local function getUser(msg)
local user = ""
local userEnd = msg:find(">")
local closeBr = msg:find(")")
if closeBr == nil or closeBr > userEnd then
return msg:sub(5, userEnd-1)
else
return msg:sub(closeBr+1, userEnd-1)
end
end
add_hook("console", "", function(msg, t)
-- 8 => public msg from someone else
-- 16 => public msg from you
if t == 8 or t == 16 then
echo("user: "..getUser(msg))
else
echo(t)
end
end)
Also, use [code] tags to display code.
local closeBr = msg:find(")")
to local closeBr = msg:find(")") or msg:find("%]")
I have no idea why i made it get the start and end so many times.local function getUser(msg)
local user = ""
local userEnd = msg:find(">")
msgName = msg:sub(0,userEnd)
local closeBr = msgName:find(")") or msgName:find("%]")
if closeBr == nil or closeBr > userEnd then
return msg:sub(5, userEnd-1)
else
return msg:sub(closeBr+1, userEnd-1)
end
end
add_hook("console", "", function(msg, t)
-- 8 => public msg from someone else
-- 16 => public msg from you
if t == 8 or t == 16 then
echo("user: "..getUser(msg))
else
echo(t)
end
end)
Also a quick tip: You can write 'a:find("%[")' instead of 'string.find(a, "%[")'. Note the colon though, it's necessary. Works only for variables so '"asdf":find(...)' won't work.
("asd()"):find("()", 1, true)
Also, do you know if they recently made some changes for lua in toribash? Drawing seems to be much faster now at least.
Actually, "asd":find won't work because of the parser, if you do ("asd"):find it will work, another thing, string.find has a 4th parameter that let's you pass non-pattern strings, like this:
lua code:("asd()"):find("()", 1, true)
I didn't know the parser thing. That seems very odd to me. Doesn't that imply that "asd" and ("asd") are different language constructs? Shouldn't they both be equal in every aspect? Is this a general problem of Lua or did the parser used by TB just get that wrong?
for k=0,10 do
run_frames(k)
end
Tori=0
Uke =1
joint = 0
tori_dp = get_joint_dismember(Tori,joint)
if tori_dp then
echo("Tori got Decapped")
end
for i=1,19 do
tori_dm = get_joint_dismember(Tori,i)
if tori_dm then
echo ("Tori got dismembered in no."..i.." joint")
end
end
uke_dp = get_joint_dismember(Uke,joint)
if uke_dp then
echo("Uke got Decapped")
end
for i=1,19 do
uke_dm = get_joint_dismember(Uke,i)
if tori_dm then
echo ("Uke got dismembered in no."..i.." joint")
end
end
Hi Toribash developers,
I'm trying to be able to run_frames() in a loop but it is just stepping one time and at the last loop round .
I'm using this code :
lua code:
for k=0,10 do
run_frames(k)
end
for k=s, e do
run_frames(k)
end
run_frames(- (s - e - 1) * (s + e) / 2)
So... I tried to make a script that echos if tori/uke got dismembered/decaped. The script which I made, only works one time when called after tori/uke got dismembered.
I wanted to make it toggle, like after doing /ls name.lua, whenever tori/uke got dismembered, it would echo (One time). Any help appreciated ?
[... code ...]
P.S :- First time trying lua.
-- The function that is called when a frame is entered.
-- The functions name can be whatever you want
local function onEnterFrame()
echo("entered a frame")
end
-- register the hook
-- first argument is the event name
-- second argument can be ignored for now
-- third argument is the function you want to call.
add_hook("enter_frame", "", onEnterFrame)