Help with Ascii-Talk
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Help with Ascii-Talk

Started by miago, 23 April, 2008, 15:07:49

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

miago

Hi.

Need some help with this script so all users (operator, vips and regs) get the RCmenu under hubtab and userslist, atm only masters get it.
I think it's the second line that needs to be changed but I dont know to what, have tried on my own but I cant get it to work.

function ATalk:SendUserCommands( user )
	if (self.RegOnly == 0) or (self.RegOnly == 1 and user.iProfile ~= -1) then
		Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say It! (Font: default)$<%[mynick]> "..self.Prefix..self.SayCmd.." %[line: Say your 

thing]&#124;")
		for i,_ in pairs( self.Fonts ) do
			if i ~= self.DefaultFont then
				Core.SendToUser(user, "$UserCommand 0 0 "..self.Menu.."\\Say It! (Font: "..i..", "..self.Defaultsize[i]..")$<%[mynick]> 

"..self.Prefix..self.SayFormatCmd.." {\\"..i.." %[line: Say your thing]}&#124;")
			end
		end
		--Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say It! (choose font, size)$<%[mynick]> "..self.Prefix..self.SayFormatCmd.." {\\%

[line: Font?]\\%[line: Size?] %[line: Say your thing]}&#124;")
		Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\AsciiTalk Help$<%[mynick]> "..self.Prefix..self.HelpCmd.."&#124;")
		Core.SendToUser(user, "$UserCommand 0 3 &#124;")
		Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say:$&#124;")
		if self.CatchWord == 1 then
			for _,v in ipairs( self.SingleWordIndex ) do
				if string.find( self.SingleWord[v][1], "%[arg%]" ) then
					Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say :\\ "..v.."$<%[mynick]> "..v.." %[line: Name?]&#124;") 
					--Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\   ->         "..v.."   . . .$<%[mynick]> "..v.." %[line:  

. . . ]&#124;")
				else
					Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say :\\ "..v.."$<%[mynick]> "..v.."&#124;")
					--Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\   ->         "..v.."$<%[mynick]> "..v.."&#124;")
				end
			end
		end
	end
end


and heres the whole lua.

--// Another UwV and CHILL CODE ? production //--
--// Idea taken from aDe's SAY SCRIPT, many thx //--

--// ASCII TALK  0.3 //--

--[[
	CHANGELOG:
	-----------------------
	V 0.3i -        UwV          nov. 13 2007   @ 00:58:05 
	    changed to new px api

	V 0.2 -   15/11/2006:	    
		Added more SingleWords support (second argument), check file (UwV)
		Fixed linebreaks this time...
		Changed UserCommands, deleted submenu for single words
		
	V 0.1  -  7/11/2006:
		Changed Ascii File Layout
		Added Support for Emotions, Phrases
		Added SingleWord support and SingleWordFile (UwV)
		Optimised Loading of Fonts
		Fixed linebreaks, can now be used in all commands
		Added [name] support in Single Words
		Added formatmode for Single Words
		Made Tabstops and linbreaks c conform e.g. \n, \t
		Added SingleWord Menu Support (UwV)
	

--]]--

--// All Fonts optimised for Microssoft Sans Serif Size 8


--// ASCII TALK //--

-- Appearance
ATalk = {}
ATalk.Botname = "-=Ascii-Talk=-"
ATalk.Menu = "-=Ascii-Talk=-"
--ATalk.Menu = "AsciiTalk\\ATalk" --with submenu
ATalk.Prefix = "!" -- The shown  Prefix
ATalk.SayCmd = "blowup"
ATalk.SayFormatCmd = "fblowup"
ATalk.HelpCmd = "atalk"
ATalk.ShowCmd = 0  -- shows used command
ATalk.CatchWord = 1  -- try to convert a single word, emotion from mainchat, with default font

-- Security
ATalk.RegOnly = 1

ATalk.Path = "ASCII/"
ATalk.DefaultFont = "grUwVitty"

----------------------------------------------
----------------------------------------------

ATalk.Version = "0.3 (Return of the ASCII.i)"

-- Fonts
ATalk.Fonts = {}
ATalk.Defaultsize = {}
-- Single Word
ATalk.SingleWord = {}

-- SingleWord Index Table
ATalk.SingleWordIndex = {}

--// PTOKAX API //--

function OnStartup()
	ATalk:Main()
end

function ChatArrival( User, Data )
	return ATalk:ChatArrival( User, Data )
end

function UserConnected( User )
	ATalk:SendUserCommands( User )
end
OpConnected = UserConnected


-- MAIN
function ATalk:Main()
	-- load font grUwVitty normal
	self:loadFont( self.Path.."grUwVitty.normal.txt" )
	-- load font graffitytab normal
	self:loadFont( self.Path.."graffitytab.normal.txt" )
	-- load font semicolon big
	self:loadFont( self.Path.."semicolon.big.txt" )

	if self.CatchWord == 1 then
		-- load Single Word File
		self:loadSingleWord( self.Path.."SingleWord.txt" )
	end
end

function ATalk:SendUserCommands( user )
	if (self.RegOnly == 0) or (self.RegOnly == 1 and user.iProfile ~= -1) then
		Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say It! (Font: default)$<%[mynick]> "..self.Prefix..self.SayCmd.." %[line: Say your 

thing]&#124;")
		for i,_ in pairs( self.Fonts ) do
			if i ~= self.DefaultFont then
				Core.SendToUser(user, "$UserCommand 0 0 "..self.Menu.."\\Say It! (Font: "..i..", "..self.Defaultsize[i]..")$<%[mynick]> 

"..self.Prefix..self.SayFormatCmd.." {\\"..i.." %[line: Say your thing]}&#124;")
			end
		end
		--Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say It! (choose font, size)$<%[mynick]> "..self.Prefix..self.SayFormatCmd.." {\\%

[line: Font?]\\%[line: Size?] %[line: Say your thing]}&#124;")
		Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\AsciiTalk Help$<%[mynick]> "..self.Prefix..self.HelpCmd.."&#124;")
		Core.SendToUser(user, "$UserCommand 0 3 &#124;")
		Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say:$&#124;")
		if self.CatchWord == 1 then
			for _,v in ipairs( self.SingleWordIndex ) do
				if string.find( self.SingleWord[v][1], "%[arg%]" ) then
					Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say :\\ "..v.."$<%[mynick]> "..v.." %[line: Name?]&#124;") 
					--Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\   ->         "..v.."   . . .$<%[mynick]> "..v.." %[line:  

. . . ]&#124;")
				else
					Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\Say :\\ "..v.."$<%[mynick]> "..v.."&#124;")
					--Core.SendToUser(user, "$UserCommand 1 3 "..self.Menu.."\\   ->         "..v.."$<%[mynick]> "..v.."&#124;")
				end
			end
		end
	end
end


-- CHAT ARRIVAL
function ATalk:ChatArrival( user, sdata )
	if (self.RegOnly == 0) or (self.RegOnly == 1 and user.iProfile ~= -1) then
		sdata = string.sub( sdata, 1, - 2 )
		local _,_,cmd = string.find( sdata, "^%b<>%s+%p(%S+)" )
		if cmd and self.Cmd[cmd] then
			self.Cmd[cmd]( self, user, sdata )
			return true
		elseif self.CatchWord == 1 then
			local _,_,word = string.find( sdata, "^%b<>%s+(%S+)" )
			local _,_,word2 = string.find( sdata, "^%b<>%s+%p(%S+)" )
			if word and self.SingleWord[word] then
				self:doSingleWord( user, sdata, word )
				return true
			elseif word2 and self.SingleWord[word2] then
				self:doSingleWord( user, sdata, word2 )
				return true
			end
		end			
	end
end

-- ATALK COMMANDS
-- Special Commands
function ATalk:doSingleWord( user, sdata, word )
	-- get random ascii to display
	local ascii = self.SingleWord[word][math.random( 1, table.getn( self.SingleWord[word] ) )]
	-- check for second argument
	local _,_,arg = string.find( sdata, "^%b<>%s+%S+%s+(.+)" )
	local name = user.sNick
	arg = arg or ""
	local tosub = {
		["[arg]"] = function() return arg end,
		["[name]"] = function()
			user.sNick = self.Botname
			return name
		end,
		["[time]"] = function() return os.date( "%H:%M:%S" ) end,
		["[Year]"] = function() return os.date( "%Y" ) end,
		["[year]"] = function() return os.date( "%y" ) end,
		["[Month]"] = function() return os.date( "%B" ) end,
		["[month]"] = function() return os.date( "%b" ) end,
		["[mon]"] = function()  return os.date( "%m" ) end,
		["[DAY]"] = function() return os.date( "%A" ) end,
		["[Day]"] = function() return os.date( "%a" ) end,
		["[day]"] = function() return os.date( "%d" ) end,
	}
	local x = string.gsub( ascii, "%b[]", function( c )
		if tosub[c] then
			return tosub[c]()
		else
			return c
		end
	end)
	x = string.gsub( x, "%b{}", function( c )
		return string.sub( self:convertf( c ), 3, -1 )
	end)
	if self.ShowCmd == 1 then
		Core.SendToAll( sdata..x )
		return true
	else
		Core.SendToAll( "<"..user.sNick.."> "..x )
	end
end

ATalk.Cmd = {}

-- say with default formating
ATalk.Cmd[ATalk.SayCmd] = function( self, user, sdata )
	local _,_,saystring = string.find( sdata, "^%b<>%s+%p%S+%s+(.+)" )
	if saystring then
		if self.ShowCmd == 1 then
			Core.SendToAll( sdata..self:convert( saystring, self.DefaultFont ) )
		else
			Core.SendToAll( "<"..user.sNick.."> "..self:convert( saystring, self.DefaultFont ) )
		end
	else
		Core.SendToUser(user,"<"..self.Botname.."> "..sdata..": error: no string given, syntax: "..self.Prefix..self.SayCmd.." Your Text" )
	end
end


-- say + option to change formating
ATalk.Cmd[ATalk.SayFormatCmd] = function( self, user, sdata )
	local _,_,saystring = string.find( sdata, "^%b<>%s+%p%S+%s+(.+)" )
	if saystring then
		saystring = self:convertf( saystring )
		if self.ShowCmd == 1 then
			Core.SendToAll( sdata..saystring )
		else
			Core.SendToAll( "<"..user.sNick.."> "..saystring )
		end
	else
		Core.SendToUser(user, "<"..self.Botname.."> "..sdata..": error: no string given, syntax: "..self.Prefix..self.SayFormatCmd.." {Your Text}" )
	end
end

-- help, info
ATalk.Cmd[ATalk.HelpCmd] = function( self, user, sdata )
	Core.SendToUser(user,  "<"..self.Botname.."> \r\n\tASCII TALK "..self.Version.."\r\n"..
		"\t--------------------------------------------\r\n"..
		"\t"..self.Prefix..self.SayCmd.." Your Text   - Converts \"Your Text\" to Ascii (with default font)\r\n"..
		"\t"..self.Prefix..self.SayFormatCmd.." {Your Text}   - Converts everything in {} to Ascii (with default font)\r\n"..
		"\t"..self.Prefix..self.SayFormatCmd.." {\\<font> Your Text}   - Converts everything in {} to Ascii (with given font)\r\n"..
		"\t"..self.Prefix..self.SayFormatCmd.." {\\<font>\\<size> Your Text}   - Converts everything in {} to Ascii (with given font and size)\r\n"..
		"\t"..self.Prefix..self.HelpCmd.."   - Shows you this text\r\n"..
		"\t--------------------------------------------\r\n"..
		"\tTabstops can be done by \"\\t\"\r\n"..
		"\tLinebreaks can be done by \"\\n\"\r\n"..
		"\t--------------------------------------------\r\n"..
		"\t- Available Fonts:"..self:getFonts().."\r\n" )
end

-- GET FONTS
function ATalk:getFonts()
	local s = ""
	for i,v in pairs( self.Fonts ) do
		if i == self.DefaultFont then
			s = s.."\r\n\tFont: "..i.." (default), Size: "
		else
			s = s.."\r\n\tFont: "..i..", Size: "
		end
		for i2,_ in pairs ( v ) do
			s = s..i2..", "
		end
	end
	return s
end

-- COVERT TO ASCII FORMATMODE
function ATalk:convertf( s )
	s = string.gsub( s, "%b{}", function( x )
		x = string.sub( x, 2, -2 )
		local font, size, x2 = "", "",""
		_,_,font,size,x2 = string.find( x, "^\\(%S+)\\(%S+)%s(.+)" )
		if font then
			x = x2
		else
			_,_,font, x2 = string.find( x, "^\\(%S+)%s(.+)" )
			if font and self.Fonts[font] then
				x = x2
				size = self.Fonts[font].Defaultsize
			else
				font = self.DefaultFont
				size = nil
			end
		end
		return self:convert( x, font, size )
	end )
	s = string.gsub( s, "\\t", "\t" )
	s = string.gsub( s, "\\n", "\n" )
	return s
end

-- CONVERT TO ASCII
function ATalk:convert( s, font, size )
	-- replace tab-stops
	s = string.gsub( s, "\\t", "\t" )
	-- replace linebreaks
	s = string.gsub( s, "\\n", "\n" )
	local font = font or self.DefaultFont
	if self.Fonts[font] then
		local size = size or self.Defaultsize[font]
		if self.Fonts[font][size] then
			local maxlen = self.Fonts[font][size].Maxlen
			if string.len( s ) ~= 0 then
				-- automatic linebreak
				local x1 = ""
				while string.len( s ) > maxlen do
					-- check for linebreaks in s
					local lbreak = string.find( string.sub( s, 1, maxlen+1), "(\n)[^\n]+$" ) or string.find( string.sub( s, 1, maxlen+1), 

"\n" )
					if lbreak then
						x1 = x1.."\r\n"..self:toascii( string.sub( s, 1, lbreak-1), font, size )
						s = string.sub( s, lbreak+1, -1 )
					else
						local start = string.find( string.sub( s, 1, maxlen), "(%s)%S+$" )
						if start then
							x1 = x1.."\r\n"..self:toascii( string.sub( s, 1, start-1), font, size )
							s = string.sub( s, start+1, -1 )
						else
							x1 = x1.."\r\n"..self:toascii( string.sub( s, 1, maxlen), font, size )
							s = string.sub( s, maxlen+1, -1 )
						end
					end
				end
				return x1.."\r\n"..self:toascii( s, font, size )
			else
				return "\r\n"
			end
		else
			return "\r\nerror: no such size in font: "..font..", "..size
		end
	else
		return "\r\nerror: no such font: "..font
	end
end

-- STRING TO ASCII
function ATalk:toascii( s, font, size )
	local tosub = {}
	-- check for phrases, emotions etc.
	s = string.gsub( s, "(%S+)", function( c )
		if self.Fonts[font][size].Ascii[c] then
			table.insert( tosub, self.Fonts[font][size].Ascii[c] )
			return "|"  -- Replace with character that is never found in chat or in Ascii
		else
			return c
		end
	end)
	-- create new table with size as entries
	local tASCII = {}
	for _ = 1, self.Fonts[font][size].VLines do
		table.insert( tASCII, " " ) -- one space at the beginning for < in chat
	end
	for c in string.gmatch( s, "." ) do
		if c == "|" then  -- Now replace speacialchar with saved ascii
			local tchar = tosub[1] or self.Fonts[font][size].Default
			table.remove( tosub, 1 )
			tASCII = self:concat( tASCII, tchar )
		elseif c == "\n" then  -- newline char
			tASCII[1] = tASCII[1].."\r\n"
			for i,v in ipairs( tASCII ) do
				if i ~= 1 then
					tASCII[1] = tASCII[1]..v.."\r\n"
					tASCII[i] = " "
				end
			end
		else
			local tchar = self.Fonts[font][size].Ascii[c] or  self.Fonts[font][size].Default
			tASCII = self:concat( tASCII, tchar )
		end
	end
	return table.concat( tASCII, "\r\n" )
end

-- CONCAT 2 ASCIITABLES
function ATalk:concat( tascii1, tascii2 )
	for i,v in ipairs( tascii1 ) do
		tascii1[i] = v..tascii2[i]
	end
	return tascii1
end

-- LOAD FONT
function ATalk:loadFont( sfile )
	local file = io.open( sfile, "r" )
	local getAscii = 0
	local tFont = { Font = "", Fontsize = "", Defaultsize = "", VLines = 0,  Maxlen = 0, Default = {}, Ascii = {} }
	local tDo = { 	["[Font]"] = function() tFont.Font = file:read( "*l" )  end,
			["[Fontsize]"] = function() tFont.Fontsize = file:read( "*l" ) end,
			["[Defaultsize]"] = function() tFont.Defaultsize = file:read( "*l" ) end,
			["[VLines]"] =	function()
						tFont.VLines = tonumber( file:read( "*l" ) )
						for _ = 1, tFont.VLines do
							table.insert( tFont.Default, " " )

						end
					end,
			["[Maxlen]"] = function() tFont.Maxlen = tonumber( file:read( "*l" ) ) end,
			["[Ascii]"] = function() getAscii = 1 end,
	}
	for line in file:lines() do
		if getAscii == 1 then
			local _,_,copychar, tocopychar = string.find( line, "^%[(.+)%]%s=%s%[(.+)%]$" )
			if copychar then
				if tFont.Ascii[tocopychar] then
					 tFont.Ascii[copychar] =  tFont.Ascii[tocopychar]
				end
			else
				local _,_,char = string.find( line, "^%[(.+)%]$" )
				if char then
					tFont.Ascii[char] = {}
					for _ = 1, tFont.VLines do
						local x = string.gsub(  file:read( "*l" ), "|", "?" )
						table.insert( tFont.Ascii[char], x )
					end
				end
			end
		elseif tDo[line] then
			tDo[line]()
		end
	end
	file:close()
	self.Fonts[tFont.Font] = {}
	self.Defaultsize[tFont.Font] = tFont.Defaultsize
	self.Fonts[tFont.Font][tFont.Fontsize] = tFont
end

-- LOAD SINGLE WORD FILE
function ATalk:loadSingleWord( sfile )
	self.SingleWord = {}
	local file = io.open( sfile, "r" )
	local iline = 0
	for line in file:lines() do
		iline = iline + 1
		local _,_,copychar, tocopychar = string.find( line, "^%[(%S+)%]%s=%s%[(%S+)%]$" )
		if copychar then
			if self.SingleWord[tocopychar] then
				self.SingleWord[copychar] = self.SingleWord[tocopychar]
			end
		else
			local _,_,char,vlines = string.find( line, "^%[(%S+)%]:(%d+)$" )
			if char then
				if not self.SingleWord[char] then
					self.SingleWord[char] = {}
					table.insert( self.SingleWordIndex, char )
				end					
				local ascii = ""
				for _ = 1, tonumber( vlines ) do
					local curline =  file:read( "*l" )
					if not curline then
						error( "Line expected; File: "..sfile..", Line: "..iline )
					end
					iline = iline + 1
					ascii = ascii.."\r\n"..string.gsub(  curline, "|", "?" )
				end
				table.insert( self.SingleWord[char], ascii )
			end
		end
	end
	file:close()
	table.sort( self.SingleWordIndex )
end
--[[--

[name]  kicks    
      o?    o   [arg] in the but,...
    ,/I_, /\\,
       |,  |,|,

[name]  kicked    
     o   ,  ?o   [arg] in the head,...
    ,/\/   /\\,
        |, ,|,|

[name]  kicks  the  humiliated
      o?        [arg] in the booty,...
    ,/I_, __o?
       |,  |,|, \\,


[name]  kicks  the  
      o?        [arg] in the face ,...
    ,/I_,?o__
       |,  ,//,|,|


[name]  slaps
     o_,?o /          
    /\  / |        [arg]    
 / |,    ,/ \             



[name]  slaps  
     o_>{{}{*>    
    /\     /\   [arg]   on the head
  /'|,    ,/ \              with a big wet fish !!





  o       
 /|\      
 / \      
 o    
/|\   
/ \  

\ o / 
   |    
  / \  

_ o      
  /\     
 | \      
                            
  ___\o                                
/)       |                 

 o/__      
    |    (\      


  __|      
       \o  
        ( \ 


  \ / 
    |   
  /o\

              
         |__ 
    o/    
   / |    

--]]--


Regards
miago
Being a biatch aint easy ;)

atonal

is true   i habe the same problem    well probaby Mutor can help for  Ascii-Talk
only master,OP Owner can see   Ascii-Talk ,  vips or Register user cant no see Ascii-Talk

if some bory can help to fix this , will apreciet  thanks

miago

Many thanks as usual.
Works fine now  =)

Regards
miago
Being a biatch aint easy ;)

atonal

thanks , now is workin well

good work , beutifull

atonal25

kalle370

I get this error:
[19:57] Syntax C:\Hubs\PrivateFriend\scripts\ASCII.lua:361: attempt to index local 'file' (a nil value)
:(
some can help ?
i use the new 0.4.1.0

Thanks :D

SMF spam blocked by CleanTalk