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
  #76  
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
  #77  
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
  #78  
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
  #79  
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
  #80  
Old 05-01-2009, 04:30 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
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.
__________________
Reply With Quote
  #81  
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
  #82  
Old 05-01-2009, 10:13 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by Raelyn View Post
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.
Reply With Quote
  #83  
Old 05-01-2009, 03:34 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 Pelikano View Post
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
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #84  
Old 05-01-2009, 04:04 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Raelyn View Post
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

__________________
Reply With Quote
  #85  
Old 05-01-2009, 04:31 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 Chompy View Post
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?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #86  
Old 05-01-2009, 04:51 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Raelyn View Post
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.
__________________
Reply With Quote
  #87  
Old 05-01-2009, 05:37 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 Chompy View Post
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?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #88  
Old 05-01-2009, 06:07 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #89  
Old 05-01-2009, 06:31 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 Stefan View Post
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.
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #90  
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 01:31 PM.


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