PDA

View Full Version : !pm command help!


tbofram
6th January 2011, 17:54
i am making a command in a insim to private message people and here is a example of the code i made. i desided to just let the forum help me because i have no clue on how to finish this command. sorry if it such a simple command i just dont know!!!

[Command("pm", "pm <username> <message>")]
public void pm(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
// string Send = StrMsg[1];

foreach (clsConnection i in Connections)
{
if (i.Username == Msg.Remove(0, 4))
{
InSim.Send_MTC_MessageToConnection("^6> ^7Private Message from " + Connections[GetConnIdx(MSO.UCID)].PlayerName, i.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^6> ^7" + Msg.Remove(0, StrMsg[1].Length + 1), i.UniqueID, 0);
}

}

skywatcher122
6th January 2011, 22:21
the next strmsg must be removed so the messge will be received

I'll give a sample for yah c'ya in msn

PoVo
7th January 2011, 08:01
the next strmsg must be removed so the messge will be received

I'll give a sample for yah c'ya in msn

Is it so hard posting the code here? :razz: Or you want 1202419347803174 more threads like this? :shrug:

Heiko1
7th January 2011, 08:25
Here it is guys...
what a pitty that no other coder post codes.. like this easy things..

case "!pmsg":
if (StrMsg.Length > 2)
{
string Message = Msg.Remove(0, 4 + StrMsg[1].Length);
bool SendComplete = false;

foreach (clsConnection Conn in Connections)
{
if (Conn.Username.ToUpper().Contains(StrMsg[1].ToUpper()))
{
if (Connections[GetConnIdx(MSO.UCID)].Username == StrMsg[1])
{
InSim.Send_MTC_MessageToConnection("^3>^7 You cant can send a pm to yourself!", MSO.UCID, 0);
}
else
{

SendComplete = true;
InSim.Send_MTC_MessageToConnection("Private Message :", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("To " + Conn.PlayerName , MSO.UCID, 0);

InSim.Send_MTC_MessageToConnection("^7 " + Message, MSO.UCID, 0);

InSim.Send_MTC_MessageToConnection("Private Message :", Conn.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("From " + Connections[GetConnIdx(MSO.UCID)].PlayerName, Conn.UniqueID, 0);

InSim.Send_MTC_MessageToConnection("^^7 " + Message, Conn.UniqueID, 0);
}


}
}

}

else
{
InSim.Send_MTC_MessageToConnection("^3>^7 Invalid message or username.", MSO.UCID, 0);
}
break;

skywatcher122
7th January 2011, 08:32
Here it is guys...
what a pitty that no other coder post codes.. like this easy things..

case "!pmsg":
if (StrMsg.Length > 2)
{
string Message = Msg.Remove(0, 4 + StrMsg[1].Length);
bool SendComplete = false;

foreach (clsConnection Conn in Connections)
{
if (Conn.Username.ToUpper().Contains(StrMsg[1].ToUpper()))
{
if (Connections[GetConnIdx(MSO.UCID)].Username == StrMsg[1])
{
InSim.Send_MTC_MessageToConnection("^3>^7 You cant can send a pm to yourself!", MSO.UCID, 0);
}
else
{

SendComplete = true;
InSim.Send_MTC_MessageToConnection("Private Message :", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("To " + Conn.PlayerName , MSO.UCID, 0);

InSim.Send_MTC_MessageToConnection("^7 " + Message, MSO.UCID, 0);

InSim.Send_MTC_MessageToConnection("Private Message :", Conn.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("From " + Connections[GetConnIdx(MSO.UCID)].PlayerName, Conn.UniqueID, 0);

InSim.Send_MTC_MessageToConnection("^^7 " + Message, Conn.UniqueID, 0);
}


}
}

}

else
{
InSim.Send_MTC_MessageToConnection("^3>^7 Invalid message or username.", MSO.UCID, 0);
}
break;

that code is like !pmsg <message> <username> sounds like sending a cash :razz:

why not try this


[Command("pm", "pm <username> <message>")]
public void pm(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
if (StrMsg.Length > 2)
{
if (Connections[GetConnIdx(MSO.UCID)].Username == StrMsg[1] && StrMsg[1].Length > 1)
{
InSim.Send_MTC_MessageToConnection("^4|^7 You can't send PM to yourself!", MSO.UCID, 0);
}
else
{
clsConnection Conn = Connections[GetConnIdx(MSO.UCID)];
bool PMUserFound = false;
foreach (clsConnection C in Connections)
{
string Message = Msg.Remove(0, C.Username.Length + 5);

if (C.Username == StrMsg[1] && StrMsg[1].Length > 1)
{
PMUserFound = true;

InSim.Send_MTC_MessageToConnection("^4|^3 Message Sent To: ^7" + C.NoColPlyName + " (" + C.Username + ")", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^4|^3 Msg: ^7" + Message, MSO.UCID, 0);

InSim.Send_MTC_MessageToConnection("^4|^3 PM From: ^7" + Conn.NoColPlyName + " (" + Conn.Username + ")", C.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^4|^3 Msg: ^7" + Message, C.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^4|^3 To reply use ^2!pm " + Conn.Username + " <message>", C.UniqueID, 0);

foreach (clsConnection F in Connections)
{
if ((F.IsAdmin == 1 && F.IsSuperAdmin == 1) && F.UniqueID != MSO.UCID)
{
InSim.Send_MTC_MessageToConnection("^4|^3 PM From: ^7" + Conn.NoColPlyName + " to " + C.NoColPlyName, F.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^4|^3 Msg: ^7" + Message, F.UniqueID, 0);
}
}
}
}
if (PMUserFound == false)
{
InSim.Send_MTC_MessageToConnection("^4|^7 Username not found.", MSO.UCID, 0);
}
}
}
else
{
InSim.Send_MTC_MessageToConnection("^4|^7 Invalid Command.", MSO.UCID, 0);
}
}


note: NoColPlyName is like removing all colors of playername so just replace it in PlayerName perhaps and remove the IsSuperAdmin if only u don't have it :P

Is it so hard posting the code here? Or you want 1202419347803174 more threads like this?

why not post yours? so it would be helpful for those 1202419347803174 threads that possibly in the future? ;)

Heiko1
7th January 2011, 14:01
that code is like !pmsg <message> <username> sounds like sending a cash :razz:



your code is the same as mine -.-
and im not using <msg> <username>
im doing the same as you.. !pm <username> <msg>

first read then talk :)

skywatcher122
7th January 2011, 14:06
im using StrMsg not msg removing ;)

Heiko1
7th January 2011, 14:13
read what ive got includet StrMsg[x] -.- its the same

skywatcher122
7th January 2011, 14:22
AFAIK, the codes like StrMsg[1] u did on sample works only in non-spaced usernames ;) so thats why i made StrMsg[1] && StrMsg[1].Lenghts > 1 ;) well lets just not fight with the !pm code anyways ;)

tbofram
7th January 2011, 17:19
haha thanks both of you.

tbofram
7th January 2011, 18:17
ok the code worked i just done a bit of a mod to it and it worked fine thanks

broken
7th January 2011, 22:57
Both of these won't work with usernames, containing spaces.

I recently stripped out my pm command from OsC, which is based on dougie-lampkin's cruise thingo, because I was sending it to someone. It's not very optimized, I'm sure, that I can rewrite it in a much better way, but it works, so here it is:

case "!pm":
try
{
if (Msg.Remove(0, 4).Length > 1)
{
string message = Msg.Remove(0, 3);
string userright = "wrong";
foreach (clsConnection PMuser in Connections)
{
if (message.IndexOf(PMuser.Username) == 1)
{
userright = "right";
string PMmsg = message.Remove(message.IndexOf(PMuser.Username), (PMuser.Username.Length + 1));
InSim.Send_MTC_MessageToConnection("^3» ^7Personal message to " + PMuser.PlayerName + "^7:", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^3»^7" + PMmsg, MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^3» ^7Personal message from " + Connections[GetConnIdx(MSO.UCID)].PlayerName + "^7:", PMuser.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^3»^7" + PMmsg, PMuser.UniqueID, 0);
}
}
if (userright != "right")
{
InSim.Send_MTC_MessageToConnection("^3» ^1Wrong syntax.", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^3» ^2The right syntax is: !pm [username] [message].", MSO.UCID, 0);
}
}
}
catch
{
InSim.Send_MTC_MessageToConnection("^3» ^1Your message could not be sent.", MSO.UCID, 0);
}
break;

I'm not very happy about it. In fact - I am not at all happy about it. But when I reach that point in my current project, I'll post the pm snippet, probably in the thread I posted a while ago (http://www.lfsforum.net/showthread.php?t=60687).

[..]
what a pitty that no other coder post codes.. like this easy things..
[..]

?!

skywatcher122
7th January 2011, 23:20
actually I forgot to add this syntax

C.Username.Contains(StrMsg[1]) == true && C.Username.Contains(StrMsg[2]) == true
but meh your code is doing fine broken ;)

broken
7th January 2011, 23:22
actually I forgot to add this syntax

C.Username.Contains(StrMsg[1]) == true && C.Username.Contains(StrMsg[2]) == true
but meh your code is doing fine broken ;)

Your snippet is even worse than mine.. I, personally, would never count on such a thing. Sorry.. :razz:

mariuba2
8th January 2011, 02:43
Maybe try this?

PHP Code:
C.Username.Contains.(" ") + (StrMsg[1]) == true && C.Username.Contains.(" ") + (StrMsg[2]) == true *

Or

PHP Code:
C.Username.(StrMsg[1]) == true && C.Username.Contains(StrMsg[2]) == true *
{*
If Contains(StrMsg[1]) == true .....blah blah

Maybe try InSim.Parse("Crash"); ??

broken
8th January 2011, 12:18
Maybe try this?

PHP Code:
C.Username.Contains.(" ") + (StrMsg[1]) == true && C.Username.Contains.(" ") + (StrMsg[2]) == true *

Or

PHP Code:
C.Username.(StrMsg[1]) == true && C.Username.Contains(StrMsg[2]) == true *
{*
If Contains(StrMsg[1]) == true .....blah blah

Maybe try InSim.Parse("Crash"); ??

How can you count on such a thing? O_O

What would you count on more:
1 - A script that iterates through all the connections, and checks if the string after "!pm " starts with the username of somebody;
Or 2 - A script that checks whether the 1st and 2nd word after !pm are contained(anywhere) in the username?


I would never count on 2. It makes no sense, and if you have a 3 word username after !pm, it just becomes irrelevant.

Sorry if I sound a bit harsh, I had no intentions to, but this just isn't the way.

mariuba2
8th January 2011, 12:25
How can you count on such a thing? O_O

What would you count on more:
1 - A script that iterates through all the connections, and checks if the string after "!pm " starts with the username of somebody;
Or 2 - A script that checks whether the 1st and 2nd word after !pm are contained(anywhere) in the username?


I would never count on 2. It makes no sense, and if you have a 3 word username after !pm, it just becomes irrelevant.

Sorry if I sound a bit harsh, I had no intentions to, but this just isn't the way.

^^ i dont know, i was just trying to see if i was right with the code.