Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   my first code (https://forums.graalonline.com/forums/showthread.php?t=86870)

Liberated 07-13-2009 09:09 AM

my first code
 
I hope this is the right place to post this, but i'm getting into Gscript2, and want to make sure i do everything correct, i was just wondering if i scripted this correctly, and what i could different and/or better.

PHP Code:

function onCreated () 
{
setimg ("door.png");
}

//#CLIENTSIDE

function onPlayerchats () 
{
 if (
player.chat == "hello")
 {
 
this.chat "hi There";
 }
   else  
 if (
player.chat == "you're dumb")
 {
  
this.chat "I do NOT wish to talk to you sir.";
 }


yeah i know it's a talking door.

cbk1994 07-13-2009 09:26 AM

Quote:

Originally Posted by Liberated (Post 1506615)
I hope this is the right place to post this, but i'm getting into Gscript2, and want to make sure i do everything correct, i was just wondering if i scripted this correctly, and what i could different and/or better.

PHP Code:

function onCreated () 
{
setimg ("door.png");
}

//#CLIENTSIDE

function onPlayerchats () 
{
 if (
player.chat == "hello")
 {
 
this.chat "hi There";
 }
   else  
 if (
player.chat == "you're dumb")
 {
  
this.chat "I do NOT wish to talk to you sir.";
 }


yeah i know it's a talking door.

You did a couple things wrong. Here's how it should be written (see comments):

PHP Code:

function onCreated() // events should not have spaces before the paranthesis 
{
  
setimg("door.png"); // always indent two spaces (press TAB if using RC) and functions should not have a space before the parameters
}

//#CLIENTSIDE

function onPlayerchats()  // remember the parenthesis
{
  if (
player.chat == "hello")
  {
    
this.chat "hi There"// remember to indent two spaces
  
}
  else if (
player.chat == "you're dumb"// most people will put the else and if on the same line, but it doesn't really matter - people do it both ways
  
{
    
this.chat "I do NOT wish to talk to you sir.";
  }



Liberated 07-13-2009 09:38 AM

okay thanks, i'm now working on a script for a handheld item, just for practice, but im not sure, is the setani client or serverside?

cbk1994 07-13-2009 09:44 AM

Quote:

Originally Posted by Liberated (Post 1506617)
okay thanks, i'm now working on a script for a handheld item, just for practice, but im not sure, is the setani client or serverside?

It works either way.

Liberated 07-13-2009 09:47 AM

so would this be correct?( i doubt it since it since im such a nab, but w/e)
I also can't test it myself on testbed because somehow i can't open my Q inventory.

PHP Code:

onCreated()
{
  
player.attr[1] = "toygun.png";
  
setani("gunani","");
}

//#CLIENTSIDE

onWeaponFired()
{
  
this.chat "BANG, owait, no bullet, it's a toygun!";



cbk1994 07-13-2009 11:03 AM

Quote:

Originally Posted by Liberated (Post 1506619)
so would this be correct?( i doubt it since it since im such a nab, but w/e)
I also can't test it myself on testbed because somehow i can't open my Q inventory.

PHP Code:

onCreated()
{
  
player.attr[1] = "toygun.png";
  
setani("gunani","");
}

//#CLIENTSIDE

onWeaponFired()
{
  
this.chat "BANG, owait, no bullet, it's a toygun!";



For one thing, you forgot the function in front of your events.

I'm not sure why you're setting it serverside. That's being called when you update the weapon, not when you fire it. You would have to use triggers to call that, and that would be really stupid for a gun. Move all the stuff down into the onWeaponFired event.

PHP Code:

//#CLIENTSIDE
function onWeaponFired()
{
  
player.attr[1] = "toygun.png";
  
setAni("gunani"null);
  
this.chat "boom";


However, weapons are "invisible" - they don't have a physical location on your screen, so there's no way for you to see text, unlike with an NPC (e.g. a talking door). You most likely want to set the player's chat with this:

PHP Code:

player.chat "chat"

which brings your script to

PHP Code:

//#CLIENTSIDE
function onWeaponFired()
{
  
player.attr[1] = "toygun.png";
  
setAni("gunani"null);
  
player.chat "boom";


Normally you should only use serverside when you're doing something that affects multiple players (e.g. attacking players) or you need to do something in a way that is secure and cannot be easily "hacked" by players with memory editors. There's some more information about that here and here. I'm not sure if there's an article on communicating between the two, I'll try to find one. If not, I'll write one later.

EDIT: There's some information on triggers here (use your browser's "Find" to look for triggerserver and triggerclient).


All times are GMT +2. The time now is 04:12 PM.

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