Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-19-2004, 08:59 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Gauge thingie

A nifty analogous display of percentages, pretty customisable I hope. Comments?

The functions:
NPC Code:
function show_scale() {
range = this.ANGLES[1] - this.ANGLES[0];
dist = this.POINTERLENGTH * 1.2;
for (i = this.MIN; i <= this.MAX; i += this.SCALE) {
angle = this.ANGLES[0] + i * range / (this.MAX - this.MIN);
showpoly index, {
sx + sin(angle) * dist * 1.4, sy + cos(angle) * dist * 1.4,
sx + sin(angle+pi*0.01) * dist * 1.3, sy + cos(angle+pi*0.01) * dist * 1.3,
sx + sin(angle) * dist * 1.1, sy + cos(angle) * dist * 1.1,
sx + sin(angle-pi*0.01) * dist * 1.3, sy + cos(angle-pi*0.01) * dist * 1.3
};
changeimgvis index, 4;

colouredness = 1 - abs(gauge - i) / (this.MAX - this.MIN) * this.SCALEFADE;
changeimgcolors index, this.SCALECOLOURS[0]*colouredness,
this.SCALECOLOURS[1]*colouredness,
this.SCALECOLOURS[2]*colouredness,
this.SCALECOLOURS[3];
index ++;
}
}
function show_gauge() {
range = this.ANGLES[1] - this.ANGLES[0];
angle = this.ANGLES[0] + gauge * range / (this.MAX - this.MIN);
showpoly index, {
sx, sy,
sx + sin(angle+pi*0.05) * dist * 0.2, sy + cos(angle+pi*0.05) * dist * 0.2,
sx + sin(angle) * dist * 1.0, sy + cos(angle) * dist * 1.0,
sx + sin(angle-pi*0.05) * dist * 0.2, sy + cos(angle-pi*0.05) * dist * 0.2
};
changeimgvis index, 4;
changeimgcolors index, this.POINTERCOLOURS[0],
this.POINTERCOLOURS[1],
this.POINTERCOLOURS[2],
this.POINTERCOLOURS[3];
index ++;
}



Example usage:
NPC Code:
if (created) {
this.MAX = 100;
this.MIN = 0;
this.SCALE = 10;
this.ANGLES = {pi * 0.5, pi * 1.5};
this.POINTERLENGTH = 32;
this.POINTERCOLOURS = {0.8, 1, 0.2, 1};
this.SCALECOLOURS = {0.8, 1, 0.5, 0.8};
this.SCALEFADE = 0.5;

timeout = 0.05;
}
if (created || timeout) {
index = 200;

sx = 140;
sy = 140;
gauge = abs(mousex - playerx-1.5) * 5;
if (gauge > this.MAX) gauge = this.MAX;
else if (gauge < this.MIN) gauge = this.MIN;

// Calling the magic functions
show_scale();
show_gauge();

hideimgs index, this.lastimgindex;
this.lastimgindex = index;

timeout = 0.05;
}



I figure the api sucks, and how I use gauge as variable name but this.OMGCAPITALS for most things, but dunno.
Reply With Quote
 


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 07:03 PM.


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