Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 07-22-2010, 07:57 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
haha cool
__________________
Reply With Quote
  #3  
Old 07-23-2010, 04:17 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
hehe, I made it make hundreds of bars, made them spiral around the screen, while all animating smoothly. Fun to watch.
__________________
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
  #4  
Old 07-23-2010, 01:07 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
__________________
Reply With Quote
  #5  
Old 08-18-2010, 10:04 PM
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

Never did post the video did I.
The bars track mousex and mousey for demo purposes.
__________________
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
  #6  
Old 08-18-2010, 10:08 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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 
__________________
Reply With Quote
  #7  
Old 08-18-2010, 10:18 PM
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
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.
__________________
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
  #8  
Old 08-18-2010, 10:25 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by adam View Post
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 .
__________________
Reply With Quote
  #9  
Old 08-18-2010, 10:33 PM
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
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.
__________________
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
Reply


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 08:16 AM.


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