Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-30-2009, 10:22 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Raelyn View Post
So, disableselectweapons and showstats don't work online? And what is callstack overrun?
disableselectweapons and showstats are clientside only functions. They affect the player only. It looks like you need to run the code clientside. Put //#CLIENTSIDE at the top of your scripts.

The callstack overrun happens when your script is executing too many functions too quickly. It'll probably go away if you switch the script over to clientside. (I bet you have a 0.05 timeout, which is too much for the server to handle).
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #2  
Old 04-30-2009, 10:23 PM
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 napo_p2p View Post
disableselectweapons and showstats are clientside only functions. They affect the player only. It looks like you need to run the code clientside. Put //#CLIENTSIDE at the top of your scripts.

The callstack overrun happens when your script is executing too many functions too quickly. It'll probably go away if you switch the script over to clientside. (I bet you have a 0.05 timeout, which is too much for the server to handle).
Timeouts faster than a tenth of a second are automagically changed to .1 on serverside.

And yeah, I didn't think about the fact that //#CLIENTSIDE isn't required in the level editor for clientside scripts. Good catch.
__________________
Reply With Quote
  #3  
Old 04-30-2009, 10:36 PM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by napo_p2p View Post
disableselectweapons and showstats are clientside only functions. They affect the player only. It looks like you need to run the code clientside. Put //#CLIENTSIDE at the top of your scripts.

The callstack overrun happens when your script is executing too many functions too quickly. It'll probably go away if you switch the script over to clientside. (I bet you have a 0.05 timeout, which is too much for the server to handle).
Inserting //#CLIENTSIDE at the top seems to have removed the errors. Thanks. But now won't my player's stats be vulnerable to cheap string editng kiddies? :P
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #4  
Old 04-30-2009, 12:43 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
You know, now that I think of it, it's requesting the script from the server when you call join(), which results in a small delay.

So, yea. It's easiest just to do all joins serverside.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #5  
Old 04-30-2009, 12:38 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Jerret, you're actually missing something.

It's not being updated on clientside when you join it clientsided, true. But it's also not updated clientsided if you join it serversided. Note that sometimes both works, sometimes they don't - and when it doesn't work, it's updated if you reconnect with your client.

This is why I never "release" an updated clientsided class before manually reconnecting all current clients to ensure that they all got the update.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #6  
Old 04-30-2009, 08:26 PM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Ok, maybe I should ask this differently.. I wrote these scripts in GS1, but now I want to put them on my server, so can they be converted to GS2 easier with syntax changes? Or do I have to re-write them entirely?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #7  
Old 04-30-2009, 08:51 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Raelyn View Post
Ok, maybe I should ask this differently.. I wrote these scripts in GS1, but now I want to put them on my server, so can they be converted to GS2 easier with syntax changes? Or do I have to re-write them entirely?
You might get away with just putting the GS1 script up, but it's good practice to use only GS2 online.

You can mostly go line-by-line and make a direct change from GS1->GS2.

If you haven't checked it out already:
http://wiki.graal.net/index.php/Creation/Dev/GS1_To_GS2

That article gives a pretty good overview of the types of changes you need to make.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #8  
Old 04-30-2009, 09:27 PM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by napo_p2p View Post
You might get away with just putting the GS1 script up, but it's good practice to use only GS2 online.

You can mostly go line-by-line and make a direct change from GS1->GS2.

If you haven't checked it out already:
http://wiki.graal.net/index.php/Creation/Dev/GS1_To_GS2

That article gives a pretty good overview of the types of changes you need to make.
Ok, well for displaying showtext I presume this is the GS2 equivalent of what I have done for my hud.

