Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-13-2009, 09:09 AM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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.
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.

Last edited by Tigairius; 07-14-2009 at 03:16 AM.. Reason: Don't try to evade the swear filter, it's here for a reason.
Reply With Quote
  #2  
Old 07-13-2009, 09:26 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 Liberated View Post
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.";
  }

__________________

Last edited by Tigairius; 07-14-2009 at 03:16 AM..
Reply With Quote
  #3  
Old 07-13-2009, 09:38 AM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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?
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #4  
Old 07-13-2009, 09:44 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 Liberated View Post
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.
__________________
Reply With Quote
  #5  
Old 07-13-2009, 09:47 AM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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!";

__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #6  
Old 07-13-2009, 11:03 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 Liberated View Post
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).
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 07:26 PM.


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