Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Something interesting (https://forums.graalonline.com/forums/showthread.php?t=134259917)

adam 07-22-2010 06:12 AM

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 ));



xAndrewx 07-22-2010 07:57 AM

haha cool

adam 07-23-2010 04:17 AM

hehe, I made it make hundreds of bars, made them spiral around the screen, while all animating smoothly. Fun to watch.

Crow 07-23-2010 01:07 PM

I don't think it's a very uncommon thing to do. I've also made and released dynamic (to some point at least) status bar code. Been a while though, and it's not exactly what I wanted it to be initially, but I suppose it works a bit like yours, at least to some degree.

adam 08-18-2010 10:04 PM


Never did post the video did I.
The bars track mousex and mousey for demo purposes.

cbk1994 08-18-2010 10:08 PM

FYI you can probably do this a lot easier with...

PHP Code:

temp.bar = new TStaticVar();

bar.whatever "yea";
bar.join("statusbar"); 

then in class 'statusbar':

PHP Code:

function onCreated() {
  
// whatever
}

public function 
setDrawi(i) {
  
this.drawi i;
}
// etc 


adam 08-18-2010 10:18 PM

Yeah, I was just thinking about that actually. It's mostly that I never realized I could do it the way I did until recently. Ya know, it's 'new to me' syndrome, I just wanna do it that way. And it's also just a one line declaration this way.

cbk1994 08-18-2010 10:25 PM

Quote:

Originally Posted by adam (Post 1595139)
Yeah, I was just thinking about that actually. It's mostly that I never realized I could do it the way I did until recently. Ya know, it's 'new to me' syndrome, I just wanna do it that way. And it's also just a one line declaration this way.

Generally I do something like this (using custom projectiles as an example of something I used it for)

PHP Code:

CustomProjectile = new TStaticVar();
CustomProjectile.join("projectile"); 

then in other scripts I can just do

PHP Code:

temp.proj = new CustomProjectile();

proj.10;
proj.12;
proj.angle pi 2;
proj.speed 5;

proj.fire(); 

I guess you could also make a function for them but I prefer variables to long arrays of parameters.

Also sorry if I come off as condescending, I like the way you did it, just wanted to point this out as well in case anyone doesn't know about it :).

adam 08-18-2010 10:33 PM

Indeed, I appreciate your input. :) I was considering the variables, or even setter functions for altering variables, as long arrays of arguments do get annoying. Using 'new' at all is kinda new to me. But inevitable on my road to understanding things others do not.

I'm also working on something new with similar idea's in implementation.


All times are GMT +2. The time now is 08:21 PM.

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