Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Help with GS2 Script (https://forums.graalonline.com/forums/showthread.php?t=73202)

foxboi 04-01-2007 05:02 PM

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.

Chandler 04-01-2007 05:07 PM

HTML Code:

function onPlayerChats()
  {
  if (player.chat.starts("/box"))
    this.chat = min(player.chat.substring(4).trim(), 2);
  elseif (player.chat == "/reset")
    this.chat = "";
  }


foxboi 04-01-2007 06:54 PM

Quote:

Originally Posted by Chandler (Post 1295329)
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>?

Chandler 04-01-2007 07:08 PM

Quote:

Originally Posted by foxboi (Post 1295357)
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!

killerogue 04-01-2007 07:26 PM

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.

Chandler 04-01-2007 09:00 PM

Quote:

Originally Posted by killerogue (Post 1295370)
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 ^^

killerogue 04-01-2007 09:09 PM

Quote:

Originally Posted by Chandler (Post 1295441)
That's fine, nice work ^^

Thanks. :P

foxboi 04-01-2007 11:43 PM

killer, your "/reset" part isn't working, but everything ELSE worked out great. :D

killerogue 04-02-2007 01:53 AM

It's supposed to not show anything at all. Hence the meaning of "NULL".

foxboi 04-02-2007 02:16 PM

I know, the number stays there, and when I say "/reset" it won't disappear.

Twinny 04-02-2007 02:22 PM

Quote:

Originally Posted by killerogue (Post 1295370)
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

killerogue 04-02-2007 07:42 PM

Oh, sorry. Blegh.

godofwarares 04-02-2007 09:11 PM

Quote:

Originally Posted by killerogue (Post 1295370)
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. 


foxboi 04-02-2007 10:51 PM

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..

Riot 04-02-2007 10:59 PM

Quote:

Originally Posted by godofwarares (Post 1296011)
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"

godofwarares 04-02-2007 11:06 PM

Quote:

Originally Posted by Riot (Post 1296047)
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


All times are GMT +2. The time now is 01:18 AM.

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