Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-01-2007, 05:02 PM
foxboi foxboi is offline
zzzzz
foxboi's Avatar
Join Date: Aug 2005
Posts: 101
foxboi is on a distinguished road
Help with GS2 Script

NPC Code:
function onPlayerChats()
if(player.chat=="/box1"){
message 1;
}
if(player.chat.starts("/box1")){
this.t = player.chat.tokenize();
this.t[0] = "/box1";
if(this.t[1]=="2"){
message 2;
}
}
function onPlayerChats(){
if(player.chat=="/reset"){
message;
}
}




Just learning how to script.. umm the whole point of this script is when the player says /box1 the number 1 appears in the place I laid the level npc. Also when I say /box1 2, it is supposed to display 2 but when i say /reset it deletes the number.. But right now when I say /box1 or /box1 2 it doesn't work netiher does the /reset part...

Help Please lmao.
Reply With Quote
  #2  
Old 04-01-2007, 05:07 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
HTML Code:
function onPlayerChats()
  {
  if (player.chat.starts("/box"))
    this.chat = min(player.chat.substring(4).trim(), 2);
  elseif (player.chat == "/reset")
    this.chat = "";
  }
Reply With Quote
  #3  
Old 04-01-2007, 06:54 PM
foxboi foxboi is offline
zzzzz
foxboi's Avatar
Join Date: Aug 2005
Posts: 101
foxboi is on a distinguished road
Quote:
Originally Posted by Chandler View Post
HTML Code:
function onPlayerChats()
  {
  if (player.chat.starts("/box"))
    this.chat = min(player.chat.substring(4).trim(), 2);
  elseif (player.chat == "/reset")
    this.chat = "";
  }



Yeah code you sorta explain how you made that script>?
Reply With Quote
  #4  
Old 04-01-2007, 07:08 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by foxboi View Post
Yeah code you sorta explain how you made that script>?
Sure, well I only call the function once, that is when the player chats.
PHP Code:
function onPlayerChats()  
  {
  } 
Now, you check what it is the player is saying. You can do this many of ways, I used the normal
PHP Code:
if (player.chat.starts("/box"))
  {
  } 
As you only know what the player is going to start their chat with, you can't add anything else.
You'll then notice I used one line, to make the chat of the NPC change.
PHP Code:
this.chat min(player.chat.substring(4).trim(), 2); 
Well, this.chat works the same as
PHP Code:
message("Hi there"); 
So don't get lost on that part!
You're probably lost on the part after this though, being this:
PHP Code:
min(player.chat.substring(4).trim(), 2); 
Well, I'll explain "min()" first.
PHP Code:
min(number1number2); 
Basically, it'll see which number [being that number1 or number2] is the lowest.
So, since we know that you only wanted to use two boxes, I know that the lowest highest number that you needed would be 2. Anything over that number will set it automatically to 2, do you see this? [If not, I shall explain again!]
You'll then see what I did to the players chat with this command
PHP Code:
player.chat.substring(4).trim() 
What I am doing is cutting the first four letters from the players chat. ["/box"] being the four letters being cut each time, leaving only the number left. I added the ".trim()" part, to remove the unnecessary spaces that was left out. [" " <--Being an unnecessary space]

I hope this helped!
Reply With Quote
  #5  
Old 04-01-2007, 07:26 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
What Chandler posted is most likely to help you, but I took about 5-6 minutes to make this

PHP Code:
// This will require the player follows this format:
// "/box 1". <- Too change the box number.

