Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-25-2009, 10:05 AM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Clicky Hud (GUI)

HTML Code:
//#CLIENTSIDE
function onCreated() {
    //How many bars there are... [in order]
  if (client.hud_barsactive == null) {
    client.hud_barsorder = {"hp", "armor", "weapon", "money", "time"};
    client.hud_barsactive = {1, 1, 1, 1, 1};
    client.inv_trans = 1;
  }
  this.onDisplay();
}

function onDisplay() {
  temp.ix = 5;
  temp.iy = 5;
  
  hideimgs(200, 300);
  this.buttons = {};
  for (temp.i = 0; temp.i < client.hud_barsorder.size(); temp.i++) {   
    temp.active = getRowByID(i);
    
    temp.img = showimg(201 + i, "era_gui_line2.png", ix, iy + (i * 16));
    temp.img.layer = 4;
    temp.img.partx = 0; temp.img.party = 0;
    temp.img.partw = (active? 112: 13); temp.img.parth = 16;
    temp.img.alpha = 1;    

    if (active) {
      this.("onDraw" @ getNameByID(i))({ix, iy + (i * 16)});
      this.buttons.add({i, {ix + 12, iy + (i * 16)}, {112, 12}, "row"}); 
    }
    
    temp.text = (active? "-":"+");
    temp.img = showtext(210 + i, ix + 4, iy + (i * 16), "Arial", "b", temp.text);
    temp.img.layer = 4;
    temp.img.zoom = (active? 0.75:0.7);
    
    this.buttons.add({i, {ix, iy + (i * 16)}, {16, 16}});
  }
}

function drawBars(bar) {
  temp.img = showimg(bar[0], "era_gui_hpbars.png", bar[1][0], bar[1][1]);
  temp.img.layer = 5;
  temp.img.partw = 66; temp.img.parth = 10; 
  
  temp.img = showimg(bar[0] + 1, "era_gui_hpbars.png", bar[1][0], bar[1][1]);
  temp.img.layer = 6;
  temp.img.partw = bar[2][0]; temp.img.parth = 10;
  temp.img.party = bar[2][1];
}

function onDrawHP(pos) {
  temp.img = showtext(230, temp.pos[0] + 43, temp.pos[1] + 1, "Arial", "b", "HP:" @ max(0, clientr.hp) @ "/" @ clientr.hpmax);
  temp.img.layer = 7; temp.img.zoom = 0.6;
  temp.img.alpha = 0.6;

  temp.img = showimg(231, "era_gui_symbols.png", temp.pos[0] + 15, temp.pos[1] + 1); 
  temp.img.layer = 6;  temp.img.partx = (level.nopkzone? 16: 0);
  temp.img.partw = 16; temp.img.parth = 16;
 
  this.drawBars({232, {pos[0] + 35, pos[1] + 3}, {max(1, roundTo((clientr.hp / clientr.hpmax) * 66, 10)), 10}});
}

function onDrawArmor(pos) {
  temp.img = showtext(240, temp.pos[0] + 43, temp.pos[1] + 1, "Arial", "b", "Armor:" @ max(0, clientr.armor) @ "/" @ max(0, clientr.armormax));
  temp.img.layer = 7; temp.img.zoom = 0.6;
  temp.img.alpha = 0.6;

  temp.img = showimg(241, "era_gui_symbols.png", temp.pos[0] + 15, temp.pos[1] + 1); 
  temp.img.layer = 26;  temp.img.partx = 32;
  temp.img.partw = 16; temp.img.parth = 16;

  this.drawBars({242, {pos[0] + 35, pos[1] + 3}, {max(1, roundTo((clientr.armor / clientr.armormax) * 66, 10)), 40}});
}

function onDrawMoney(pos) {
  temp.img = showtext(250, temp.pos[0] + 43, temp.pos[1] + 1, "Arial", "b", "$" @ player.rupees);
  temp.img.layer = 7; temp.img.zoom = 0.6;
  temp.img.alpha = 0.6;

  temp.img = showimg(251, "era_gui_symbols.png", temp.pos[0] + 15, temp.pos[1] + 1); 
  temp.img.layer = 26;  temp.img.partx = 64;
  temp.img.partw = 16; temp.img.parth = 16;
}

function onDrawTime(pos) {
  if (!getRowByName("time")) return false;

  temp.cHours = int(hours);
  if (cHours >= 12) cHours -= 12;
  if (cHours == 0) cHours = 12;

  //Replace the £ with the percentage sign
  temp.cTime = int(cHours / 10) @ int(cHours £ 10) @ ":" @ int(mins / 10) @ int(mins £ 10);
  
  cTime = cTime SPC (hours >= 12? "PM":"AM");

  temp.img = showtext(260, temp.pos[0] + 43, temp.pos[1] + 1, "Arial", "b", cTime);
  temp.img.layer = 7; temp.img.zoom = 0.6;
  temp.img.alpha = 0.6;

  temp.img = showimg(261, "era_gui_symbols.png", temp.pos[0] + 15, temp.pos[1] + 1); 
  temp.img.layer = 26;  temp.img.partx = 48;
  temp.img.partw = 16; temp.img.parth = 16;
  
  cancelevents("DrawTime");
  scheduleevent(3, "DrawTime", {temp.pos});
}

