http://wiki.graal.us/
|
|
Join Date: Nov 2001
Posts: 2,247
|
|
Something interesting
I can only imagine that few people have made, or understand scripts like this one. So I'm posting it as an object of curiosity for people to play with, and wonder why the heck it works.
It's a script for a status bar, could be any variable with a maximum value, like HP, MP, AP, X, Y, Mousex, Speed(fun one).
PHP Code:
//NPC Created by Rogue Shadow (TCN)
//#CLIENTSIDE
function newBar(scope, x, y, label, drawi, varScope, var, maxValue){
temp.bar = new TStaticVar();
bar.global = scope;// save scope, so I can do things like global.findimg() later, in the functions
bar.label = (label == "") ? "HP":label; // using the () ? : syntax to default to the label "HP" if none is given
bar.x = x; bar.y = y;
bar.width = 140; bar.height = 10;
bar.padding = 2;
bar.currentValue = 0;
bar.targetValue = 0;
bar.maxValue = 0;
bar.real_speed = 1;
bar.dir = 3;
bar.drawi = (drawi == "") ? 200:drawi;
bar.varScope = (varScope == "") ? player:varScope;
bar.varVar = (var == "") ? "hp":var;
bar.maxValue = (maxValue == "") ? player.maxhp:maxValue;
bar.speed = (bar.maxValue/100)*bar.real_speed;
bar.setDrawi = function (i) { this.drawi = i; };
bar.setDir = function (dir) { this.dir = dir; };
bar.setSpeed = function (speed) { this.real_speed = speed; };
bar.onMove = function (x, y) { this.x = x; this.y = y; ontick(this.drawi, true);};
bar.onResize = function (width, height) { this.width = (width >= 25) ? width:25; this.height = (height >= 25) ? height:25; } ;
bar.setMaxValue = function (value, setcurrent) {
this.maxValue = value;
this.speed = (value/100)*this.real_speed;
};
bar.setValue = function (value){
this.targetValue = (value < 0) ? 0:value;
if (this.targetValue > this.maxValue)this.targetValue = this.maxValue;
};
bar.setVar = function (scope, var, maxvalue, label) {
this.label = (label == "") ? var:label;
setMaxValue(maxvalue);
this.varScope = scope;
this.varVar = var;
temp.v = -1;
with (this.varScope) temp.v = makevar(this.varVar);
onUpdate();
};
bar.onUpdate = function () {
temp.v = -1;
with (this.varScope)temp.v = makevar(this.varVar);
if (temp.v != this.lastvalue){
this.lastvalue = temp.v;
setValue(temp.v);
}
ontick(this.drawi);
this.scheduleevent(0.05, "Update", null);// useing scheduleevent to create a loop internal to the tstaticvar, kinda neat
};
bar.ontick = function (index , forceupdate) {
this.lasti = index;
temp.dist = this.currentValue - this.targetValue;
if (temp.dist == 0 && forceupdate == "")return;
if (abs(temp.dist) <= this.speed){
this.currentValue = this.targetValue;
}else{
this.currentValue -= (temp.dist > 0) ? this.speed:-this.speed;
}
if (this.maxValue != 0){
this.percent = this.currentValue/this.maxValue;
this.percent2 = this.targetValue/this.maxValue;
}elseif(forceupdate == "") return;
temp.poly = {this.x + this.width + this.padding, this.y - this.padding,this.x + this.width + this.padding, this.y + this.height + this.padding, this.x - this.padding, this.y + this.height + this.padding,this.x - this.padding, this.y - this.padding};
temp.x1 = { this.x + this.width , this.x + this.width, this.x + this.width, this.x + this.width * this.percent};
temp.y1 = { this.y + this.height - ( this.height * this.percent) , this.y, this.y, this.y };
temp.x2 = { this.x + this.width, this.x + this.width, this.x + this.width, this.x + this.width * this.percent};
temp.y2 = { this.y + this.height, this.y + this.height, this.y + this.height * this.percent, this.y + this.height };
temp.x3 = { this.x, this.x + this.width - ( this.width * this.percent), this.x, this.x };
temp.y3 = { this.y + this.height, this.y + this.height, this.y + this.height * this.percent, this.y + this.height };
temp.x4 = { this.x, this.x + this.width - ( this.width * this.percent), this.x, this.x };
temp.y4 = { this.y + this.height - ( this.height * this.percent), this.y, this.y, this.y };
temp.poly2 = {temp.x1[this.dir], temp.y1[this.dir], temp.x2[this.dir], temp.y2[this.dir], temp.x3[this.dir], temp.y3[this.dir], temp.x4[this.dir], temp.y4[this.dir]};
temp.x1 = { this.x + this.width, this.x + this.width - (this.width * this.percent), this.x + this.width, this.x + this.width * this.percent2};
temp.y1 = { this.y + this.height - ( this.height * this.percent2) , this.y, this.y + this.height * this.percent, this.y };
temp.x2 = { this.x + this.width, this.x + this.width - (this.width * this.percent), this.x + this.width, this.x + this.width * this.percent2};
temp.y2 = { this.y + this.height - (this.height * this.percent), this.y + this.height , this.y + this.height * this.percent2, this.y + this.height };
temp.x3 = { this.x,this.x + this.width - (this.width * this.percent2), this.x, this.x + this.width * this.percent };
temp.y3 = { this.y + this.height - (this.height * this.percent), this.y + this.height, this.y + this.height * this.percent2, this.y + this.height };
temp.x4 = { this.x, this.x + this.width - (this.width * this.percent2), this.x, this.x + this.width * this.percent };
temp.y4 = { this.y + this.height - ( this.height * this.percent2), this.y, this.y + this.height * this.percent, this.y };
temp.poly3 = {temp.x1[this.dir], temp.y1[this.dir], temp.x2[this.dir], temp.y2[this.dir], temp.x3[this.dir], temp.y3[this.dir], temp.x4[this.dir], temp.y4[this.dir]};
with (this.global.findimg(index)){
polygon = temp.poly;
red = 0; green = 0; blue = 0;
layer = 4;
}
index ++;
with (this.global.findimg(index)){
polygon = temp.poly2;
green = .3; red = 1; blue = .2;
layer = 5;
}
index ++;
with (this.global.findimg(index)) {
polygon = temp.poly3;
green = 1; red = .3; blue = .3;
layer = 6;
}
index ++;
with (this.global.findimg(index)) {
x = thiso.x + thiso.padding + thiso.width + 4;
y = thiso.y - 4 ;
text = thiso.label;
zoom = 0.7;
layer = 7;
}
index ++;
with (this.global.findimg(index)) {
x = thiso.x + thiso.padding + thiso.width + 4;
y = thiso.y - 29;
text = thiso.currentValue @ "/" @ thiso.maxValue;
zoom = 0.7;
layer = 7;
}
index ++;
return index;
};
bar.onUpdate();// starts the update loop =D
return temp.bar;
}
function onCreated(){
// all you need to do, is to store the newbar somewhere on creation, and your done, no need to mess with loops or anything
// now you have a fully animated self-updating status bar thing!
// Scope, x, y, label, draw index start, var scope, var name, max value
this.bars.add( newBar( this, 10, 200, "Mouse X", 200 , this, "mousex", 64 ));
this.bars.add( newBar( this, 10, 240, "Mouse Y", 205 , this, "mousey", 64 ));
}
|
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)
For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
|
|
|