Aller au contenu

Photo

Chat Color


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
YeezY

YeezY
  • Members
  • 5 messages

Hi!

 

Code:

#include "inc_colortext"
void main()
{
string sInput = GetPCChatMessage();
string sFirst = GetStringLeft(sInput, 3);

if(sFirst == "/me") // me
{
sInput = ColorText(sInput, 186, 85, 211);
SetPCChatMessage(sInput);
}

if(sFirst == "/rp") // role play action
{
sInput = ColorText(sInput, 50, 205, 50);
SetPCChatMessage(sInput);
}

if(sFirst == "/ds") // dungeon master comment
{
sInput = ColorText(sInput, 255, 215, 0);
SetPCChatMessage(sInput);
}

if(sFirst == "/oo") // out of character
{
sInput = ColorText(sInput, 170, 170, 170);
SetPCChatMessage(sInput);
}

}

Need some help with this script. It should work like this, if someone type: "/me blabla", on chat should be only "babla", without this first 3 chars (/me). I tried to do this with GetSubString but it didnt work. Any idea?



#2
CaveGnome

CaveGnome
  • Members
  • 290 messages
Maybe you need to extract a 3 characters string and not just 1 in the GetStringLeft. If you don't have it, get the Lexicon on the neverwintervault (there is also an internet based Lexicon). It is probably the best reference to learn NWN scripting.
  • YeezY aime ceci

#3
YeezY

YeezY
  • Members
  • 5 messages

I know it. I change it to 3 but it still don't work. I have no idea how to remove 3 first characters.



#4
CaveGnome

CaveGnome
  • Members
  • 290 messages

Sorry, i am not well versed in "GetPCChatMessage" and "SetPCChatMessage()" use. A good idea would be to filter the input to just get the PC talk. Something in top script position like:

object oPC = GetPCChatSpeaker();
if(!GetIsPC(oPC))
{return;}

 

If this doesn't help, don't despair, there are many great scripters (far far better than your humble failing gnome ;-) haunting this place.


  • YeezY aime ceci

#5
Kerick Ulthrall

Kerick Ulthrall
  • Members
  • 2 messages

Maybe try finding the length of sInput and subtract three from it and use that with GetStringRight.  Something like:

string sDisplay = GetRightString(sInput,(GetStringLength(sInput) - 3)).  I don't Code NWN, but That is the idea anyway.

 - Mark


  • YeezY aime ceci

#6
Proleric

Proleric
  • Members
  • 2 346 messages
That's correct, except it's -4 because you want to remove the blank, too.
  • Kerick Ulthrall et YeezY aiment ceci

#7
KMdS!

KMdS!
  • Members
  • 189 messages

I saw some things in your code that could be better implemented. The code I have here will check any chat strings run past this function and will only modify those strings being colorized. Otherwise, no modification is done and the string is passed unchanged. I included code to strip he colorizing characters if found. i can't test it per say as I don't have the inc_colortext include. There must be a space character separating ther colorization tokens and the actual message string. Should you want I can include a check to see if the space exists or not and modify the characters not included in the message.

 

Edited, Meaglyn's suggestions included. 

#include "inc_colortext"
 
void main()
{
    int i1, i2, i3;
    int bColorize = FALSE;
    int iStringLength;
    // store chat string
    string sInput = GetPCChatMessage();
    // store possible colorize token
    string sFirst = GetStringLeft(sInput, 3);
 
    // check against colorize token string
    if(sFirst == "/me") // me
    {
        i1=186; i2=85; i3=211;
        bColorize=TRUE;
     }
    else if(sFirst == "/rp") // role play action
    {
        i1=50; i2=205; i3=50;
        bColorize=TRUE;
    }
    else if(sFirst == "/ds") // dungeon master comment
    {
        i1=255; i2=215; i3=0;
        bColorize=TRUE;
    }
    else if(sFirst == "/oo") // out of character
    {
        i1=170; i2=170; i3=170;
        bColorize=TRUE;
    }
 
    if(bColorize)
    {
        // get the length of the string
        iStringLength = GetStringLength(sInput);
        // cut out the token before any processing
        sInput = GetStringRight(sInput, iStringLength-4);
        //colorize the string
        sInput = ColorText(sInput, i1, i2, i3);
        SetPCChatMessage(sInput);
    }
}

  • YeezY aime ceci

#8
meaglyn

meaglyn
  • Members
  • 807 messages

That won't work KMds!.   You're colorizing the string before you remove the first characters. But colorizing it adds characters at the beginning and end of the string. If you are really trying to avoid doing extra work,  why not use 3 int variables and just set those to the 3 color values in the main if clauses. Then in your bColorize section strip the string and colorize it.   Also, I'd put the SetPCChatMessage line inside those brackets too.


  • YeezY aime ceci

#9
KMdS!

KMdS!
  • Members
  • 189 messages

Original code posted has been modified with the information provided by Meaglyn. I read up on the chat functions and agree with his input. Thanks.


  • YeezY aime ceci

#10
YeezY

YeezY
  • Members
  • 5 messages
  if(bColorize)
    {
        // get the length of the string
        iStringLength = GetStringLength(sInput);
        // cut out the token before any processing
        sInput = GetStringRight(sInput, iStringLength-4);
        //colorize the string
        ColorText(sInput, i1, i2, i3);
        SetPCChatMessage(sInput);
    }
}

It didnt work, I fix this:

sInput = ColorText(sInput, i1, i2, i3);

Great, thank you very much! Greetings from Poland  :D


  • meaglyn aime ceci