View previous topic :: View next topic |
Author |
Message |
TroveLord
Joined: 22 Nov 2006 Posts: 136 Location: Italy
|
Posted: Mon Oct 06, 2008 16:37 Post subject: |
|
|
Anyone else have it? or can I get some direction about setting up the scripts? |
|
Back to top |
|
|
NewPoint
Joined: 23 Oct 2007 Posts: 13
|
Posted: Sat Oct 11, 2008 9:58 Post subject: |
|
|
Here is the function I use to send messages:
Code: | int SendMessage(object oSender, int nChannel, string sMessage, object oRecipient=OBJECT_INVALID) {
if (!GetIsObjectValid(oSender)) return FALSE;
if (GetStringLength(sMessage) == 0) return FALSE;
if (FindSubString(sMessage, "¬")!=-1) return FALSE;
if (nChannel == CHAT_CHANNEL_PRIVATE && !GetIsObjectValid(oRecipient)) return FALSE;
return NWNXGetInt("CHAT", "SPEAK", ObjectToString(oSender) + "¬" + ObjectToString(oRecipient) + "¬" + IntToString(nChannel) + "¬" + sMessage, 0);
} |
The chat channels are:
Code: | const int CHAT_CHANNEL_TALK = 17;
const int CHAT_CHANNEL_SHOUT = 18;
const int CHAT_CHANNEL_WHISPER = 19;
const int CHAT_CHANNEL_PRIVATE = 20;
const int CHAT_CHANNEL_SERVER_MSG = 21;
const int CHAT_CHANNEL_PARTY = 30; |
To get the message the player typed into the chat window I use this:
Code: | // get text
string sText = NWNXGetString("CHAT", "TEXT", "", 0);
string sMsg;
int nChannel = StringToInt(GetStringLeft(sText,2));
int nTo = StringToInt(GetSubString(sText,2,10));
sText = GetSubString(sText, 12, GetStringLength(sText)); |
To stop the message the player just sent I use:
Code: | NWNXSetInt("CHAT", "SUPRESS", "", 0, 1); |
All of this works great with 0.3.3 but not with 0.3.5. I switch my test server over to NWNX 4.09 and everything works fine except for this. I haven't tested Chat 0.3.3 with NWNX 4.09 yet but I will this weekend.
You can get the old demo mod nwnx_demo_chat.7z |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
Atruatzin SC
Joined: 12 Oct 2008 Posts: 1
|
Posted: Sun Oct 12, 2008 16:11 Post subject: |
|
|
Yes, it works in NWNX4 1.09.
Thanks a lot. |
|
Back to top |
|
|
TroveLord
Joined: 22 Nov 2006 Posts: 136 Location: Italy
|
Posted: Mon Oct 13, 2008 15:48 Post subject: |
|
|
Thanks for the examples NewPoint, I still have a few questions.
Do I need to use void dmb_PCin(object oPC); and void dmb_PCout(object oPC); in the module events? (on enter and on exit respectively)
How do I get the sender and the receiver when hooking a private message?
Thanks. |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
TroveLord
Joined: 22 Nov 2006 Posts: 136 Location: Italy
|
Posted: Mon Oct 13, 2008 23:07 Post subject: |
|
|
So you changed
Code: | int NWNXChat_SendMessage(object oSender, int nChannel, string sMessage, object oRecipient=OBJECT_INVALID) |
to
Code: | void NWNXChat_SendMessage(object oSender, int nChannel, string sMessage, object oRecipient=OBJECT_INVALID) |
But the function still has returns
Code: | void NWNXChat_SendMessage(object oSender, int nChannel, string sMessage, object oRecipient=OBJECT_INVALID){
if (!GetIsObjectValid(oSender)) return;
if (FindSubString(sMessage, "¬")!=-1) return;
if (nChannel == CHAT_CHANNEL_PRIVATE && !GetIsObjectValid(oRecipient)) return;
int nResult = NWNXGetInt("CHAT", "SPEAK", ObjectToString(oSender)+"¬"+ObjectToString(oRecipient)+"¬"+IntToString(nChannel)+"¬"+sMessage, 0);
if (nResult) return TRUE;
else return FALSE;
} |
And they should be removed.
I would also add the DM channel constant
Code: | const int CHAT_CHANNEL_DM = 14; |
That's all for now. |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
TroveLord
Joined: 22 Nov 2006 Posts: 136 Location: Italy
|
Posted: Tue Oct 14, 2008 0:32 Post subject: |
|
|
Just a minor, since you changed NWNXChat_SendMessage back to a int, what about changing
Code: | if (nResult) return TRUE;
else return FALSE; |
with return nResult;
EDIT:
Since the function is an int, the first three checks should return a value.
The function should look like:
Code: | int NWNXChat_SendMessage(object oSender, int nChannel, string sMessage, object oRecipient=OBJECT_INVALID)
{
if(!GetIsObjectValid(oSender)) return FALSE;
if(FindSubString(sMessage, "¬")!=-1) return FALSE;
if(nChannel == CHAT_CHANNEL_PRIVATE && !GetIsObjectValid(oRecipient)) return FALSE;
return NWNXGetInt("CHAT", "SPEAK", ObjectToString(oSender)+"¬"+ObjectToString(oRecipient)+"¬"+IntToString(nChannel)+"¬"+sMessage, 0);
} |
|
|
Back to top |
|
|
NewPoint
Joined: 23 Oct 2007 Posts: 13
|
Posted: Tue Oct 14, 2008 7:32 Post subject: |
|
|
TroveLord wrote: | Thanks for the examples NewPoint, I still have a few questions.
Do I need to use void dmb_PCin(object oPC); and void dmb_PCout(object oPC); in the module events? (on enter and on exit respectively)
How do I get the sender and the receiver when hooking a private message?
Thanks. |
As fare I can know you still need to store the and ID for the PC as a mod var. Here is what I use to set it as part of the onpcloaded event script:
Code: | // set chat id mod variable for the pc
int nID = r2_GetChatID(oPC);
if (nID != -1) SetLocalObject(GetModule(), "dmbPC_" + IntToString(nID), oPC); |
Code: | int r2_GetChatID(object oPC) {
if (!GetIsObjectValid(oPC))
return -1;
if (!GetIsPC(oPC) && !GetIsPossessedFamiliar(oPC) && !GetIsDM(oPC) && !GetIsDMPossessed(oPC))
return -1;
return NWNXGetInt("CHAT", "GETID", ObjectToString(oPC), ObjectToInt(oPC));
}
|
and to retreive it:
Code: | object GetChatPC(int nID) {
return GetLocalObject(GetModule(), "dmbPC_" + IntToString(nID));
} |
I'm not sure what the NWNXGetInt("CHAT", "GETID", ObjectToString(oPC), ObjectToInt(oPC)) returns. As you can see I'm assuming the integer will always be positive if they PC is valid.
If it simply returns the object reference as in integer then this may no longer be necessarily with the IntToObject function. Someday I may try it out. |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
TroveLord
Joined: 22 Nov 2006 Posts: 136 Location: Italy
|
Posted: Tue Oct 14, 2008 12:52 Post subject: |
|
|
virusman, are you sure you uploaded the right file? it looks the same of RC2 to me. What's the difference?
Also, have you considered my suggested change in the post above? |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Tue Oct 14, 2008 13:05 Post subject: |
|
|
right, it was the old version. Updated. |
|
Back to top |
|
|
TroveLord
Joined: 22 Nov 2006 Posts: 136 Location: Italy
|
Posted: Tue Oct 14, 2008 13:21 Post subject: |
|
|
Awesome. |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
|