Forum

> > CS2D > Scripts > ChatLog
Forums overviewCS2D overview Scripts overviewLog in to reply

English ChatLog

5 replies
To the start Previous 1 Next To the start

old ChatLog

Marcell
Super User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--********************--
--*****Initialize*****--
--********************--

logdir = "sys/log"

addhook("say","on_say")

function on_say(p,logdir,txt,message)
     local USGN = player(p,"usgn")
	 local pName = player(p,"name")
	 local pIP = player(p,"ip")
     if(io.open(""..logdir.."/chat.log")~=nil) then
	 for p in io.lines(""..logdir.."/chat.log") do
	 l = p
	 if(l~=nil)then

	 l = readfile(""..logdir.."/chat.log")
	 io.output(io.open(""..logdir.."/chat.log", "w+"))
	 io.write("["..USGN"]--["..pIP"] "..pName": "..message"")
	 io.close()
end
end
end
end

I haven't got any error, what do you think?
I just learning LUA and IO file scripting now, so do not insult me about it...

old Re: ChatLog

Deleted User

Quote
Why.... Why can't you tab your script properly?!

Properly tabbed version in case if someone will want to help him >


Problem that I see here is that say hook has only two parameters, which are "id" and "text". So there are not parameters such as "logdir" and "message"

Also, you have a global variable called "logdir", which gets overwritten when function "on_say" gets executed, which changes "logdir" variable to the text that player has written.

I cannot understand what you wanted to do for the rest of the code because it all just doesn't make sense to me.

old Re: ChatLog

Rainoth
Moderator Off Offline

Quote
@user Infinite Rain: Yey, a tabbed version #+1
For your confusion, he takes info checks if he can write it and then writes it. Not like It should work.

@user Marcell: if I were you, I would check if the script works instead of posting to write "what do you think"

old Re: ChatLog

Marcell
Super User Off Offline

Quote
Tested, but havent got any error and still not work

old Re: ChatLog

Zeik
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
addhook("say","on_say")
function on_say(p,txt)
    local USGN = player(p,"usgn")
    local pName = player(p,"name")
    local pIP = player(p,"ip")
    local file = io.open("sys/log/chat.log", "a+")
	file:write("["..USGN.."]--["..pIP.."] "..pName..": "..txt.."\n")
	file:close()
	return 0
end

I almost go crazy don't knowing why "file" was returning "nil". It was because I had to manually create the "log" directory for it to work.

Your code is very weird and unreadable, just try to understand mine.

old Re: ChatLog

VADemon
User Off Offline

Quote
user Zeik ninja'd me, however:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
chatlogDir = "chatlogs/"

addhook("say", "chatlog_say", -9000)

function chatlog_say(id, say)
	local state, file = pcall(io.open, chatlogDir .. os.date("%Y_%m_%d", os.time()) .. "-Chat.log", "a+")

	if file then
		file:write("[" .. os.date("%H:%M:%S", os.time()) .. "]: #" .. player(id, "usgn") .. ", " .. player(id, "ip") .. ", " .. player(id, "name") .. ": " .. say .. "\n") -- \n == \r\n here, dunno
		file:close()
	else
		print("©255000000[Chatlog] Error! Cannot open/create file or directory '<your CS2D directory>/" .. chatlogDir .. "' does not exist!")
	end

end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview