PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Woodster on 10 March, 2004, 11:40:57

Title: rules
Post by: Woodster on 10 March, 2004, 11:40:57
//- Rules
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+)")

if(cmd==mcmd.. "rules") then

From that how will i know make it so it will open the file from txt/rules.txt

Thanx

Woody

p.s Please bare with me - I am still fairly new to LUA
Title:
Post by: DorianG on 10 March, 2004, 12:08:17
Try 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

--// Rules
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+)")
if cmd == "!rules" then
local rules = "txt/rules.txt"
Readtextfile(user, rules)
return 1
end
end
end