logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Chat plugin for NWNX4?
Goto page Previous  1, 2, 3 ... 8, 9, 10, 11  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Mon Oct 06, 2008 16:37    Post subject: Reply with quote

Anyone else have it? or can I get some direction about setting up the scripts?
Back to top
View user's profile Send private message
NewPoint



Joined: 23 Oct 2007
Posts: 13

PostPosted: Sat Oct 11, 2008 9:58    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sun Oct 12, 2008 13:09    Post subject: Reply with quote

There may be a problem with hooking in 0.3.5. I've compiled a fixed version:
http://data.virusman.ru/nwn/nwnx4/xp_chat-0.3.6-rc1.rar
please test it. If it works, I'll release it with an updated NWScript library shortly.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Atruatzin SC



Joined: 12 Oct 2008
Posts: 1

PostPosted: Sun Oct 12, 2008 16:11    Post subject: Reply with quote

Yes, it works in NWNX4 1.09.

Thanks a lot.
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Mon Oct 13, 2008 15:48    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Oct 13, 2008 21:40    Post subject: Reply with quote

Updated NWScript library:
http://data.virusman.ru/nwn/nwnx4/nwnx_chat.nss-0.3.6-rc1.rar
please test it as well.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Mon Oct 13, 2008 23:07    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Oct 14, 2008 0:08    Post subject: Reply with quote

Fixed:
http://data.virusman.ru/nwn/nwnx4/nwnx_chat.nss-0.3.6-rc2.rar
Thanks, TroveLord.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Oct 14, 2008 0:32    Post subject: Reply with quote

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
View user's profile Send private message
NewPoint



Joined: 23 Oct 2007
Posts: 13

PostPosted: Tue Oct 14, 2008 7:32    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Oct 14, 2008 11:10    Post subject: Reply with quote

GETID returns player ID for PC (not PC object ID). It's necessary to get the recipient of a private message (Tell).
Updated library:
http://data.virusman.ru/nwn/nwnx4/nwnx_chat.nss-0.3.6-rc3.rar
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Oct 14, 2008 12:52    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Oct 14, 2008 13:05    Post subject: Reply with quote

Embarassed right, it was the old version. Updated.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Oct 14, 2008 13:21    Post subject: Reply with quote

Awesome. Very Happy
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Oct 14, 2008 14:55    Post subject: Reply with quote

NWNX4 Chat 0.3.6
http://data.virusman.ru/nwn/nwnx4/xp_chat-0.3.6.rar
  • Fixed the hooking function
  • Updated the scripting library
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Goto page Previous  1, 2, 3 ... 8, 9, 10, 11  Next
Page 9 of 11

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group