Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Raelyn's Big Book of Scripting Questions. (https://forums.graalonline.com/forums/showthread.php?t=85091)

Pelikano 04-29-2009 11:47 AM

People hate reading GS1 xD

Skyld 04-29-2009 12:37 PM

Quote:

Originally Posted by Raelyn (Post 1487541)
Because I don't know GS2 yet, and because I am silly? :)

Learn GScript2. Old GScript is not worth so much as a moment of your time, and basically, GScript2 is better in absolutely every way.

Codein 04-29-2009 01:43 PM

Quote:

Originally Posted by Skyld (Post 1487589)
Learn GScript2. Old GScript is not worth so much as a moment of your time, and basically, GScript2 is better in absolutely every way.

Agreed.

Raelyn 04-29-2009 01:51 PM

Quote:

Originally Posted by Pelikano (Post 1487585)
People hate reading GS1 xD

Well that's lame. :/

Do classes operate like global functions? Like, if I put all my functions into classes, I can call them up in any scripts on the server?

Chompy 04-29-2009 02:29 PM

Quote:

Originally Posted by Raelyn (Post 1487596)
Well that's lame. :/

Do classes operate like global functions? Like, if I put all my functions into classes, I can call them up in any scripts on the server?

You'd have to join that class to use it's content.

Lets say this is a class called fibonacci:

PHP Code:

