Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Nickname System (https://forums.graalonline.com/forums/showthread.php?t=134270360)

ffcmike 08-21-2016 04:48 PM

Nickname System
 
Here is a nickname drawing system which draws nicknames in the same way that default systems do. This ofcourse offers no advantages in itself but can be used as a base for customisations.
  • Factors in Alignment Points
  • Draws (Paused) when a player is paused
  • Draws nicknames of NPCs, set by this.nick = "Nick";
  • Is optimised so that a text display is only rendered once, and then has its variables updated as an when needed instead of being re-rendered each frame

Necessary classes will be posted in the next post otherwise the post character limit is broken.

WEAPON

PHP Code:

/*
  Created by Thor/ffcmike (Graal the Adventure)
*/

this.join("utility_display");
this.join("data_alignment");

//#CLIENTSIDE
function onCreated() {
  
this.data = new TStaticVar();
  
this.onTimeout();
}

public function 
reset() {
  
this.storedaccounts = NULL;
  
this.storednpcs = NULL;
  
this.data.clearVars();
  
this.displayWipe();
}

function 
onTimeout() {
    
  
this.setTimer(0.05);
  
  
/*
    Re-Initialization of displays
  */

  
temp.zoom = $pref::graal::defaultfontsize/24;
  if (
this.fontzoom != temp.zoom) {
    
this.fontzoom = temp.zoom;
    
this.displayWipe();
  }
  
  
temp.limitnicks = $pref::graal::limitnicknames;
  if (
this.limitnicks != temp.limitnicks) {
    
this.limitnicks = temp.limitnicks;
    
this.displayWipe();
  }
  
  
temp.limit = this.limitnicks ? $pref::graal::nicknamelimit : 75;

  if (
this.limit != temp.limit) {
    
this.limit = temp.limit;
    
this.displayWipe();
  }
  
  
temp.hash = new TStaticVar();
 

  
/*
    Handle drawing of player nicknames
  */
  
  
for (temp.pl : players) {

    
temp.hash.(@ temp.pl.account) = true;
    
    
temp.paused = temp.pl.paused;
    
    
temp.d = this.data.(@ temp.pl.account);
    
//obtains stored data of the player, if NULL stores it and continues
    
if (temp.d == NULL) {
      
//nick, ap, paused, display
      
temp.d = {temp.pl.nick, temp.pl.ap, temp.paused, NULL};
      
this.storedaccounts.add(temp.pl.account);
      
temp.change = true;
    }
    else {
      
//if player is stored, checks to see if nick, ap or paused have changed
      
temp.change = temp.pl.ap != temp.d[1] || temp.paused != temp.d[2];
      if (
temp.change) {
        
//if change, store player data
        
temp.d[0] = temp.pl.nick;
        
temp.d[1] = temp.pl.ap;
        
temp.d[2] = temp.paused;
      }
    }
  
    
//check if display already exists
    
if (temp.d[3] != NULL) {
      
//if exists, updates display coordinates and text
      
temp.d[3].x = temp.pl.x + 1.625;
      
temp.d[3].y = temp.pl.y + 2.5;
      if (
temp.change)
        
this.updateText(temp.d[3], temp.pl, temp.paused);
    
    }
    else {
      
//if not exists, creates display
      
temp.d[3] = this.displayNick(temp.pl);
      
this.updateText(temp.d[3], temp.pl, temp.paused);
      
temp.change = true;
    }
    
    if (
temp.change)
      
this.data.(@ temp.pl.account) = temp.d;
  
  }
  
  
temp.s = this.storedaccounts.size();
  for (
temp.i = 0; temp.i < temp.s; temp.i ++) {
    
temp.a = this.storedaccounts[temp.i];
    if (!
temp.hash.(@ temp.a)) {
      
this.hideimg(this.data.(@ temp.a)[3].imageindex);
      
this.storedaccounts.delete(temp.i);
      
this.data.(@ temp.a) = NULL;
      
temp.i --;
      
temp.s --;
    }
  }
  
  
/*
    Handle drawing of level NPC nicknames
  */

  
for(temp.n : npcs) {
    if (
      
temp.n.nick == NULL ||
      
temp.n.visible
    
)
      continue;

    
temp.hash.("#" @ temp.n.id) = true;
    
temp.d = this.data.("#" @ temp.n.id);
    
    
//obtains stored data of the NPC, if NULL stores it and continues
    
if (temp.d == NULL){
      
//nick, ap, display
      
temp.d = {temp.n.nick, temp.n.ap, NULL};
      
temp.change = true;
      
this.storednpcs.add(temp.n.id);
    }
    else {
      
//if NPC is stored, checks to see if nick, ap or paused have changed
      
temp.change = temp.n.nick != temp.d[0] || temp.n.ap != temp.d[1];
      if (
temp.change){
        
//if change, store NPC data
        
temp.d[0] = temp.n.nick;
        
temp.d[1] = temp.n.ap;
      }
    }
  
    
//check if display already exists
    
if (temp.d[2] != NULL) {
      
//if exists, updates display coordinates and text
      
temp.d[2].x = temp.n.x + 1.625;
      
temp.d[2].y = temp.n.y + 2.5;
      if (
temp.change)
        
this.updateNPCText(temp.d[2], temp.n);
    
    }
    else {
      
//if not exists, creates display
      
temp.d[2] = this.displayNick(temp.n);
      
this.updateNPCText(temp.d[2], temp.n);
      
temp.change = true;
    }
    if (
temp.change)
      
this.data.("#" @ temp.n.id) = temp.d;
  
  }

  
temp.s = this.storednpcs.size();
  for (
temp.i = 0; temp.i < temp.s; temp.i ++){
    
temp.id = this.storednpcs[temp.i];
    if (!
temp.hash.("#" @ temp.id)) {
      
this.hideimg(this.data.("#" @ temp.id)[2].imageindex);
      
this.storednpcs.delete(temp.i);
      
this.data.("#" @ temp.id) = NULL;
      
temp.i --;
      
temp.s --;
    }
  }

} 

/*
  The part which does the display stuff.
*/

function displayNick(temp.obj) {

  
temp.t = this.displayText2(temp.obj.x+1.625, temp.obj.y+2.5, -0.5, "", "cb", "");
  
temp.t.textshadow = 1;
  
temp.t.layer = 0;
  
temp.t.zoom = this.fontzoom;
  
  return 
temp.t;
}

function 
updateText(temp.t, temp.pl, temp.paused) {

  
temp.text = temp.pl.nick;

  
temp.text @= temp.paused ? " (paused)" : "";

  
temp.t.text = temp.text.substring(0, this.limit);
  
  
temp.c = this.getNickColors(temp.pl);
  
temp.t.red = temp.c[0][0] / 255;
  
temp.t.green = temp.c[0][1] / 255;
  
temp.t.blue = temp.c[0][2] / 255;
  
temp.t.shadowcolor = temp.c[1];
}

function 
updateNPCText(temp.t, temp.n) {
  
temp.t.text = temp.n.nick.substring(0, this.limit);
  
temp.c = this.getNickColors(temp.n);
  
temp.t.red = temp.c[0][0] / 255;
  
temp.t.green = temp.c[0][1] / 255;
  
temp.t.blue = temp.c[0][2] / 255;
  
temp.t.shadowcolor = temp.c[1];
}


/*
  Get Colours
*/

public function getNickColors(temp.pl)
  return {
this.apv[temp.pl.ap], this.aps[temp.pl.ap]};

/*
  Other
*/

function onPlayerChanges(temp.pl) {
  if (
temp.pl.level == NULL)
    return;
  
  if (
this.displayCounter > 200) {
    
temp.d = this.data.(@ temp.pl.account);
    if (
temp.d[3] != NULL) {
      if (
temp.pl.nick != temp.d[0]) {
        
this.data.(@ temp.pl.account)[0] = temp.pl.nick;
        
this.updateText(temp.d[3], temp.pl, temp.d[2]);
      }
      return;
    }
  }
} 


ffcmike 08-21-2016 04:49 PM

CLASS data_alignment

PHP Code:


//#CLIENTSIDE
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}
  };
  
