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, 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
  #2  
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
  #3  
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
  #4  
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
  #5  
Old 05-01-2009, 01:53 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Ugh, I don't know how else to do this.

I want the weapon icon to be displayed dependant on the type of weapon equipped, so..

PHP Code:

if (clientr.weapon 0001;){
   
clientr.weapon_img weaponicon.png;
}

showimg indexclientr.weapon_img,,,; 
I would assume this would basically do the same as:

PHP Code:
showimg indexweaponicon.png,,,; 
but it's not doing that at all, I'm confused...
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #6  
Old 05-01-2009, 02:00 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
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,,,;

Use:

PHP Code:
clientr.weapon_img "weaponname.png"
for strings

Quote:
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,);

onKeyPressed is called on default. Basically all of the event if's were converted to "function onEvent", such as "onPlayerTouchsMe", "onCreated", and "onPlayerEnters". There's no need for the if (keypressed) statement.

Quote:
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;
  }

hideimg might be actually destroying the image (actually, I'm pretty sure it does). Just hide it with findImg().visible. And, I don't think showimg has that many paramaters.

Plus.... you're combining GS1 and GS2 in a horrible way

Quote:
Originally Posted by Raelyn View Post
Ugh, I don't know how else to do this.

I want the weapon icon to be displayed dependant on the type of weapon equipped, so..

PHP Code:

if (clientr.weapon 0001;){
   
clientr.weapon_img weaponicon.png;
}

showimg indexclientr.weapon_img,,,; 
Something like this I guess...

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.wep_type.sword "sword.png";
}
function 
displayImage() {
  
showimg(200getImageForType(clientr.weaponType), 00);
}
function 
getImageForType(wep) {
  return 
this.wep_type.(@ wep);

and just set clientr.weaponType or another variable when you change the player's weapon. Also, there's really no reason to use clientr. for a weapon image.

And, I'm pretty sure you're adding an extra parameter to showimg almost everywhere. Press F2 and click on "Scripts", it may be giving an error.
__________________
Reply With Quote
  #7  
Old 05-01-2009, 02:43 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
Use:

PHP Code:
clientr.weapon_img "weaponname.png"
for strings


onKeyPressed is called on default. Basically all of the event if's were converted to "function onEvent", such as "onPlayerTouchsMe", "onCreated", and "onPlayerEnters". There's no need for the if (keypressed) statement.



hideimg might be actually destroying the image (actually, I'm pretty sure it does). Just hide it with findImg().visible. And, I don't think showimg has that many paramaters.

Plus.... you're combining GS1 and GS2 in a horrible way


Something like this I guess...

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.wep_type.sword "sword.png";
}
function 
displayImage() {
  
showimg(200getImageForType(clientr.weaponType), 00);
}
function 
getImageForType(wep) {
  return 
this.wep_type.(@ wep);

and just set clientr.weaponType or another variable when you change the player's weapon. Also, there's really no reason to use clientr. for a weapon image.

And, I'm pretty sure you're adding an extra parameter to showimg almost everywhere. Press F2 and click on "Scripts", it may be giving an error.
Ahh thanks. And yea, I am not adding an extra parameter in the actual scripts, just mashing the comma here to represent that parameters DO follow.

Quote:
Originally Posted by cbk1994 View Post
Use:

PHP Code:
clientr.weapon_img "weaponname.png"
for strings
I did this:

PHP Code:
clientr.weapon_img "raelyn_sword.png";

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

Still not producing an image.

Edit: Bah, I got it to work with #s.

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

Last edited by Raelyn; 05-01-2009 at 02:49 AM.. Reason: Doh!
Reply With Quote
  #8  
Old 05-03-2009, 12:41 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
onKeyPressed is called on default. Basically all of the event if's were converted to "function onEvent", such as "onPlayerTouchsMe", "onCreated", and "onPlayerEnters". There's no need for the if (keypressed) statement.
Ok, sorry to ask this again, but I am still having problems with this.. I am trying to use the GS2 solution and it's not working (I'm probably doing it wrong.)

Here is what I got..

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

I have a function doing showimg 209, and trying to use the code snippet you suggested on key i, the image remains shown, and is not hid, as expected.

Is there a way in GS1 to do this?

PHP Code:
if (keypressed) {
   if (
strequals(#p(1),I)){
      
if (img 209 is visible){
         
hideimg 209;
      } else {
         
showimg 209,file,x,y;
      }
   }

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

Last edited by Raelyn; 05-03-2009 at 02:05 PM..
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 08:15 AM.


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