Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   shared.getAlignmentColor(player.ap) (https://forums.graalonline.com/forums/showthread.php?t=134266369)

Gunderak 05-04-2012 03:34 PM

shared.getAlignmentColor(player.ap)
 
Not sure if it will help anyone, but I confused myself for a little bit but eventually figured it out.
If you would like to use this for custom names, to get the actual colors instead of it returning 0-255 (which won't help) you need to divide it by 255.
eg:
PHP Code:

  temp.apcolors shared.getAlignmentColor(player.ap);
  
//Gets the color in an array {red, green, blue}
  
temp.apcolors = {apcolors[0]/255apcolors[1]/255apcolors[2]/255};
  
//Divides the value by 255 to get the actual
  //color needed and add it to an array. 


ffcmike 05-05-2012 12:32 AM

I think it's somewhat inefficient to be obtaining colour and shadow values via a public function for every time a nick is drawn, especially if they're being re-drawn every frame (in itself an avoidable bad practise).

I just have arrays set to read from directly:

PHP Code:

function onCreated(){
  
this.apv = {
    {
64,0,0},
    {
128,64,64},
    {
133,62,62},
    {
138,59,59},
    {
143,57,57},
    {
148,54,54},
    {
153,52,52},
    {
158,49,49},
    {
163,47,47},
    {
168,44,44},
    {
173,41,41},
    {
178,39,39},
    {
183,36,36},
    {
188,34,34},
    {
194,31,31},
    {
199,29,29},
    {
204,26,26},
    {
209,24,24},
    {
214,21,21},
    {
219,18,18},
    {
224,16,16},
    {
229,13,13},
    {
234,11,11},
    {
239,8,8},
    {
244,6,6},
    {
249,3,3},
    {
255,0,0},
    {
255,10,10},
    {
255,21,21},
    {
255,31,31},
    {
255,42,42},
    {
255,53,53},
    {
255,63,63},
    {
255,74,74},
    {
255,85,85},
    {
255,95,95},
    {
255,106,106},
    {
255,116,116},
    {
255,127,127},
    {
255,138,138},
    {
255,148,148},
    {
255,159,159},
    {
255,170,170},
    {
255,180,180},
    {
255,191,191},
    {
255,201,201},
    {
255,212,212},
    {
255,223,223},
    {
255,233,233},
    {
255,244,244},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
230,255,230},
    {
205,255,205},
    {
179,255,179},
    {
154,255,154},
    {
128,255,128},
    {
128,255,128},
    {
116,255,140},
    {
103,255,153},
    {
90,255,166},
    {
77,255,178},
    {
64,255,191},
    {
52,255,204},
    {
39,255,216},
    {
26,255,229},
    {
13,255,242},
    {
0,247,255},
    {
0,238,255},
    {
0,229,255},
    {
0,220,255},
    {
0,212,255},
    {
0,203,255},
    {
0,194,255},
    {
0,185,255},
    {
0,176,255},
    {
0,168,255},
    {
0,159,255},
    {
0,150,255},
    {
0,141,255},
    {
0,132,255},
    {
0,124,255},
    {
0,115,255},
    {
0,106,255},
    {
0,97,255},
    {
0,88,255},
    {
0,80,255},
    {
0,71,255},
    {
0,62,255},
    {
0,53,255},
    {
0,44,255},
    {
0,36,255},
    {
0,27,255},
    {
0,18,255},
    {
0,9,255},
    {
0,0,255},
    {
231,199,0}
  };
  
this.aps = {
    {
255,255,0},
    {
255,255,64},
    {
255,255,62},
    {
255,255,59},
    {
255,255,57},
    {
255,255,54},
    {
255,255,52},
    {
255,255,49},
    {
255,255,47},
    {
255,255,44},
    {
255,255,41},
    {
255,255,39},
    {
255,255,36},
    {
255,255,34},
    {
0,0,31},
    {
0,0,29},
    {
0,0,26},
    {
0,0,24},
    {
0,0,21},
    {
0,0,18},
    {
0,0,16},
    {
0,0,13},
    {
0,0,11},
    {
0,0,8},
    {
0,0,6},
    {
0,0,3},
    {
0,0,0},
    {
0,0,10},
    {
0,0,21},
    {
0,0,31},
    {
0,0,42},
    {
0,0,53},
    {
0,0,63},
    {
0,0,74},
    {
0,0,85},
    {
0,0,95},
    {
0,0,106},
    {
0,0,116},
    {
0,0,127},
    {
0,0,138},
    {
0,0,148},
    {
0,0,159},
    {
0,0,170},
    {
0,0,180},
    {
0,0,191},
    {
0,0,201},
    {
0,0,212},
    {
0,0,223},
    {
0,0,233},
    {
0,0,244},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,230},
    {
0,0,205},
    {
0,0,179},
    {
0,0,154},
    {
0,0,128},
    {
0,0,128},
    {
0,0,140},
    {
0,0,153},
    {
0,0,166},
    {
0,0,178},
    {
0,0,191},
    {
0,0,204},
    {
0,0,216},
    {
0,0,229},
    {
0,0,242},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
0,0,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,255},
    {
255,255,0}
  };