this.leave("data_alignment");
} 

CLASS utility_display

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.displayCounter = 200;
  
this.oldDisplayCounter = 200;
}

public function 
displayWipe() {
  
this.hideimgs(200, this.displayCounter);
  
this.oldDisplayCounter = 200;
  
this.displayCounter = 200;
}

public function 
displayRestart() {
  
// if there are any unused indexes, hide unused indexes
  
if (this.displayCounter < this.oldDisplayCounter)
    
this.hideimgs(this.displayCounter+1, this.oldDisplayCounter);

  
this.oldDisplayCounter = this.displayCounter;
  
this.displayCounter = 200;
}

function 
displayImage(temp.image, temp.x, temp.y) 
  return 
this.showimg(++this.displayCounter, temp.image, temp.x, temp.y);


function 
displayImage2(temp.image, temp.x, temp.y, temp.z) 
  return 
this.showimg2(++this.displayCounter, temp.image, temp.x, temp.y, temp.z);


function 
displayText(temp.x, temp.y, temp.font, temp.style, temp.text) 
  return 
this.showtext(++this.displayCounter, temp.x, temp.y, temp.font, temp.style, temp.text);


function 
displayText2(temp.x, temp.y, temp.z, temp.font, temp.style, temp.text) 
  return 
this.showtext2(++this.displayCounter, temp.x, temp.y, temp.z, temp.font, temp.style, temp.text);