function onDrawWeapon(pos) {
  temp.img = showimg(270, "era_gui_symbols.png", temp.pos[0] + 15, temp.pos[1] + 1); 
  temp.img.layer = 26;  temp.img.partx = 80;
  temp.img.partw = 16; temp.img.parth = 16;
}

function onMouseDown(click) {
  if (!(temp.click in {"right", "left"})) return false;
  
  temp.m = {mousescreenx, mousescreeny};
  for (temp.i: this.buttons) {
    if (m[0] in |i[1][0], i[1][0] + i[2][0]| && m[1] in |i[1][1], i[1][1] + i[2][1]|) {
      if (click == "right") {
        client.inv_trans -= 0.2;
        if (client.inv_trans < 0) client.inv_trans = 1; 
        this.onDisplay();
        break;
      }
      if (i[3] == null) {
        this.onToggleRow(i[0]);
        this.onDisplay();
        break;
      } else {
        if (mousebuttons > 0) {
          this.data = i;
          setTimer(0.05);
        }
      }
    }
  }
}

function onTimeout() {
  temp.i = this.data;
  if (mousescreeny in |i[1][1] + i[2][1], i[1][1] + (i[2][1] * 2)|) {
    if (i[0] == (client.hud_barsorder.size() - 1)) return false;
            
    temp.index = client.hud_barsorder.index(getNameByID(i[0]));
    temp.data = client.hud_barsorder[temp.index + 1];
            
    temp.copy = client.hud_barsorder;
    temp.copy.replace(index, data);
    temp.copy.replace(index + 1, getNameByID(i[0]));
    client.hud_barsorder = temp.copy;
            
    this.data = {i[0] + 1, {i[1][0], i[1][1] + 16}, {112, 12}, "row"};
    this.onDisplay();
  }
   else 
  if (mousescreeny in |i[1][1] - (i[2][1] + 12), i[1][1] - i[2][1]|) {
    if (i[0] == 0) return false;
            
    temp.index = client.hud_barsorder.index(getNameByID(i[0]));
    temp.data = client.hud_barsorder[temp.index-1];
           
    temp.copy = client.hud_barsorder;
    temp.copy.replace(index, data);
    temp.copy.replace(index - 1, getNameByID(i[0]));
    client.hud_barsorder = temp.copy;

    this.data = {i[0] - 1, {i[1][0], i[1][1] - 16}, {112, 12}, "row"};            
    this.onDisplay();
  }
  if (mousebuttons > 0) setTimer(0.05);
}

function onToggleRow(flag) {
  client.hud_barsactive[temp.flag] = !client.hud_barsactive[temp.flag];
}

function getRowByName(flag) {
  return client.hud_barsactive[client.hud_barsorder.index(temp.flag)];
}

function getRowByID(flag) {
  return client.hud_barsactive[temp.flag];
}

function getNameByID(flag) {
  return client.hud_barsorder[temp.flag];
}

function roundTo(val, place) {
  return int(temp.val / temp.place + 0.5) * temp.place;
}

function onUpdateVariable(temp.varName) {
  if (!(varName in {"hp", "hpmax", "armor", "armormax"}))
    return false;
    
  this.onCreated();
}
I designed this for Era Dev, but it was never used. Here's the HUD
Attached Images
   
Reply With Quote
  #2  
Old 04-25-2009, 07:19 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
I'd like to point out that since these images are being used by Era currently and in the future, you're going to have to make your own graphics if you use this.

Also, the script looks okay, but I would add a way to update a single bar without updating the entire interface.
__________________
Reply With Quote
  #3  
Old 11-29-2009, 09:22 PM
Samposse Samposse is offline
Chopa Shopa !
Samposse's Avatar
Join Date: Nov 2008
Location: Norway
Posts: 87
Samposse is an unknown quantity at this point
Send a message via AIM to Samposse Send a message via MSN to Samposse
I will Edit those Image / make my own but im just testing the scrit whit Era's image to see it the Script self works .. and it dont wher do i put it in and is it a GUI system ?
__________________
Delitto :3

A
SERVER
UNDER
CONSTRUCTION !

feel free to ask me about delitto
Reply With Quote
  #4  
Old 11-30-2009, 12:17 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Samposse View Post
I will Edit those Image / make my own but im just testing the scrit whit Era's image to see it the Script self works .. and it dont wher do i put it in and is it a GUI system ?
Put it in a weapon named something like "-System/HUD" and make sure you have the weapon. Also, "Replace the £ with the percentage sign"
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #5  
Old 11-30-2009, 10:36 AM
Samposse Samposse is offline
Chopa Shopa !
Samposse's Avatar
Join Date: Nov 2008
Location: Norway
Posts: 87
Samposse is an unknown quantity at this point
Send a message via AIM to Samposse Send a message via MSN to Samposse
Quote:
Originally Posted by Switch

Replace the £ with the percentage sign
????
i dont know what to do or where that is ... may you just Post me the Script Complete ?
whit that Replace the £ with the percentage sign done ?

plz
__________________
Delitto :3

A
SERVER
UNDER
CONSTRUCTION !

feel free to ask me about delitto
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 12:05 AM.


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