Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Token problem (https://forums.graalonline.com/forums/showthread.php?t=73840)

Sum41Freeeeek 05-06-2007 12:40 AM

Token problem
 
I'm making a gang system, but I'm having a small problem.
I have this in a class:

PHP Code:

function onPlayerchats()
{
  if (
player.chat.starts(":"))
  {
    
findNpc("Gang Control").leaderCommand(player.chat);
  }


and I have this in the Gang Control npc

PHP Code:

public function leaderCommand(toks)
{
  switch (
temp.toks[0])
  {
    case 
":addmember":
      
player.chat "testing";
    break;
  }


when I say :addmember alone, it switches my test to "testing" which is what I want, sort of (since I'm trying to debug it) but if I say :addmember blahwhatever, it doesn't do anything.

even if I changed it to player.chat = temp.toks[1]; , it doesn't return temp.toks[1] what am I doing wrong?

sorry if I don't explain it that well, I tried my best.

Skyld 05-06-2007 12:42 AM

Change public function leaderCommand(toks) to (cmd) or something, and then immediately after, do:
PHP Code:

temp.toks temp.cmd.tokenize(); 

Strings don't tokenize themselves; in your script, temp.toks is the full chat string, not a tokenized array from tokenize();.

Sum41Freeeeek 05-06-2007 12:44 AM

worked, thanks.

killerogue 05-06-2007 12:50 AM

Ha ha, I was going to post something similar before Mr. Gscript ( phrase originally coined by Twinny ) came in to save the day! :P

cbk1994 05-06-2007 01:41 PM

Quote:

Originally Posted by Sum41Freeeeek (Post 1305757)
I'm making a gang system, but I'm having a small problem.
I have this in a class:

PHP Code:

function onPlayerchats()
{
  if (
player.chat.starts(":"))
  {
    
findNpc("Gang Control").leaderCommand(player.chat);
  }


and I have this in the Gang Control npc

PHP Code:

public function leaderCommand(toks)
{
  switch (
temp.toks[0])
  {
    case 
":addmember":
      
player.chat "testing";
    break;
  }


when I say :addmember alone, it switches my test to "testing" which is what I want, sort of (since I'm trying to debug it) but if I say :addmember blahwhatever, it doesn't do anything.

even if I changed it to player.chat = temp.toks[1]; , it doesn't return temp.toks[1] what am I doing wrong?

sorry if I don't explain it that well, I tried my best.

When I use switch( var ), I find it helpful to do it like this:
PHP Code:

switch ( var )
{
  case 
"test":
  {
    
// Stuff Here
    
break;
  }
  case 
"blah":
  {
    
// More stuff here.
    
break;
  }


The braces organize it better, I think atleast.

Sum41Freeeeek 05-06-2007 04:28 PM

I agree. I usually do it like that, but someone told me I didn't really need it for functionallity(sp) so this time I didn't bracket in the case's.

Chandler 05-06-2007 04:32 PM

One to their own.

Novo 05-06-2007 04:43 PM

PHP Code:

temp.toks player.chat.tokenize();
(@
"Gang Control").leaderCommandstemp.toks[0], temp.toks[1], temp.toks[2], temp.toks[3]);

...
public function 
leaderCommandcommandparam1param2param3 )
  {
  if ( ! 
isLeaderplayer.account ) )
    return;

  switch ( 
command )
    {
    default:
      echo( 
"Command ["command @"]: Is not recognized." );
    break;
    }
  } 



All times are GMT +2. The time now is 08:53 PM.

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