//#CLIENTSIDE
function onPlayerChats()
{

  if(
player.chat.starts("/box")) //C hecks if the player chat starts with this
  
{

    
tokens player.chat.tokenize(); //S plits the player chat into tokens
    
if(tokens[1] == 1// If this is true
    
{
      
message(1); // Changes the message to this
    
}
    else if (
tokens[1] == 2// If the above is not true and this is true
    
{
      
message(2); // Changes the message to this
    
}
  }
}

function 
onPlayerChats()
{

  if(
player.chat == "/reset"//Checks if this is the players chat
  
{
    
message(NULL); //If the above is true does this
  
}

PHP Code:
//Doesn't follow any format and you must say it as it's portrayed
//in the script.

//#CLIENTSIDE

function onPlayerChats()
{
  if (
player.chat == "/box1"// If this is true
  
{
    
message(1); // Does this
  
}
  else if (
player.chat == "/box2"// If above is not true and this is
  
{
    
message(2); // Does this
  
}
  else if (
player.chat == "/reset"// If both things above are untrue
  
{  
    
message(NULL); // Does this
  
}

The latter being much simpler and easier to understand.


Edit: I quite like how you did that by the way Chandler, really nice.

This was just posted to give a more general and, in this case, less advanced way to do things.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #6  
Old 04-01-2007, 09:00 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by killerogue View Post
The latter being much simpler and easier to understand.


Edit: I quite like how you did that by the way Chandler, really nice.

This was just posted to give a more general and, in this case, less advanced way to do things.
That's fine, nice work
Reply With Quote
  #7  
Old 04-01-2007, 09:09 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Chandler View Post
That's fine, nice work
Thanks. :P
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #8  
Old 04-01-2007, 11:43 PM
foxboi foxboi is offline
zzzzz
foxboi's Avatar
Join Date: Aug 2005
Posts: 101
foxboi is on a distinguished road
killer, your "/reset" part isn't working, but everything ELSE worked out great.
Reply With Quote
  #9  
Old 04-02-2007, 01:53 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
It's supposed to not show anything at all. Hence the meaning of "NULL".
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #10  
Old 04-02-2007, 02:16 PM
foxboi foxboi is offline
zzzzz
foxboi's Avatar
Join Date: Aug 2005
Posts: 101
foxboi is on a distinguished road
I know, the number stays there, and when I say "/reset" it won't disappear.
Reply With Quote
  #11  
Old 04-02-2007, 02:22 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by killerogue View Post
What Chandler posted is most likely to help you, but I took about 5-6 minutes to make this

PHP Code:
// This will require the player follows this format:
// "/box 1". <- Too change the box number.

//#CLIENTSIDE
function onPlayerChats()
{

  if(
player.chat.starts("/box")) //C hecks if the player chat starts with this
  
{

    
tokens player.chat.tokenize(); //S plits the player chat into tokens
    
if(tokens[1] == 1// If this is true
    
{
      
message(1); // Changes the message to this
    
}
    else if (
tokens[1] == 2// If the above is not true and this is true
    
{
      
message(2); // Changes the message to this
    
}
  }
}

function 
onPlayerChats()
{

  if(
player.chat == "/reset"//Checks if this is the players chat
  
{
    
message(NULL); //If the above is true does this
  
}

It may just be me but isn't having two of the same events under //#CLIENTSIDE bad practise? You have function onPlayerChats() defined twice
Reply With Quote
  #12  
Old 04-02-2007, 07:42 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Oh, sorry. Blegh.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #13  
Old 04-02-2007, 09:11 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
Quote:
Originally Posted by killerogue View Post
What Chandler posted is most likely to help you, but I took about 5-6 minutes to make this

PHP Code:
// This will require the player follows this format:
// "/box 1". <- Too change the box number.

//#CLIENTSIDE
function onPlayerChats()
{

  if(
player.chat.starts("/box")) //C hecks if the player chat starts with this
  
{

    
tokens player.chat.tokenize(); //S plits the player chat into tokens
    
if(tokens[1] == 1// If this is true
    
{
      
message(1); // Changes the message to this
    
}
    else if (
tokens[1] == 2// If the above is not true and this is true
    
{
      
message(2); // Changes the message to this
    
}
  }
}

function 
onPlayerChats()
{

  if(
player.chat == "/reset"//Checks if this is the players chat
  
{
    
message(NULL); //If the above is true does this
  
}

PHP Code:
message(NULL); // NULL isn't a string...
message(""); // That'll work. "" is a string. Null won't work here. 
__________________
What signature? I see no signature?
Reply With Quote
  #14  
Old 04-02-2007, 10:51 PM
foxboi foxboi is offline
zzzzz
foxboi's Avatar
Join Date: Aug 2005
Posts: 101
foxboi is on a distinguished road
NPC Code:
//#CLIENTSIDE
function onPlayerChats()
{

if(player.chat.starts("/seat1"))
{

tokens = player.chat.tokenize();
if(tokens[1] == 1)
{
message(1);
}
else if (tokens[1] == 2){
message(2);
}
else if (tokens[1] == 3){
message(3);
}
else if (tokens[1] == 4){
message(4);
}
else if (tokens[1] == 5){
message(5);
}
else if (tokens[1] == 6){
message(6);
}
}
}

function onPlayerChats()
{

if(player.chat == "/reset"){
message("");

}
}



I have that but it still won't work.. everything else with setting of points work.. Not the /reset though..
Reply With Quote
  #15  
Old 04-02-2007, 10:59 PM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
Quote:
Originally Posted by godofwarares View Post
PHP Code:
message(NULL); // NULL isn't a string...
message(""); // That'll work. "" is a string. Null won't work here. 
message(NULL); will work fine. "" is considered null as far as Graal is concerned, as is 0.

The following works fine:
HTML Code:
function onCreated()
{
  message("test");
  this.scheduleEvent(1, "hide", null);
}

function onHide()
{
  message(null);
}
It, however, won't work if you just assign this.chat. this.chat = null; would make the current object's chat "0"
Reply With Quote
  #16  
Old 04-02-2007, 11:06 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
Quote:
Originally Posted by Riot View Post
message(NULL); will work fine. "" is considered null as far as Graal is concerned, as is 0.

The following works fine:
HTML Code:
function onCreated()
{
  message("test");
  this.scheduleEvent(1, "hide", null);
}

function onHide()
{
  message(null);
}
It, however, won't work if you just assign this.chat. this.chat = null; would make the current object's chat "0"
I know, But it's good practice to use message(""); ... No non-strings are acceptable xP
__________________
What signature? I see no signature?
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 07:37 AM.


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