Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   My Script Thread (https://forums.graalonline.com/forums/showthread.php?t=134266869)

Imperialistic 07-27-2012 11:33 PM

My Script Thread
 
So as I stated before I'm trying to teach myself further into GS2 and I would appreciate any help or criticism. I guess this is where I'm going to post my 'in progress' scripts and get feedback from you guys whether it's correct or not.

The following script is basically something I am just toying around with to help me sharpen my skills on this particular area (which I'm poor at).

PHP Code:

function onActionServerSide(cmdtarget) {
  if (
cmd == "info") {
    
temp.pl findPlayerByCommunityName(target);
    
temp.level temp.pl " is in the level: " temp.pl.level;
    
temp.loc " X: " temp.pl."   Y: " temp.pl.y;
    if (
pl == null) {
      return 
player.chat "(player not found)";
    }
    
pl.triggerClient("gui"this.name"info"player.communityname);
    echo(
"Info Bot v2 - Level: " temp.level);
    echo(
"Info Bot v2 - X/Y: " temp.loc);
    echo(
"Info Bot v2 - Gralats: " temp.pl.gralats);
    echo(
"Info Bot v2 - ID: " temp.pl.id);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/info ")) {
    
temp.tokens player.chat.tokenize();
    
temp.acc temp.tokens[1];
    
player.chat "Info received!";
    
triggerServer("gui"this.name"info"acc);
  }


Reminder: This isn't finished, it's merely to focus on my weak points and get feedback from more advanced scripters.

I first was coding the echo to look something like this:
PHP Code:

echo("Info Bot v2 - Level: " temp.acc "is located at: " temp.level "X: " temp.pl."Y: " temp.pl.y

But then I realized it was jamming too much into one thing, so I decided to space it out like so:
PHP Code:

    temp.pl findPlayerByCommunityName(target);
    
temp.level temp.pl " is in the level: " temp.pl.level;
    
temp.loc " X: " temp.pl."   Y: " temp.pl.y;

    echo(
"Info Bot v2 - Level: " temp.level);
    echo(
"Info Bot v2 - X/Y: " temp.loc); 


Crow 07-27-2012 11:55 PM

First off, have this code:
PHP Code:

function onActionServerSide(cmdtarget) {
  if (
cmd == "info") {
    
temp.pl findPlayerByCommunityName(target);
    if (
temp.pl == null) {
      
player.chat "(player not found");
      return;
    }

    
temp.level temp.pl.account " is in the level: " temp.pl.level.name;
    
temp.loc " X: " temp.pl."   Y: " temp.pl.y;

    
pl.triggerClient("gui"this.name"info"player.communityname);
    echo(
"Info Bot v2 - Level: " temp.level.name);
    echo(
"Info Bot v2 - X/Y: " temp.loc);
    echo(
"Info Bot v2 - Gralats: " temp.pl.gralats);
    echo(
"Info Bot v2 - ID: " temp.pl.id);
  }


I made some slight modifications. First, there's no reason to store stuff in variables if the referenced object doesn't even exist, so let's check that first. Next, both temp.pl and temp.pl.level are, in this case, objects. Nothing you should put into a string. Instead, let's use temp.pl.account and temp.pl.level.name. I believe that's it, but I'm rather tired right now..

Imperialistic 07-28-2012 12:04 AM

Quote:

Originally Posted by Crow (Post 1700272)
I made some slight modifications. First, there's no reason to store stuff in variables if the referenced object doesn't even exist, so let's check that first. Next, both temp.pl and temp.pl.level are, in this case, objects. Nothing you should put into a string. Instead, let's use temp.pl.account and temp.pl.level.name. I believe that's it, but I'm rather tired right now..

Okay, so I was on the right track though right?

I still get really confused when it comes to variables/objects/strings, mostly because I don't know the actual definition and purpose of each one. I think I will read back over Jerret's and Twinny's GS2 guide and see if it helps.

Thanks Crow!


All times are GMT +2. The time now is 07:56 PM.

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