function 
displayAnimation(temp.x, temp.y, temp.dir, temp.ani, temp.param1) 
  return 
this.showani(++this.displayCounter, temp.x, temp.y, temp.dir, temp.ani, temp.param1);


function 
displayAnimation2(temp.x, temp.y, temp.z, temp.dir, temp.ani, temp.param1) 
  return 
this.showani2(++this.displayCounter, temp.x, temp.y, temp.z, temp.dir, temp.ani, temp.param1);


function 
displayPolygon(temp.points) 
  return 
this.showpoly(++this.displayCounter, temp.points); 


PlanetOscar 08-22-2016 05:38 AM

Awesome :pluffy:

Crono 08-22-2016 08:17 AM

thx thor :pluffy:

LebJoe 01-17-2017 05:59 PM

I've uploaded it to my server in order to test it and found that it couldn't work for NPCs unless using the F9 (editing them). Can you please fix it? Thanks.

ffcmike 01-17-2017 06:06 PM

Quote:

Originally Posted by LebJoe (Post 1740824)
I've uploaded it to my server in order to test it and found that it couldn't work for NPCs unless using the F9 (editing them). Can you please fix it? Thanks.

This sounds like a problem which is specific to your server. Can you provide one of these NPC's scripts?

And while I'm posting I should also point out that default nicknames need to be disabled via enableFeatures().

Cubes 01-18-2017 03:12 AM

u really should have tried selling this on auto trader

LebJoe 02-18-2017 01:15 PM

Quote:

Originally Posted by ffcmike (Post 1740825)
This sounds like a problem which is specific to your server. Can you provide one of these NPC's scripts?

Sure:
NPC Code:
function onCreated() {
showcharacter();
this.head = "head0.png";
this.body = "body.png";
this.ap = 100;
this.nick = "NPC";
this.colors[0] = "orange";
this.colors[1] = "white";
this.colors[2] = "blue";
this.colors[3] = "red";
this.colors[4] = "black";
this.shield = "no-shield.png";
this.dir = 2;
setcharani("idle",NULL);
}



All times are GMT +2. The time now is 05:47 PM.

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