On pre-wipe Classic it was being calculated by:

PHP Code:

function getAlignmentColor(value) {
  if (
value<=0) return {64,0,0};
  if (
value<=26) return {128+int(127*(value-1)/25),64-int(64*(value-1)/25),64-int(64*(value-1)/25)};
  if (
value<=49) return {255,int(255*(value-26)/24),int(255*(value-26)/24)};
  if (
value<=55) return {255,255,255};
  if (
value<=60) return {255-int(127*(value-55)/5),255,255-int(127*(value-55)/5)};
  if (
value<=70) return {128-int(128*(value-61)/10),255,128+int(127*(value-61)/10)};
  if (
value<=99) return {0,255-int(255*(value-70)/29),255};
  return {
231,199,0};

function 
getAlignmentShadow(value) {
  
temp.getAlignmentColor(value);
  if (
value == 100)
    
temp.= {255,255,0};
  else
    
temp.c[0] = temp.c[1] = 255 * !(temp.c[0]>191.25 || temp.c[1]>191.25);
  return 
temp.c;



fowlplay4 05-05-2012 01:44 AM

This doesn't just apply to that particular function:

PHP Code:

with (findimg(200)) {
  
red 1// Wants a value between 0 and 1
  
green 1;
  
blue 1;


Therefore in order to convert a color specified by using the 0-255 range into 0-1 range color, you must divide by 255.

Gunderak 05-05-2012 07:40 AM

@ffcmike
Your method seems a tad better, but I really don't know how you drew yourself to make the arrays. Wouldn't that of taken a very long time?

fowlplay4 05-05-2012 07:47 AM

Quote:

Originally Posted by Gunderak (Post 1693720)
@ffcmike
Your method seems a tad better, but I really don't know how you drew yourself to make the arrays. Wouldn't that of taken a very long time?

not if you have a script generate it for you..

ffcmike 05-05-2012 08:36 AM

Quote:

Originally Posted by Gunderak (Post 1693720)
@ffcmike
Your method seems a tad better, but I really don't know how you drew yourself to make the arrays. Wouldn't that of taken a very long time?

PHP Code:

//#CLIENTSIDE
function onCreated(){
  for(
temp.0temp.101temp.++){
    
temp.this.getAlignmentColor(temp.i);
    
temp.a.add("{" temp."},");
    
temp.s.add("{" this.getAlignmentShadow(temp.itemp.c) @ "},");
  }
  
temp.a.savelines("apvalues.txt"0);
  
temp.s.savelines("shadowvalues.txt"0);

function 
getAlignmentColor(value) { 
  if (
value<=0) return {64,0,0}; 
  if (
value<=26) return {128+int(127*(value-1)/25),64-int(64*(value-1)/25),64-int(64*(value-1)/25)}; 
  if (
value<=49) return {255,int(255*(value-26)/24),int(255*(value-26)/24)}; 
  if (
value<=55) return {255,255,255}; 
  if (
value<=60) return {255-int(127*(value-55)/5),255,255-int(127*(value-55)/5)}; 
  if (
value<=70) return {128-int(128*(value-61)/10),255,128+int(127*(value-61)/10)}; 
  if (
value<=99) return {0,255-int(255*(value-70)/29),255}; 
  return {
231,199,0}; 
}  

function 
getAlignmentShadow(temp.aptemp.c) { 
  if (
temp.ap == 100
    
temp.= {255,255,0}; 
  else 
    
temp.c[0] = temp.c[1] = 255 * !(temp.c[0]>191.25 || temp.c[1]>191.25); 
  return 
temp.c



Gunderak 05-05-2012 09:56 AM

Ah.. That would help speed the process.
Also a bit off topic but is there any way to get all GUI's on the screen and remove them?
GUI's as in windows, showing's and stuff.

cbk1994 05-05-2012 05:20 PM

Quote:

Originally Posted by Gunderak (Post 1693724)
Ah.. That would help speed the process.
Also a bit off topic but is there any way to get all GUI's on the screen and remove them?
GUI's as in windows, showing's and stuff.

showimg's are not GUIs.

You can get a list of all GUIs in GUIContainer.controls or GraalControl.controls (probably the latter is better for your case; GUIContainer contains GraalControl, the taskbar, etc). Recurse through the array and hide everything.

Gunderak 05-06-2012 04:05 AM

Oh so it's all in the array of GuiContainer?

cbk1994 05-06-2012 04:57 AM

Quote:

Originally Posted by Gunderak (Post 1693770)
Oh so it's all in the array of GuiContainer?

It's an array of only that control's child controls.

Add Jer's GUI Explorer to your server for a visual representation.


All times are GMT +2. The time now is 07:03 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.