English how to make private message?

9 replies
Goto Page
To the start Previous 1 Next To the start
12.04.12 06:46:39 pm
Up
Eternal
User
Offline Off
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
12.04.12 06:53:34 pm
Up
DC
Admin
Offline Off
• 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)
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
12.04.12 07:13:50 pm
Up
Eternal
User
Offline Off
i don't know how to make string commands
to go to detect !sayto
can someone help me??
12.04.12 07:36:48 pm
Up
EngiN33R
Moderator
Offline Off
Code:
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.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
12.04.12 08:41:37 pm
Up
Eternal
User
Offline Off
user EngiN33R has written:
Code:
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
12.04.12 10:43:52 pm
Up
EngiN33R
Moderator
Offline Off
More information, for fuck's sake!

• What exactly do you do?
• Any errors in the console?
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
12.04.12 11:19:43 pm
Up
Jhony
User
Offline Off
how ? :S
12.04.12 11:20:27 pm
Up
EP
User
Offline Off
Code:
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
12.04.12 11:21:38 pm
Up
sheeL
User
Offline Off
user EP has written:
Code:
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
Code:
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:
13.04.12 03:12:16 am
Up
MikuAuahDark
User
Offline Off

Code:
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
Hello? Are you there, Tae Hanazono?
To the start Previous 1 Next To the start