PHP Code:
function onCreated() {
  
temp.= {55};
  
  
temp.txt "HP:" clientr.player_hp "/" clientr.player_hpmax;
  
temp.showtext(200temp.p[0], temp.p[1], "Arial""b"temp.txt);
  
temp.i.layer 4;

  
temp.txt "MP:" clientr.player_mp "/" clientr.player_mpmax;
  
temp.showtext(201temp.p[0], temp.p[1] + 20"Arial""b"temp.txt);
  
temp.i.layer 4;

As far as I can tell, this works the same, but I don't understand "temp.p" and "temp.i", "temp.i.layer". I presume temp.i.layer is the same as changeimgvis, but what I don't understand is why the text being on layer 4 works, when I thought only 5 and up works for the screen instead of the playing field?

This script is something another scripter made/posted on my RC and I'm trying to learn off it and/or convert it to match what I have done in GS1, since it seems nearly identical but with strange syntax differences.

This really confuses me as to why everyone says "GS2 is easier to understand" or "GS2 makes more sense" because GS1 makes sense to me, but looking at this stuff, I am like.. what?!
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #9  
Old 04-30-2009, 10:52 PM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Ok, so I have inserted my baddy script into a class, if I wanted to place baddies on the map with the baddie class as their script, would I be able to do something like a weapon with a trigger and some sort of putnpc script referencing back to the class? How would I do that serverside? I want the baddie to be seen the same by all players... would putnpc work with a class?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #10  
Old 04-30-2009, 11:11 PM
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
These wiki pages should help you a bit with your understanding of clientside/serverside:
http://wiki.graal.net/index.php/Clientside
http://wiki.graal.net/index.php/Serverside
http://www.graal.net/index.php/Creat...Starting_Guide
http://wiki.graal.net/index.php/Crea.../Script/Client (explains how to communicate between serverside and clientside)

Quote:
Originally Posted by Raelyn View Post
This confuses the piss out of me, doesn't it just make more sense to reference the index directly than to try calling a variable pointing to the index?
What?
Quote:
Any specific reason? Functionally is bad? Or some "purist" idealism?
Not sure exactly, but Stefan said at several times not to, so that suggests to me that perhaps he checks what the script is in and decides how to parse it or something like that could be added later.

And yeah, GS1 just uglifies a beautiful script. GS2 is also considerably more efficient than GS1.
Quote:
So basically, it's not needed to join a class?
Haha yes, correct.
Quote:
I thought anything behind // isn't read by the system, so how does tagging //serverside produce a difference in the code?
It doesn't, the only time the parser reads anything that starts with "//" is when it is //#CLIENTSIDE. The ones I placed after the join were just labels.
Quote:
Originally Posted by Raelyn View Post
Ok, so join() works like putnpc, but it called from a class instead of a text file, and inserts all commands in the class in order below the join() command.. Gotcha..
You should always use putnpc2 now anyway; just put the code in a class rather than a text file.
Quote:
Originally Posted by Raelyn View Post
Inserting //#CLIENTSIDE at the top seems to have removed the errors. Thanks. But now won't my player's stats be vulnerable to cheap string editng kiddies? :P
Only if you used 'client.' vars. You should always use clientr (or serverside player. vars) for storing sensitive information.
Quote:
Originally Posted by Raelyn View Post
Ok, so I have inserted my baddy script into a class, if I wanted to place baddies on the map with the baddie class as their script, would I be able to do something like a weapon with a trigger and some sort of putnpc script referencing back to the class? How would I do that serverside? I want the baddie to be seen the same by all players... would putnpc work with a class?
If you want them to be dynamic (randomly placed), you should use a database NPC with something like the following

PHP Code:
function onCreated() {
  
// init vars
  
this.mapSize = {33}; // width, height in levels
  
this.classesToDrop = {"baddy"};
  
  
onTimeOut();
}
function 
onTimeOut() {
  
temp.tries 0;
  
  while (
tries ) {
    
temp.dpos = {random(0this.mapSize[0] * 64), random(0this.mapSize[1] * 64)};
    
    if (! 
onwall2(dpos[0] - 3dpos[1] - 366)) {
      
// should improve the above checks, it's just an example.
      
temp.classToJoin this.classesToDrop[int(random(0this.classesToDrop.size()))];
      
      
temp.drop putnpc2(dpos[0], dpos[1], "");
      
drop.join(classToJoin);
    }
    
tries ++;
  }
  
  
setTimer(360); // could also add a way to check how many baddies there are.

Otherwise, if you want them in static locations, just make a level NPC (with level editor) with this:

PHP Code:
join("baddy"); // or the other class 
__________________
Reply With Quote
  #11  
Old 04-30-2009, 11:56 PM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
These wiki pages should help you a bit with your understanding of clientside/serverside:
http://wiki.graal.net/index.php/Clientside
http://wiki.graal.net/index.php/Serverside
http://www.graal.net/index.php/Creat...Starting_Guide
http://wiki.graal.net/index.php/Crea.../Script/Client (explains how to communicate between serverside and clientside)


What?

Not sure exactly, but Stefan said at several times not to, so that suggests to me that perhaps he checks what the script is in and decides how to parse it or something like that could be added later.

And yeah, GS1 just uglifies a beautiful script. GS2 is also considerably more efficient than GS1.

Haha yes, correct.

It doesn't, the only time the parser reads anything that starts with "//" is when it is //#CLIENTSIDE. The ones I placed after the join were just labels.

You should always use putnpc2 now anyway; just put the code in a class rather than a text file.

Only if you used 'client.' vars. You should always use clientr (or serverside player. vars) for storing sensitive information.

If you want them to be dynamic (randomly placed), you should use a database NPC with something like the following

PHP Code:
function onCreated() {
  
// init vars
  
this.mapSize = {33}; // width, height in levels
  
this.classesToDrop = {"baddy"};
  
  
onTimeOut();
}
function 
onTimeOut() {
  
temp.tries 0;
  
  while (
tries ) {
    
temp.dpos = {random(0this.mapSize[0] * 64), random(0this.mapSize[1] * 64)};
    
    if (! 
onwall2(dpos[0] - 3dpos[1] - 366)) {
      
// should improve the above checks, it's just an example.
      
temp.classToJoin this.classesToDrop[int(random(0this.classesToDrop.size()))];
      
      
temp.drop putnpc2(dpos[0], dpos[1], "");
      
drop.join(classToJoin);
    }
    
tries ++;
  }
  
  
setTimer(360); // could also add a way to check how many baddies there are.

Otherwise, if you want them in static locations, just make a level NPC (with level editor) with this:

PHP Code:
join("baddy"); // or the other class 
Ok, I used clientr. not sure why, but that's what I saw everyone else using so I thought it appropriate to follow suit, what is the difference between clientr. and player. ?

I will have to lookup putnpc2 since I have never used it.

Also, if I wanted to do something like a toggle, say:

PHP Code:
if (keypressed){
   if (
strequals()){
      if (
showimgIsAlreadyShown){
         
hideimg;
      } else {
         
showimg;
      }
   }

How would I detect if said image is shown already?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #12  
Old 05-01-2009, 12:35 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 Raelyn View Post
Ok, I used clientr. not sure why, but that's what I saw everyone else using so I thought it appropriate to follow suit, what is the difference between clientr. and player. ?
clientr. can only be changed serverside, so you'll have to change your existing code. clientr. vars can be read clientside, though.

player.vars can be added serverside or clientside (and changed), but there are some disadvantages (and advantages).

For serverside, you can add a player.var. This is not synchronized with clientside. For example, "player.staffLevel = 4".

On clientside, you can use it for storing objects or something. However, they are cleared when the player logs off. You can do stuff like "player.equippedItem = this" for equipping standard weapons.

Quote:
I will have to lookup putnpc2 since I have never used it.
Just use it like

PHP Code:
putnpc2(xyscript);

// You can also do

putnpc2(3232"join block;");

// but that's GS1 and poor scripting
// instead, you can use GS2

putnpc2(3232"join(\"block\");");

// but that's a mess and hard to read
// which is why I prefer to do

temp.npc putnpc2(3232"");
npc.join("block");

// and it's also easier to set attributes this way, such as

npc.spawned true
Quote:
Also, if I wanted to do something like a toggle, say:

PHP Code:
if (keypressed){
   if (
strequals()){
      if (
showimgIsAlreadyShown){
         
hideimg;
      } else {
         
showimg;
      }
   }

How would I detect if said image is shown already?
Try this:

PHP Code:
function onKeyPressed(codekeychar) {
  if (
key == "p") {
    
temp.img findImg(200);
    
img.visible = ! img.visible;
  }

__________________
Reply With Quote
  #13  
Old 05-01-2009, 01:00 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
clientr. can only be changed serverside, so you'll have to change your existing code. clientr. vars can be read clientside, though.

player.vars can be added serverside or clientside (and changed), but there are some disadvantages (and advantages).

For serverside, you can add a player.var. This is not synchronized with clientside. For example, "player.staffLevel = 4".

On clientside, you can use it for storing objects or something. However, they are cleared when the player logs off. You can do stuff like "player.equippedItem = this" for equipping standard weapons.


Just use it like

PHP Code:
putnpc2(xyscript);

// You can also do

putnpc2(3232"join block;");

// but that's GS1 and poor scripting
// instead, you can use GS2

putnpc2(3232"join(\"block\");");

// but that's a mess and hard to read
// which is why I prefer to do

temp.npc putnpc2(3232"");
npc.join("block");

// and it's also easier to set attributes this way, such as

npc.spawned true

Try this:

PHP Code:
function onKeyPressed(codekeychar) {
  if (
key == "p") {
    
temp.img findImg(200);
    
img.visible = ! img.visible;
  }

Awesome.

Another thing, I was under the impression that variable type is automatically detected, but it seems like setting a variable to a string of text doesn't work?

Trying to do something like this:

PHP Code:
clientr.weapon_img weaponname.png;

if (
trigger){
   
showimg index,clientr.weapon_img,,,;

Also, I tried using:

PHP Code:
function onKeyPressed(codekeychar) {
  if (
key == "p") {
    
temp.img findImg(200);
    
img.visible = ! img.visible;
  }

Not sure how to implement this, as a function, isn't it redundant to do this?:

PHP Code:
if (keypressed){
  
onKeyPressed(,p,);

Hrrm, am I doing this properly?


Doesn't this work?

PHP Code:
showimg 200,imagename.png,,,;
hideimg 200;

if (
keypressed) {
  if (
strequals(#p(1),p)) {
    
temp.img findImg(200);
    
img.visible = ! img.visible;
  }

__________________
*Don't let the door hit you on the way out.*

Last edited by Raelyn; 05-01-2009 at 01:29 AM.. Reason: Ohsnap, another edit.
Reply With Quote
  #14  
Old 05-01-2009, 03:53 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You can use GS2 now! Don't be a slave to GS1 conventions.

PHP Code:
function onTrigger() {
  
with (findimg(index)) {
     
image clientr.weapon_img;
     
thiso.x;
     
thiso.y;
  }

__________________
Quote:
Reply With Quote
  #15  
Old 05-01-2009, 06:26 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
You can use GS2 now! Don't be a slave to GS1 conventions.

PHP Code:
function onTrigger() {
  
with (findimg(index)) {
     
image clientr.weapon_img;
     
thiso.x;
     
thiso.y;
  }

The thing I don't understand is that this looks like it is outlining a function... so if I made function onTrigger(), how would I call it? Just with onTrigger();?
__________________
*Don't let the door hit you on the way out.*
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:08 AM.


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