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 05-29-2007, 06:45 PM
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
Graphical Interface

Here's a simple gui effect

HTML Code:
//#CLIENTSIDE
function onCreated()
{
  playergui = this;
  this.startGui();
}

function startGui()
{
  this.guiPosition = {2, 2};
   
  this.updateData();
  
  for (temp.currentImage: this.imageData)
  {
    this.drawImage(temp.currentImage);
  }
}
function updateData()
{
  this.imageData = {
    {200, "c_gui-base.png", this.guiPosition, 4},
    {201, player.headimg, {(this.guiPosition[0] + 4), (this.guiPosition[1] + 6)}, 5, {0, 64, 32, 32}},
    {202, "c_gui-hpbar.png", {(this.guiPosition[0] + 42), (this.guiPosition[1] + 11)}, 5, {0, 0, this.findBar("hp"), 7}},
    {203, "c_gui-mpbar.png", {(this.guiPosition[0] + 42), (this.guiPosition[1] + 22)}, 5, {0, 0, 59, 7}}
  };
}
function drawImage(imageData)
{
  showimg(temp.imageData[0], temp.imageData[1], temp.imageData[2][0], temp.imageData[2][1]);
  changeimgvis(temp.imageData[0], temp.imageData[3]);
  if (temp.imageData[4].size() == 4)
  {
    changeimgpart(temp.imageData[0], temp.imageData[4][0], temp.imageData[4][1], temp.imageData[4][2],temp.imageData[4][3]);
  }
}

function findBar(barType)
{
  if (temp.barType == "hp")
    return ((player.hearts / player.fullhearts) * 59 <= 1? 1: (player.hearts / player.fullhearts) * 59);
}

public function updateHP()
{
  this.updateData();
  this.drawImage(this.imageData[2]);
}

public function updateMP()
{ 
  //place holder, make your own! 
}
public function hideGui()
{
  hideimgs(200, 210);
}
Here are the images! It's the top left gui thing.
Attached Thumbnails
Click image for larger version

Name:	myGui.png
Views:	359
Size:	24.6 KB
ID:	41353  
Attached Images
   
__________________
Reply With Quote
  #2  
Old 05-31-2007, 01:39 AM
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
Looks nice. Script is a bit long for this, but that's not a problem. Long scripts don't usually mean anything.
__________________
Reply With Quote
  #3  
