read .txt from folder cant make it workin'
 

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

read .txt from folder cant make it workin'

Started by b_w_johan, 19 November, 2004, 19:54:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

b_w_johan

cant get it right...
i was trying to make a small script which reads from a folder "txt" and opens *.txt depending the command.
well i was puzzeling all the time and couldn't figure it out must be something very small and stupid...


this is what i try to make work now..


bot = "Guard"
AantUur = 1   -- aantal uren
hrs = 1000 * 60 * 60 * AantUur

function Main()
   SetTimer(hrs)
   StartTimer()
end

function OnTimer()
   SendRules(user)
end

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") then
   data=strsub(data,1,strlen(data)-1)
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
end
end


if (cmd=="+rules") then
   SendRules(user)
end



function SendRules(user)
   readfrom("txt/rules.txt")
   local text = "\r\n"
   while 1 do
      line = read()
         if line == nil then
            break
         end
      text = text.."\r\n"..line
   end
   user:SendPM(bot,text.."|")
   readfrom()
end




this is what i started with:

bot = "Guard"
AantUur = 1   -- aantal uren
textfile = "txt/Rules.txt"
hrs = 1000 * 60 * 60 * AantUur


function Main()
   SetTimer(hrs)
   StartTimer()
end

function OnTimer()
   massMessageToAll()
end




if (cmd=="+rules") then
   SendUserRules(user)
end

function SendUserRules(user)
   readfrom("txt/Rules.txt")
   while 1 do
      line = read()
      if line == nil then break end
         SendToAll(bot, line)
      end
   readfrom()
end

function massMessageToAll()
local handle = openfile(textfile, "r")
   if (handle ~= nil) then
      local line = read(handle)
                  Temptimerfile = "\r\n"
      while line do
         Temptimerfile = Temptimerfile.."\r\n"..line
         line = read(handle)
      end
         SendPmToAll(bot, Temptimerfile)
      closefile(handle)
   end
end




but they wont work ...
(yes i picked the small box in ptokax to enable textfile support someone pointed me to that..)
so if you could help me i would be very happy ....


Thanx Johan Nolte
checkout http://wwhublist.com/index.php for my World Wide HubList project!

Themaster

maybe you need this

function Readtextfile(user, file)
   	local filecontents = ""
	local handle = openfile(file, "r")
	if (handle ~= nil) then
		local line = read(handle)
		while line do
        	filecontents = filecontents..line.."\r\n"
		line = read(handle)
		end
		closefile(handle)
      	user:SendPM(bot, filecontents)
	end
end
peace out...and love to your all scripter..that do the hard work  :D And all thx to your all there are here 2 help!!! :]

blade.lir.dk

b_w_johan

I can't get it working can you put all of the source in here ??
and tell me if it worked by you ?
cause i used that part but it isn't going to work..
grrrr

thx Johan
checkout http://wwhublist.com/index.php for my World Wide HubList project!

Themaster

Kos = "[RuLeR]"

Command = "+rules"

MasRules = "text/masrules.txt"
OpRules = "text/oprules.txt"
VipRules = "text/viprules.txt"
RegRules = "text/regrules.txt"

function Main() 
	frmHub:RegBot(Kos) 
end 

function DataArrival(ustring,dstring) 
	if strsub(dstring, 1, 1) == "<" then
		dstring=strsub(dstring,1,strlen(dstring)-1)
		local s,e,cmd = strfind(dstring,"%b<>%s+(%S+)")
	
		if cmd == Command then
			if ustring.iProfile == 0 then
				file = MasRules
				WhileRead(ustring,file)
			elseif ustring.bOperator then
				file = OpRules
				WhileRead(ustring,file)
			elseif ustring.iProfile == 2 then
				file = VipRules
				WhileRead(ustring,file)
			else
				file = RegRules
				WhileRead(ustring,file)
			end
		end 
	end
end

function WhileRead(ustring,file)
	readfrom(file)
	while 1 do 
		line = read() 
		if line == nil then
			break
		end 
		ustring:SendPM(Kos,line) 
	end
 	readfrom()
end
peace out...and love to your all scripter..that do the hard work  :D And all thx to your all there are here 2 help!!! :]

blade.lir.dk

b_w_johan

Thank you very much now its working !
lol only change it a bit to show themevery 2 owrs in main ..
checkout http://wwhublist.com/index.php for my World Wide HubList project!

Themaster

peace out...and love to your all scripter..that do the hard work  :D And all thx to your all there are here 2 help!!! :]

blade.lir.dk

SMF spam blocked by CleanTalk