Aller au contenu

Photo

Custom Tokens


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

#1
Xardex

Xardex
  • Members
  • 217 messages
Does it hurt to have loads of custom tokens? (1000+)

#2
Xardex

Xardex
  • Members
  • 217 messages
Well, I might just as well ask here... Any idea why this script doesn't even seem to launch?

OnModuleLoad
#include "mod_color"
void main()
{
    string sDesc = "";                 //
    GiveGoldToCreature(GetFirstPC(), 1); // //
    int r=0,g=0,b=0;
    while (r+g+b != 27)
    {
        sDesc += ColorString("XXXXXX\\n", r*25+30, g*25+30, b*25+30, 1);  //
        SetCustomToken(6000 + r*100 + g*10 + b*1, ColorString("", r*25+30, g*25+30, b*25+30));
             if ((g == 9) && (b == 9)) {r++; g=0; b=0;}
        else if             ((b == 9)) {     g++; b=0;}
        else                           {          b++;}
    }
    GiveGoldToCreature(GetFirstPC(), 2); // //
    SetCustomToken(7000, "</c>");
    SetDescription(GetObjectByTag("thechest"), sDesc);    //
}

mod_color
const string COLORTOKEN = "                  ##################$%&'()*+,-./0123456789:;;==?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[[]^_`abcdefghijklmnopqrstuvwxyz{|}~~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¡¢£¤¥¦§¨©ª«¬¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþþ";

// returns a properly color-coded sText string based on specified RGB values
// ends color mode after sText if iEnd = 1
string ColorString(string sText, int nRed=255, int nGreen=255, int nBlue=255, int iEnd = 0);
string ColorString(string sText, int nRed=255, int nGreen=255, int nBlue=255, int iEnd = 0)
{
    string sEnd = "";
    if (iEnd = 1) {sEnd = "</c>";}
    return "<c" + GetSubString(COLORTOKEN, nRed, 1) + GetSubString(COLORTOKEN, nGreen, 1) + GetSubString(COLORTOKEN, nBlue, 1) + ">" + sText + sEnd;
}

Im not getting the 1 or 2 gold I put in the script for testing.

Modifié par Xardex, 03 juin 2011 - 06:59 .


#3
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
GetFirstPC won't return valid on modload - there are no pcs.

Funky

#4
_Guile

_Guile
  • Members
  • 685 messages

FunkySwerve wrote...

GetFirstPC won't return OBJECT_INVALID on modload - there are no pcs.

Funky


fixed..   =D

#5
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

FunkySwerve wrote...

GetFirstPC won't return valid on modload - there are no pcs.

Funky



_Guile wrote...

FunkySwerve wrote...

GetFirstPC won't return OBJECT_INVALID on modload - there are no pcs.

Funky


fixed..   =D



I do not know what you think you fixed _Guile.  Funky's ststment is correct.  GetFirstPC will not  return valid object on mod load.  

Your fix of his statment is 100% incorrect.  Since it will return OBJECT_INVALID every time in the on mod load event.     

#6
Xardex

Xardex
  • Members
  • 217 messages
Okay, that explains that.... But after meddling with the script some more, this breaks due to too many instructions.

To make it easier to grasp ill explain what it is supposed to do...
Basically go through 1000 colors, set tokens 6000-6999, so custom token 6900 would be brightred, 6040 dark green... (6RGB)

void SetColors()
{
    string sDesc = "";                 //
    int r=0,g=0,b=0,n=0;
    while (n != 1000)
    {
        sDesc += ColorString("XXXXXX\\n", r*25+30, g*25+30, b*25+30, 1);  //
        SetCustomToken(6000 + r*100 + g*10 + b*1, ColorString("", r*25+30, g*25+30, b*25+30));
             if ((g == 9) && (b == 9)) {r++; g=0; b=0;}
        else if             ((b == 9)) {     g++; b=0;}
        else                           {          b++;}
        n++;
    }
    SetCustomToken(7000, "</c>");
    SetDescription(GetObjectByTag("thechest"), sDesc);    //
}

Color string is the same as above... Cant figure it out.
Also about the performance of having lots of custom tokens..?

Modifié par Xardex, 04 juin 2011 - 08:14 .


#7
Xardex

Xardex
  • Members
  • 217 messages
.... 1000 loops through that script causes "too many instructions"??
n++ -> n+=10
and it works. Too bad its not enough...

1000 loops? seriously?

#8
Xardex

Xardex
  • Members
  • 217 messages
Well, I got it to work and it seems it does lag. Alot.

So I reduced the amount of color intensities to 3 per color, which makes a total of 27 colors. And what is this? Exactly same amount of lag.

Switched back to 1000 varieties AND NO LAG?

What the hell?
but this is just ... IMPOSSIBLE!

It seems that it randomly lags like there is no tomorrow, or not at all.

#9
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Why not just use.

// FILE: x3_inc_string      FUNCTION: StringToRGBString()
//
// This function will make sString be the specified color
// as specified in sRGB.  RGB is the Red, Green, and Blue
// components of the color.  Each color can have a value from
// 0 to 7.
// Ex: red   == "700"
//     green == "070"
//     blue  == "007"
//     white == "777"
//     black == "000"
// The STRING_COLOR_* constants may be used for sRGB.
string StringToRGBString(string sString, string sRGB);
 


Or is there a perpose here that I am missing. 

As far as setting the tokens I do not see a performance problem with setting them one time on ModLoad. 

The To Many Instructions error does not really care about how many loops there are in the script.  It is how many instructions are executed.  The limit is around 16000 if what I havew heard is right.  But then again I do not know if that is machine instructions or number of  instructions being fed to the script interperter.  Or where the blocking for the count is.   

I just do not know what you need to set all the tokens for that the above function will not handle.  

#10
Xardex

Xardex
  • Members
  • 217 messages
Alrighty, after lots of script honing and chilling off (sorry for my earlier almost-rage)...

The script works now, and it does actually lag if I set 1000 tokens. (Not just momentarily, it persists)
Im going with the 27 colors, it doesn't lag at all and the reason it lagged earlier was propably because I forgot to compile my stuff.

I might have used that nwn's own thingy but I didn't even know it existed. Anyhow, im good with the one I got from... somewhere... + It offers a wider spectrum of colors.

Thanks though, you are most helpful as usual. B)

Modifié par Xardex, 04 juin 2011 - 09:19 .