function fib(n) {
  return (((
1+5^0.5)/2)^- ((1-5^0.5)/2)^n)/(5^0.5)



To use that function, I would have to do:

PHP Code:

function onCreated() {
  
join("fibonacci");

  echo(
fib(7)); // 13



Raelyn 04-29-2009 03:52 PM

Quote:

Originally Posted by Chompy (Post 1487600)
You'd have to join that class to use it's content.

Lets say this is a class called fibonacci:

PHP Code:

function fib(n) {
  return (((
1+5^0.5)/2)^- ((1-5^0.5)/2)^n)/(5^0.5)



To use that function, I would have to do:

PHP Code:

function onCreated() {
  
join("fibonacci");

  echo(
fib(7)); // 13



Ok, thanks.

Deas_Voice 04-29-2009 05:11 PM

one thing i always wondered when it comes to join(),
should i join it on serverside or clientside?
or even both?

Chompy 04-29-2009 05:19 PM

Quote:

Originally Posted by Deas_Voice (Post 1487613)
one thing i always wondered when it comes to join(),
should i join it on serverside or clientside?
or even both?

Depends on where you'll be using the class' content.

Deas_Voice 04-29-2009 05:42 PM

Quote:

Originally Posted by Chompy (Post 1487614)
Depends on where you'll be using the class' content.

both sides.
sometimes clientside or serverside.

napo_p2p 04-29-2009 07:25 PM

Quote:

Originally Posted by Deas_Voice (Post 1487616)
both sides.
sometimes clientside or serverside.

If you join it serverside, then both clientside and serverside parts of the class will work. If you join it clientisde, then only the clientside part of the class will work.

fowlplay4 04-29-2009 08:53 PM

I've noticed on the clientside if you join a class clientside you can't use the functions from the class right away.

ex:

PHP Code:

//class: whatever
//#CLIENTSIDE
function somefunc() {
  echo(
"!");


Then doing following..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("whatever");
  
somefunc(); // the somefunc in the class would not actually be called..
  
this.trigger("WildEvent"""); // so I would use a trigger..
}

function 
onWildEvent() {
  
somefunc(); // and ! would be displayed in F2



napo_p2p 04-29-2009 09:16 PM

Quote:

Originally Posted by fowlplay4 (Post 1487659)
I've noticed on the clientside if you join a class clientside you can't use the functions from the class right away.

ex:

PHP Code:

//class: whatever
//#CLIENTSIDE
function somefunc() {
  echo(
"!");


Then doing following..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("whatever");
  
somefunc(); // the somefunc in the class would not actually be called..
  
this.trigger("WildEvent"""); // so I would use a trigger..
}

function 
onWildEvent() {
  
somefunc(); // and ! would be displayed in F2



That's weird. Have you tried:
PHP Code:

whatever::somefunc(); 

??

cbk1994 04-29-2009 09:21 PM

It might take a minute to join, I've had trouble with that before as well.

fowlplay4 04-30-2009 12:28 AM

Quote:

Originally Posted by napo_p2p (Post 1487661)
That's weird. Have you tried:
PHP Code:

whatever::somefunc(); 

??

Just tried it, it only happens when you login/connect though, not when you update the script.

My above script didn't work with the trigger, however this worked fine and isn't noticable.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("whatever");
  
whatever::somefunc(); // the somefunc in the class would not actually be called..
  
this.scheduleevent(0.1"WildEvent"""); // so I would use a trigger..
}

function 
onWildEvent() {
  
somefunc(); // and ! would be displayed in F2


So I'd recommend joining serverside if you don't want to deal with the workaround above..

PHP Code:

function onCreated() {
  
join("whatever");
}
//#CLIENTSIDE
function onCreated() { 
  
somefunc(); // the somefunc in the class is called.



napo_p2p 04-30-2009 12:43 AM

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.

xXziroXx 04-30-2009 12:38 PM

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.

Raelyn 04-30-2009 08:26 PM

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?

napo_p2p 04-30-2009 08:51 PM

Quote:

Originally Posted by Raelyn (Post 1487919)
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.

Raelyn 04-30-2009 09:27 PM

Quote:

Originally Posted by napo_p2p (Post 1487929)
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?!

Raelyn 04-30-2009 09:35 PM

Quote:

Originally Posted by Chompy (Post 1487600)
You'd have to join that class to use it's content.

Lets say this is a class called fibonacci:

PHP Code:

function fib(n) {
  return (((
1+5^0.5)/2)^- ((1-5^0.5)/2)^n)/(5^0.5)



To use that function, I would have to do:

PHP Code:

function onCreated() {
  
join("fibonacci");

  echo(
fib(7)); // 13



Ok, so if I take all my functions from my base system script, and make the classes all functions, I can just go through and replace all the functions listed in the script with:

PHP Code:

function onCreated() {
join("class_name");


Is that right? What is the echo? And will GS1 and GS2 mix? It seems like they mix, but only that GS2 doesn't work offline.. is that right?

Raelyn 04-30-2009 09:42 PM

Quote:

Originally Posted by Deas_Voice (Post 1487613)
one thing i always wondered when it comes to join(),
should i join it on serverside or clientside?
or even both?

How do you designate one or the other?

cbk1994 04-30-2009 09:46 PM

Quote:

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?
Layers 4+ are screen layers.

"temp.i" is a variable, which is pointing to the image object. When you use 'showtext' or 'showimg', it returns the actual image created (can also be obtained through findImg(index)).

Which means you could even do like (though it's not a good idea)

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.msg showtext(2003030"Arial""b""hi");
}
function 
changeText(text) {
  
this.msg.text text;


Kinda odd the way you're doing it. I would do it either like this:

PHP Code:

with (findimg(200)) {
  
500;
  
500;
  
  
text "Hello, world!";
  
  
font "Arial"// not sure if this is the variable name, use /scripthelp
  
fontface "b"// see above line
  
  
layer 4;
  
  
red 1;
  
blue .5;
  
green .5;
  
  
alpha 1;


or

PHP Code:

showtext(200500500 "Arial""b""Hello, world!");
changeimgvis(2004);
changeimgcolors(2001.5.51); 

Either works, but the top one is probably preferred (though I could be wrong; the top one seems to agree with GS2 standards whereas the bottom is for compatibility).
Quote:

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?!
GS2 makes a lot more sense, and you'll understand it when you've been working with it longer.
Quote:

Originally Posted by Raelyn (Post 1487937)
Ok, so if I take all my functions from my base system script, and make the classes all functions, I can just go through and replace all the functions listed in the script with:

PHP Code:

function onCreated() {
join("class_name");


Is that right? What is the echo? And will GS1 and GS2 mix? It seems like they mix, but only that GS2 doesn't work offline.. is that right?

GS1 and GS2 can mix, but it's strongly discouraged.

echo(message) simply outputs the message to NC (or RC if you have the server option enabled), and since he's echoing a function, it will echo whatever that function returns.

And yes, you can take all the functions you want to be in a shared class from the individual scripts and put them in a class, then join that class.


Edit (in response to designating clientside/serverside):
PHP Code:

join("class"); // serverside
//#CLIENTSIDE
function onCreated() {
  
classFunctionThatWillAlreadyWork();


or

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("class"); // clientside (not a good idea)
  
classFunctionThatWillNotWorkBecauseOfDelaysAndWillReportAnErrorToF2(); // ;)



Raelyn 04-30-2009 09:52 PM

Ok, so I put the functions in classes, and uploaded the rest of the main script as a weapon, and this is the errors I got:

Quote:

Script: Function disableselectweapons not found at line 126 in script of -Player
Script: Function showstats not found at line 127 in script of -Player
Script: Callstack overrun at line 104 in script of -Player
So, disableselectweapons and showstats don't work online? And what is callstack overrun?

Chompy 04-30-2009 10:10 PM

Quote:

Originally Posted by Raelyn (Post 1487937)
Ok, so if I take all my functions from my base system script, and make the classes all functions, I can just go through and replace all the functions listed in the script with:

PHP Code:

function onCreated() {
join("class_name");


Is that right? What is the echo? And will GS1 and GS2 mix? It seems like they mix, but only that GS2 doesn't work offline.. is that right?

Well, echo() will output test into RC serverside, and into F2 clientside.

What join() do, is that it takes the content of the class (all the functions and such) and applies it to the script/object that is joining the class.

cbk1994 04-30-2009 10:18 PM

Quote:

Originally Posted by Raelyn (Post 1487946)
Ok, so I put the functions in classes, and uploaded the rest of the main script as a weapon, and this is the errors I got:



So, disableselectweapons and showstats don't work online? And what is callstack overrun?

As far as I know, callstack overrun means you're calling a function too many times, e.g.

PHP Code:

function onCreated() {
  
badLoop();
}
function 
badLoop() {
  
// bad loop stuff here
  
badLoop();


and no ... showstats an disableselectweapons are clientside, which means you need to do this in your system weapons:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
initStats();
}
function 
initStats() {
  
showstats(allstats whatever);
  
disableselectweapons();


though for disableselectweapons, it's better to use "enablefeatures" if you don't plan on ever enabling it.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
initStats();
}
function 
initStats() {
  
showstats(1024);
  
enablefeatures(allfeatures 4);


Here are the rest of the game features:

http://img404.imageshack.us/img404/2161/picture8h.png

napo_p2p 04-30-2009 10:22 PM

Quote:

Originally Posted by Raelyn (Post 1487946)
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).

cbk1994 04-30-2009 10:23 PM

Quote:

Originally Posted by napo_p2p (Post 1487958)
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.

Raelyn 04-30-2009 10:27 PM

Quote:

Originally Posted by cbk1994 (Post 1487942)
Layers 4+ are screen layers.

"temp.i" is a variable, which is pointing to the image object. When you use 'showtext' or 'showimg', it returns the actual image created (can also be obtained through findImg(index)).

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?

Quote:

Originally Posted by cbk1994 (Post 1487942)
Kinda odd the way you're doing it. I would do it either like this:

Heh, that was someone elses little snippet of code, like I said, I was trying to read/understand it, I actually did your suggestion below in MY script:

Quote:

Originally Posted by cbk1994 (Post 1487942)
PHP Code:

showtext(200500500 "Arial""b""Hello, world!");
changeimgvis(2004);
changeimgcolors(2001.5.51); 


Quote:

Originally Posted by cbk1994 (Post 1487942)
GS1 and GS2 can mix, but it's strongly discouraged.

Any specific reason? Functionally is bad? Or some "purist" idealism?


Quote:

Originally Posted by cbk1994 (Post 1487942)
echo(message) simply outputs the message to NC (or RC if you have the server option enabled), and since he's echoing a function, it will echo whatever that function returns.

So basically, it's not needed to join a class?

Quote:

Originally Posted by cbk1994 (Post 1487942)
Edit (in response to designating clientside/serverside):
PHP Code:

join("class"); // serverside
//#CLIENTSIDE
function onCreated() {
  
classFunctionThatWillAlreadyWork();



I thought anything behind // isn't read by the system, so how does tagging //serverside produce a difference in the code?

Raelyn 04-30-2009 10:29 PM

Quote:

Originally Posted by Chompy (Post 1487954)
Well, echo() will output test into RC serverside, and into F2 clientside.

What join() do, is that it takes the content of the class (all the functions and such) and applies it to the script/object that is joining the class.

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

Raelyn 04-30-2009 10:36 PM

Quote:

Originally Posted by napo_p2p (Post 1487958)
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

Raelyn 04-30-2009 10:52 PM

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?

cbk1994 04-30-2009 11:11 PM

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 (Post 1487960)
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 (Post 1487961)
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 (Post 1487963)
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 (Post 1487965)
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 


Raelyn 04-30-2009 11:56 PM

Quote:

Originally Posted by cbk1994 (Post 1487970)
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?

cbk1994 05-01-2009 12:35 AM

Quote:

Originally Posted by Raelyn (Post 1487981)
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;
  }



Raelyn 05-01-2009 01:00 AM

Quote:

Originally Posted by cbk1994 (Post 1487995)
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;
  }



Raelyn 05-01-2009 01:53 AM

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

cbk1994 05-01-2009 02:00 AM

Quote:

Originally Posted by Raelyn (Post 1488003)
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 (Post 1488030)
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.

Raelyn 05-01-2009 02:43 AM

Quote:

Originally Posted by cbk1994 (Post 1488032)
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 (Post 1488032)
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*

fowlplay4 05-01-2009 03:53 AM

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



cbk1994 05-01-2009 04:30 AM

Quote:

Originally Posted by Raelyn (Post 1488051)
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.



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*

GS1 requires that you use the string 'function' for strings to work, which is major failure.

PHP Code:

showimg(200clientr.weapon_img3030); 

You can't expect GS2 to work if you don't use it correctly.


All times are GMT +2. The time now is 03:52 AM.

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