Thread: Nickname System
View Single Post
  #1  
Old 08-21-2016, 04:48 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.this.data.(@ temp.pl.account);
    
//obtains stored data of the player, if NULL stores it and continues
    
if (temp.== NULL) {
      
//nick, ap, paused, display
      
temp.= {temp.pl.nicktemp.pl.aptemp.pausedNULL};
      
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].temp.pl.1.625;
      
temp.d[3].temp.pl.2.5;
      if (
temp.change)
        
this.updateText(temp.d[3], temp.pltemp.paused);
    
    }
    else {
      
//if not exists, creates display
      
temp.d[3] = this.displayNick(temp.pl);
      
this.updateText(temp.d[3], temp.pltemp.paused);
      
temp.change true;
    }
    
    if (
temp.change)
      
this.data.(@ temp.pl.account) = temp.d;
  
  }
  
  
temp.this.storedaccounts.size();
  for (
temp.0temp.temp.stemp.++) {
    
temp.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.--;
      
temp.--;
    }
  }
  
  
/*
    Handle drawing of level NPC nicknames
  */

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

    
temp.hash.("#" temp.n.id) = true;
    
temp.this.data.("#" temp.n.id);
    
    
//obtains stored data of the NPC, if NULL stores it and continues
    
if (temp.== NULL){
      
//nick, ap, display
      
temp.= {temp.n.nicktemp.n.apNULL};
      
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].temp.n.1.625;
      
temp.d[2].temp.n.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.this.storednpcs.size();
  for (
temp.0temp.temp.stemp.++){
    
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.--;
      
temp.--;
    }
  }



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

function displayNick(temp.obj) {

  
temp.this.displayText2(temp.obj.x+1.625temp.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.ttemp.pltemp.paused) {

  
temp.text temp.pl.nick;

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

  
temp.t.text temp.text.substring(0this.limit);
  
  
temp.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.ttemp.n) {
  
temp.t.text temp.n.nick.substring(0this.limit);
  
temp.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.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.pltemp.d[2]);
      }
      return;
    }
  }

Reply With Quote