Old 05-31-2007, 01:40 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by cbkbud View Post
Looks nice. Script is a bit long for this, but that's not a problem. Long scripts don't usually mean anything.
bytes ++
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #4  
Old 05-31-2007, 01:42 AM
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 xXziroXx View Post
postcount ++
Fixed it for you.
bytes mean nothing, really. NPC-Server reads through it the same (though it's on the client in this script), so no harm, no foul.
__________________
Reply With Quote
  #5  
Old 05-31-2007, 01:46 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by cbkbud View Post
bytes mean nothing, really. NPC-Server reads through it the same (though it's on the client in this script), so no harm, no foul.
I know it doesn't. But I still think that the smaller a script can be in lines/words/whatever, and still be able to perform the same way another script that has more lines/words/whatever is the better script.

But hey, that's just my point of view.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #6  
Old 05-31-2007, 01:48 AM
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 xXziroXx View Post
I know it doesn't. But I still think that the smaller a script can be in lines/words/whatever, and still be able to perform the same way another script that has more lines/words/whatever is the better script.

But hey, that's just my point of view.
In that case

PHP Code:
function onCreated() { if (true){ dosomething(); dosomethingelse(); } if ( nottruelol ) { dothis(); killplayer(); } } function onPlayerEnters() { player.chat "foo"; if (player.30 ) { player.31player.chat "HAXOR!" } } 
(My ingenius haxor protection system)
__________________
Reply With Quote
  #7  
Old 05-31-2007, 02:19 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
With coding/scripting, it should be a practice to make codes/scripts as efficiently short as possible.
Reply With Quote
  #8  
Old 05-31-2007, 02:28 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by cbkbud View Post
In that case

PHP Code:
function onCreated() { if (true){ dosomething(); dosomethingelse(); } if ( nottruelol ) { dothis(); killplayer(); } } function onPlayerEnters() { player.chat "foo"; if (player.30 ) { player.31player.chat "HAXOR!" } } 
(My ingenius haxor protection system)

PHP Code:
function onCreated(){if (1){s();o();} if (0){t();k();}} function onPlayerEnters(){player.chat="foo";if(player.x<30){player.x=31;player.chat="HAXOR!"}} 
By Ziro's interpretation, I optimized your code.
Reply With Quote
  #9  
Old 05-31-2007, 04:08 AM
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 DustyPorViva View Post
With coding/scripting, it should be a practice to make codes/scripts as efficiently short as possible.
Why?
__________________
Reply With Quote
  #10  
Old 05-31-2007, 04:23 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
It's good practice. IE, it might not be completely useful in Graal, but it is in practice. Small changes in scripts and making it shorter and more efficient for Graal might not make a difference on its own, but do so to a bunch of scripts and it will.
Also, for coding, it's very important to code efficiently for various reasons.
Reply With Quote
  #11  
Old 05-31-2007, 04:25 AM
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 DustyPorViva View Post
It's good practice. IE, it might not be completely useful in Graal, but it is in practice. Small changes in scripts and making it shorter and more efficient for Graal might not make a difference on its own, but do so to a bunch of scripts and it will.
Also, for coding, it's very important to code efficiently for various reasons.
Length of script and effective code have absolutly no corrolation at all.
__________________
Reply With Quote
  #12  
Old 05-31-2007, 04:53 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Why do
PHP Code:
function onWeaponfired() {
  if (
player.dir==0shoot(blahblah crap for direction 0);
  if (
player.dir==1shoot(blahblah crap for direction 1);
  if (
player.dir==2shoot(blahblah crap for direction 2);
  if (
player.dir==3shoot(blahblah crap for direction 3);

when you can do
PHP Code:
function onWeaponfired() {
  
shoot(formulate the angle depending on the direction);

?
Sure, the first way works, but it's silly to not try to improve your scripting by finding shorter alternatives. Like I said, it's better practice. There may not be any hard evidence as to why, in terms of efficiency, but you can learn a lot of things by trying to think outside the box and find ways to shorten your code.
Reply With Quote
  #13  
Old 05-31-2007, 05:04 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by cbkbud View Post
Why?
To me, it seems as if you're arguing against shorter code just for the sake of arguing.
__________________
Reply With Quote
  #14  
Old 05-31-2007, 10:41 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
Quote:
Originally Posted by cbkbud View Post
Looks nice. Script is a bit long for this, but that's not a problem. Long scripts don't usually mean anything.
Show me how you'd make this gui, with the capability to add more features easily.
__________________
Reply With Quote
  #15  
Old 05-31-2007, 12:40 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 DustyPorViva View Post
Why do
PHP Code:
function onWeaponfired() {
  if (
player.dir==0shoot(blahblah crap for direction 0);
  if (
player.dir==1shoot(blahblah crap for direction 1);
  if (
player.dir==2shoot(blahblah crap for direction 2);
  if (
player.dir==3shoot(blahblah crap for direction 3);

when you can do
PHP Code:
function onWeaponfired() {
  
shoot(formulate the angle depending on the direction);

?
Sure, the first way works, but it's silly to not try to improve your scripting by finding shorter alternatives. Like I said, it's better practice. There may not be any hard evidence as to why, in terms of efficiency, but you can learn a lot of things by trying to think outside the box and find ways to shorten your code.
????????

I never said anything about something like that. If there is a way to make it shorter, fine. I'm saying long doesn't mean bad, which is true. Short doesn't even mean more effiecent, though it can be most of the time.
__________________
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 09:28 PM.


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