View Single Post
  #1  
Old 07-22-2010, 06:12 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
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(scopexylabeldrawivarScope, 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.xbar.y;
  
bar.width 140bar.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 (xy) { this.xthis.yontick(this.drawitrue);};
  
bar.onResize = function (widthheight) { this.width = (width >= 25) ? width:25this.height = (height >= 25) ? height:25; } ;
  
  
bar.setMaxValue = function (valuesetcurrent) {
    
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, maxvaluelabel) {
    
this.label = (label == "") ? var:label;
    
setMaxValue(maxvalue);
    
this.varScope scope;
    
this.varVar = var;
    
temp.= -1;
    
with (this.varScopetemp.makevar(this.varVar);
    
onUpdate();
  };
  
  
bar.onUpdate = function () {
    
temp.= -1;
    
with (this.varScope)temp.makevar(this.varVar);
    if (
temp.!= 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 == && 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.this.width this.paddingthis.this.padding,this.this.width this.paddingthis.this.height this.paddingthis.this.paddingthis.this.height this.padding,this.this.paddingthis.this.padding};
    
temp.x1 = { this.this.width this.this.widththis.this.widththis.this.width this.percent};
    
temp.y1 = { this.this.height - ( this.height this.percent) , this.ythis.ythis.};
    
temp.x2 = { this.this.widththis.this.widththis.this.widththis.this.width this.percent};
    
temp.y2 = { this.this.heightthis.this.heightthis.this.height this.percentthis.this.height };
    
temp.x3 = { this.xthis.this.width - ( this.width this.percent), this.xthis.};
    
temp.y3 = { this.this.heightthis.this.heightthis.this.height this.percentthis.this.height };
    
temp.x4 = { this.xthis.this.width - ( this.width this.percent), this.xthis.};
    
temp.y4 = { this.this.height - ( this.height this.percent), this.ythis.ythis.};
    
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.this.widththis.this.width - (this.width this.percent), this.this.widththis.this.width this.percent2};
    
temp.y1 = { this.this.height - ( this.height this.percent2) , this.ythis.this.height this.percentthis.};
    
temp.x2 = { this.this.widththis.this.width - (this.width this.percent), this.this.widththis.this.width this.percent2};
    
temp.y2 = { this.this.height - (this.height this.percent), this.this.height this.this.height this.percent2this.this.height };
    
temp.x3 = { this.x,this.this.width - (this.width this.percent2), this.xthis.this.width this.percent };
    
temp.y3 = { this.this.height - (this.height this.percent), this.this.heightthis.this.height this.percent2this.this.height };
    
temp.x4 = { this.xthis.this.width - (this.width this.percent2), this.xthis.this.width this.percent };
    
temp.y4 = { this.this.height - ( this.height this.percent2), this.ythis.this.height this.percentthis.};
    
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 0green 0blue 0;
      
layer 4;
    }
    
index ++;
    
with (this.global.findimg(index)){
      
polygon temp.poly2;
      
green .3red 1blue .2;
      
layer 5;
    }
    
index ++;
    
with (this.global.findimg(index)) {
      
polygon temp.poly3;
      
green 1red .3blue .3;
      
layer 6;
    }
    
index ++;
    
with (this.global.findimg(index)) {
      
thiso.thiso.padding thiso.width 4;
      
thiso.;
      
text thiso.label;
      
zoom 0.7;
      
layer 7;
    }
    
index ++;
    
with (this.global.findimg(index)) {
      
thiso.thiso.padding thiso.width 4;
      
thiso.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.addnewBarthis10200"Mouse X"200 this"mousex"64 ));
  
this.bars.addnewBarthis10240"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
Reply With Quote