Author Topic: Chat Color  (Read 535 times)

Legacy_YeezY

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Chat Color
« on: April 05, 2016, 06:29:08 pm »


               

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?



               
               

               
            

Legacy_CaveGnome

  • Sr. Member
  • ****
  • Posts: 432
  • Karma: +0/-0
Chat Color
« Reply #1 on: April 05, 2016, 08:52:56 pm »


               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.
               
               

               
            

Legacy_YeezY

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Chat Color
« Reply #2 on: April 05, 2016, 09:01:54 pm »


               

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



               
               

               
            

Legacy_CaveGnome

  • Sr. Member
  • ****
  • Posts: 432
  • Karma: +0/-0
Chat Color
« Reply #3 on: April 05, 2016, 10:34:25 pm »


               

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.



               
               

               
            

Legacy_Kerick Ulthrall

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Chat Color
« Reply #4 on: April 05, 2016, 10:42:20 pm »


               

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


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Chat Color
« Reply #5 on: April 05, 2016, 11:02:41 pm »


               That's correct, except it's -4 because you want to remove the blank, too.
               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Chat Color
« Reply #6 on: April 05, 2016, 11:53:53 pm »


               

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);
    }
}


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Chat Color
« Reply #7 on: April 06, 2016, 01:45:31 am »


               

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.



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Chat Color
« Reply #8 on: April 06, 2016, 05:07:42 am »


               

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.



               
               

               
            

Legacy_YeezY

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Chat Color
« Reply #9 on: April 06, 2016, 03:40:57 pm »


               

  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  '<img'>