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)

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.

Raelyn 05-01-2009 06:26 AM

Quote:

Originally Posted by fowlplay4 (Post 1488079)
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();?

Pelikano 05-01-2009 10:13 AM

Quote:

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

Why don't you try it before asking :o?

And yes, onTrigger() would call it.

Raelyn 05-01-2009 03:34 PM

Quote:

Originally Posted by Pelikano (Post 1488112)
Why don't you try it before asking :o?

And yes, onTrigger() would call it.

Well, I did.. I believe I posted it.

I tried to do

PHP Code:

function onTrigger(){
}

if 
onTrigger(){


Which doesn't look right to me. o.o

Chompy 05-01-2009 04:04 PM

Quote:

Originally Posted by Raelyn (Post 1488148)
Well, I did.. I believe I posted it.

I tried to do

PHP Code:

function onTrigger(){
}

if 
onTrigger(){


Which doesn't look right to me. o.o

Well,

PHP Code:

function onCreated() {
  
onTrigger();
}

function 
onTrigger() {
  
// do stuff



Raelyn 05-01-2009 04:31 PM

Quote:

Originally Posted by Chompy (Post 1488154)
Well,

PHP Code:

function onCreated() {
  
onTrigger();
}

function 
onTrigger() {
  
// do stuff



See, that confuses me, so there is no need to designate functions anymore? Or, alternatively, there is no need to set up triggers? The function itself is a trigger?

So instead of writing:

PHP Code:


function ThisStuff(){
  
stuff;
}

if (
trigger){
  
ThisStuff();


I can just do:

PHP Code:

function onThisStuffTrigger(){
  
stuff;


and it would act the same?

Chompy 05-01-2009 04:51 PM

Quote:

Originally Posted by Raelyn (Post 1488159)
See, that confuses me, so there is no need to designate functions anymore? Or, alternatively, there is no need to set up triggers? The function itself is a trigger?

So instead of writing:

PHP Code:


function ThisStuff(){
  
stuff;
}

if (
trigger){
  
ThisStuff();


I can just do:

PHP Code:

function onThisStuffTrigger(){
  
stuff;


and it would act the same?

Well, no.

PHP Code:

// This is an event that occurs when the WNPC is updated
function onCreated() {
  
this.string "foo";
}

function 
onTrigger() {
  
this.string "bar";


Since onTrigger() isn't triggered, this.string will be "foo"

However,

PHP Code:

function onCreated() {
  
this.string "foo";

  
onTrigger();
}

function 
onTrigger() {
  
this.string "bar";


Would now make this.string equal "bar" since the function is triggered.

Raelyn 05-01-2009 05:37 PM

Quote:

Originally Posted by Chompy (Post 1488166)
Well, no.

PHP Code:

// This is an event that occurs when the WNPC is updated
function onCreated() {
  
this.string "foo";
}

function 
onTrigger() {
  
this.string "bar";


Since onTrigger() isn't triggered, this.string will be "foo"

However,

PHP Code:

function onCreated() {
  
this.string "foo";

  
onTrigger();
}

function 
onTrigger() {
  
this.string "bar";


Would now make this.string equal "bar" since the function is triggered.

So I write functions like normal basically in GS1, but to call a trigger, I have to make a function... also?

So, creating the function onCreated() basically itself is a trigger, so you have to use that trigger to initialize all other triggers?

Admins 05-01-2009 06:07 PM

The function onCreated() will automatically be called when the "created" event is triggered by the engine.

Object1 triggers an event on Object2 -> onEvent() in the script of Object2 is called
Object1 can be the engine.

This is working exactly the same in GS1 as in GS2, just looking different:
instead of if (trigger) you write onTrigger(). In GS1 it was actually scanning for "if (trigger)" and was trying to only call that part of the script when the event was triggered.

Raelyn 05-01-2009 06:31 PM

Quote:

Originally Posted by Stefan (Post 1488191)
The function onCreated() will automatically be called when the "created" event is triggered by the engine.

Object1 triggers an event on Object2 -> onEvent() in the script of Object2 is called
Object1 can be the engine.

This is working exactly the same in GS1 as in GS2, just looking different:
instead of if (trigger) you write onTrigger(). In GS1 it was actually scanning for "if (trigger)" and was trying to only call that part of the script when the event was triggered.

I see. :)

Raelyn 05-03-2009 12:41 PM

Quote:

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




All times are GMT +2. The time now is 01:23 AM.

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