Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #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 Send a message via Skype™ 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

Graal Script 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
  #2  
Old 08-21-2016, 04:49 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 Send a message via Skype™ to ffcmike
CLASS data_alignment

Graal Script 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

Graal Script Code:
//#CLIENTSIDE
function onCreated() {
  
this.displayCounter 200;
  
this.oldDisplayCounter 200;
}

public function 
displayWipe() {
  
this.hideimgs(200this.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+1this.oldDisplayCounter);

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

function 
displayImage(temp.imagetemp.xtemp.y
  return 
this.showimg(++this.displayCountertemp.imagetemp.xtemp.y);


function 
displayImage2(temp.imagetemp.xtemp.ytemp.z
  return 
this.showimg2(++this.displayCountertemp.imagetemp.xtemp.ytemp.z);


function 
displayText(temp.xtemp.ytemp.fonttemp.styletemp.text
  return 
this.showtext(++this.displayCountertemp.xtemp.ytemp.fonttemp.styletemp.text);


function 
displayText2(temp.xtemp.ytemp.ztemp.fonttemp.styletemp.text
  return 
this.showtext2(++this.displayCountertemp.xtemp.ytemp.ztemp.fonttemp.styletemp.text);


function 
displayAnimation(temp.xtemp.ytemp.dirtemp.anitemp.param1
  return 
this.showani(++this.displayCountertemp.xtemp.ytemp.dirtemp.anitemp.param1);


function 
displayAnimation2(temp.xtemp.ytemp.ztemp.dirtemp.anitemp.param1
  return 
this.showani2(++this.displayCountertemp.xtemp.ytemp.ztemp.dirtemp.anitemp.param1);


function 
displayPolygon(temp.points
  return 
this.showpoly(++this.displayCountertemp.points); 
Reply With Quote
  #3  
Old 08-22-2016, 05:38 AM
PlanetOscar PlanetOscar is offline
Registered User
Join Date: Aug 2015
Location: Sweden
Posts: 177
PlanetOscar is just really nicePlanetOscar is just really nice
Awesome
Reply With Quote
  #4  
Old 08-22-2016, 08:17 AM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 19,993
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
Send a message via AIM to Crono
thx thor
__________________
Reply With Quote
  #5  
Old 01-17-2017, 04:59 PM
LebJoe LebJoe is offline
Dragon
Join Date: Aug 2016
Location: Lebanon
Posts: 16
LebJoe is on a distinguished road
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.
Reply With Quote
  #6  
Old 01-17-2017, 05:06 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 Send a message via Skype™ to ffcmike
Quote:
Originally Posted by LebJoe View Post
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().
Reply With Quote
  #7  
Old 01-18-2017, 02:12 AM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
u really should have tried selling this on auto trader
Reply With Quote
  #8  
Old 02-18-2017, 12:15 PM
LebJoe LebJoe is offline
Dragon
Join Date: Aug 2016
Location: Lebanon
Posts: 16
LebJoe is on a distinguished road
Quote:
Originally Posted by ffcmike View Post
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);
}

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:09 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.