Forum

> > CS2D > Scripts > how to make private message?
Forums overviewCS2D overview Scripts overviewLog in to reply

English how to make private message?

9 replies
To the start Previous 1 Next To the start

old how to make private message?

Eternal
User Off Offline

Quote
how to make private message , i want it like this
EXAMPLE :
player 1 typing !sayto 2 Hi !!
player 2 get messages Hi !!
without others can see that message

how to make it? teach me pls

old Re: how to make private message?

DC
Admin Off Offline

Quote
• use the say hook, cs2d lua hook say
• use Lua string commands to detect the "!sayto" and the player id / actual message

in case !sayto was found:
• use return 1 to suppress the standard chat
• use cs2d lua cmd msg2 to send the message just to that specific player (you can also use cs2d lua cmd msg2 a second time to display the text for the sender of the message as well so he knows that he actually sent it)

old Re: how to make private message?

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function string.split(str,pat)
	local t={}
	for word in string.gmatch(str,pat) do
		if word~="" then
			table.insert(t,word)
		end
	end
	return t
end

addhook("say","pmessaging",118)
function pmessaging(id,txt)
	local t=string.split(txt,"(%w+)")
	if (t[1]=="!sayto") then
		local ply=tonumber(t[2])
		local words=txt:sub(t[1]:len()+1+t[2]:len())
		msg2(ply,player(id,"name")..": "..words)
		return 1
	end
end

Probably not the most efficient implementation, but I think it should work.

old Re: how to make private message?

Eternal
User Off Offline

Quote
user EngiN33R has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function string.split(str,pat)
	local t={}
	for word in string.gmatch(str,pat) do
		if word~="" then
			table.insert(t,word)
		end
	end
	return t
end

addhook("say","pmessaging",118)
function pmessaging(id,txt)
	local t=string.split(txt,"(%w+)")
	if (t[1]=="!sayto") then
		local ply=tonumber(t[2])
		local words=txt:sub(t[1]:len()+1+t[2]:len())
		msg2(ply,player(id,"name")..": "..words)
		return 1
	end
end

Probably not the most efficient implementation, but I think it should work.


Engin33R , it doesn't work

old Re: how to make private message?

EP
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
26
27
28
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end 


addhook("say","pmsg")
function pmsg(id,txt)
local p = totable(txt)
local cmd = (p[1])
	if cmd == "!sayto" then
		local pl = tonumber(p[2])
		if player(pl,"exists") then
				local msg= string.sub(txt, 10, #txt)
				msg2(pl,"©235143041"..player(id,"name").." (PRIVATE): "..msg)
				msg2(id,"©235143041Private message to "..player(pl,"name")..": "..msg.." was sent!")
				return 1
		else
				msg2(id,"©255000000This player doesn't exists!")
				return 1
		end
	return 1
	end
end
works

old Re: how to make private message?

sheeL
User Off Offline

Quote
user EP has written
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
26
27
28
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end 


addhook("say","pmsg")
function pmsg(id,txt)
local p = totable(txt)
local cmd = (p[1])
	if cmd == "!sayto" then
		local pl = tonumber(p[2])
		if player(pl,"exists") then
				local msg= string.sub(txt, 10, #txt)
				msg2(pl,"©235143041"..player(id,"name").." (PRIVATE): "..msg)
				msg2(id,"©235143041Private message to "..player(pl,"name")..": "..msg.." was sent!")
				return 1
		else
				msg2(id,"©255000000This player doesn't exists!")
				return 1
		end
	return 1
	end
end
works


or
1
2
3
4
5
6
7
8
9
10
11
12
addhook("say","action43")
function action43(id,txt)
     if string.sub(txt,0,3) == "@pm" then
     local pl = string.sub(txt,5,6)
     if player(pl,"exists") then
          local msg = string.sub(txt,7,99)
          msg2(pl,"©235143041"..player(id,"name").." (PRIVATE): "..msg)
          msg2(id,"©000255000Your message has been succesful sent!")
          return 1
     end
     end
end

by @user EP:

old Re: how to make private message?

MikuAuahDark
User Off Offline

Quote

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook("say"privatemsg")
function privatemsg(id,txt)
	if txt:sub(1,6)=="!sayto" then
		pl = 0
		msg = ""
		if txt:sub(9,9)~=" " then
			pl = tonumber(txt:sub(8,9))
			msg = txt:sub(11)
		else
			pl = tonumber(txt:sub(8,8))
			msg = txt:sub(10)
		end
		if player(pl,"exists") then
			msg2(id,string.char(169).."255255255Private message "..player(pl,"name")..": "..msg)
			msg2(pl,string.char(169).."255255255"..player(id,"name").."(Private): "..msg)
		end
		return 1
	end
end
say: !sayto <id> <message>
tested!
http://i39.tinypic.com/16lgx94.png
edited 1×, last 13.04.12 03:22:32 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview