Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Very awesome staff "panel" (https://forums.graalonline.com/forums/showthread.php?t=134262776)

Crow 04-11-2011 04:56 PM

Very awesome staff "panel"
 
1 Attachment(s)
So, Emera's thread reminded me I wanted to release my little staff tool to you guys. Here you go!


The idea and design is a blatant rip off of the tool Era (used to?) use, sorry guys :p It looks a little cooler, though, and is full of awesome. You can add new items to the tool easily without even really touching the main portion of the code. First off, here's the code:

PHP Code:

//#CLIENTSIDE
function onCreated() {  
  
// staff tool stuff
  
this.toolOn false;
  
this.toolIdx 0;
  
  
// add new items here
  
this.toolEntries = {
    { 
"Exit""block.png" },
    { 
"Update Level""block.png" }
  };
}

// draw the staff tool
function DrawTool(create) {
  
// create image objects
  
if (create) {
    
// background
    
temp.GraalControl.width this.toolEntries.size() * 20;
    
temp.GetPolyRect(temp.xGraalControl.height 104this.toolEntries.size() * 4064);
    
with (findImg(200)) {
      
polygon temp.p;
      
red green blue 0;
      
alpha 0.75mode 1;
      
layer 5;
    }
    
    
// text
    
with (findImg(201)) {
      
temp.8;
      
GraalControl.height 58;
      
text thiso.toolEntries[thiso.toolIdx][0];
      
font "Arial"zoom 0.5;
      
red green blue 1;
      
layer 6;
    }
    
    
// icons
    
for (temp.0this.toolEntries.size(); i++) {
      
with (findImg(202 i)) {
        
temp.40;
        
GraalControl.height 96;
        
image thiso.toolEntries[i][1];
        
partx party 0;
        
partw parth 32;
        
alpha 0.5mode 1;
        
layer 6;
      }
    }
  }
  
  
// update text & alpha
  
findImg(201).text this.toolEntries[this.toolIdx][0];
  
  
temp.ci this.toolIdx// current tool
  
temp.li = (ci ci this.toolEntries.size() - 1); // last tool
  
findImg(202 ci).alpha 1;
  
findImg(202 li).alpha 0.5;
}

// reposition the staff tool when resizing Graal
function GraalControl.onResize(nwnh) {
  if (!
this.toolOn)
    return;
  
  
DrawTool(true);
}

// keyboard stuff
function GraalControl.onKeyDown(code) {
  if (
code == 69) { // E
    
if (!this.toolOn) {
      
this.toolOn  true;
      
this.toolIdx 0;
      
      
DrawTool(true);
    } else {
      
this.toolIdx++;
      
this.toolIdx %= this.toolEntries.size() - 1;

      
DrawTool(false);
    }
  } elseif (
code == 87) { // W
    
if (!this.toolOn)
      return;
    
    
temp.ReplaceText(this.toolEntries[this.toolIdx][0].upper(), " ""_");
    (
"StaffTool" temp.f)();
  }
}


// close staff tool
function StaffToolEXIT() {
  
this.toolOn false;
  
hideImgs(200201 this.toolEntries.size());
}

// update level
function StaffToolUPDATE_LEVEL() {
  
shared.chat("");
  
sleep(0.05);
  
shared.chat("update level");
}


// Dusty's, restyled
function ReplaceText(txtab) {
  if (
txt.pos(a) < 0)
    return 
txt;
  
  
temp.len a.length();
  
temp.txtpos txt.positions(a);
  
temp.newtxt txt.substring(0txtpos[0]);
  
  for (
temp.itemp.txtpos) {
    
temp.txt.substring(temp.len).pos(a);
    
temp.newtxt @= b
    
temp.newtxt @= txt.substring(temp.lentemp.p); 
  }
  
  return 
temp.newtxt
}

// Crow's :3
function GetPolyRect(xywh)
  return { 
xywywhx}; 


To use it, press E to open the menu and scroll through the items, then W to "use" the highlighted item.

To add more items, just edit the this.toolEntries array in the onCreated() event and also add a function for your new item. Functions are prefixed with "StaffTool" and then the name of the item is added, with all upper case and spaces replaced with underscores. So if your item's name is "Do some crazy StUfF", the function that's being called is StaffToolDO_SOME_CRAZY_STUFF.

Second entry in the item arrays is the icon; change if you want to.


This should run just fine, but it was "dry-stripped" (didn't test it) from an existing system that is way bigger than just this stuff. Report any problems, pretty please.

End product can look like this:
Attachment 52689


Enjoy! <3

Emera 04-11-2011 05:35 PM

Ah good ol crow :)

xAndrewx 04-11-2011 09:43 PM

yes big rip o_o gj skyld / [crow?]

Crow 04-11-2011 09:47 PM

Quote:

Originally Posted by xAndrewx (Post 1642716)
yes big rip o_o gj skyld / [crow?]

Just the idea was taken :p Was the one on Era actually as easily expandable? I can't remember.

xAndrewx 04-11-2011 09:57 PM

Yeah
HTML Code:

  this.tools = {
    {"Exit", "exit", "era_tool-exit.png", "Close tool"},
    {"Staff Stick", "staffstick", "era_icon-staffstick.png", "Destroys NPCs and unsticks players"},
    {"Staff Boomerang", "staffboomerang", "era_icon-staffrang.png", "Destroys NPCs and unsticks players"},
//    {"Staff Block", "staffblock", "era_staffblock.png", "Places staff blocks"},
    {"Staff Boots", "staffboots", "wboots.png", "Say 'Setspeed #'. Walk speed: 'setwalkspeed #'."},
    {"Unstick Me", "unstick", "era_icon-globe-hallow.png", "Go to Unstick me"},
    {"Stealth", "stealth", "block.png", "Turns you invisible"},
    {"Drag", "drag", "block.png", "Drags players"},
    {"Staff Tag", "stafftag", "era_icon-cashmoneys.png", "Adds your staff tag"},
    //{"Staff Chat", "staffchat", "block.png", "Shows staff chat"}
  };

lol it looks nicer though [yours]

cbk1994 04-11-2011 10:00 PM

I can't stand your function name capitalization...why??? Nice release though.

Also, you should probably just use VK_E instead of checking the key code directly.

Crow 04-11-2011 10:29 PM

Quote:

Originally Posted by cbk1994 (Post 1642722)
I can't stand your function name capitalization...why??? Nice release though.

What exactly don't you like? :p Thanks!


Quote:

Originally Posted by cbk1994 (Post 1642722)
Also, you should probably just use VK_E instead of checking the key code directly.

That exists?! Is there a list of all constants like those somewhere? I thought Graal didn't have these.

cbk1994 04-11-2011 10:36 PM

Quote:

Originally Posted by Crow (Post 1642727)
What exactly don't you like? :p

I'm used to using upper case first letter for object/class names and a lowercase first letter for methods like in Java.

Quote:

That exists?! Is there a list of all constants like those somewhere? I thought Graal didn't have these.
It exists, but I don't know of any documentation. We just found out about it recently. Gotta love GScript.

Quote:

Originally Posted by Stefan (Post 1574657)
It has been added more than 3 years ago x-x
Additionally to the normal VK_ defines it also provides VK_A, .. VK_Z (value is the same as 'a' ... 'z')


Crow 04-11-2011 10:55 PM

Quote:

Originally Posted by cbk1994 (Post 1642729)
I'm used to using upper case first letter for object/class names and a lowercase first letter for methods like in Java.

Well, it's all about preference I guess. I got used to upper case for my own functions and lower case for Graal's. Not sure why, but it works nicely.

Also, GScript really needs some solid documentation.

PowerProNL 04-11-2011 11:10 PM

You must spread some Reputation around before giving it to Crow again.

Demisis_P2P 04-12-2011 07:14 AM

Quote:

Originally Posted by Crow (Post 1642732)
Also, GScript really needs some solid documentation.

Maybe when GS3 comes out. Stefan's added way too much stuff to GS2 that nobody knows about to start documenting it now.

Crow 04-12-2011 09:57 AM

Quote:

Originally Posted by Demisis_P2P (Post 1642827)
Maybe when GS3 comes out. Stefan's added way too much stuff to GS2 that nobody knows about to start documenting it now.

The sole purpose of GS3 would probably be the documentation.

Emera 04-12-2011 05:29 PM

Gs3???!!!??

Devil_Lord2 04-12-2011 10:13 PM

Quote:

Originally Posted by Crow (Post 1642851)
The sole purpose of GS3 would probably be the documentation.

I hopes so >.>,
And I hope it explains better than commands.txt and bible..
That would be awesome :]

fatcat123 07-19-2011 06:36 PM

I love this. :blush:

Although, when I die, I cannot figure out why the black GUI disappears and all I see is the wording of the staff tool name in white font.


All times are GMT +2. The time now is 09:26 AM.

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