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 05-19-2007, 02:11 AM
oinknessx oinknessx is offline
Banned
oinknessx's Avatar
Join Date: Apr 2004
Location: United States
Posts: 646
oinknessx is on a distinguished road
Send a message via AIM to oinknessx
Red face Help with && (and)

Hi guys. My learning of GScript2 is going pretty smooth, but now I'm stuck. I need to figure out how to do an AND.

In Gscript1, you could make it so if the player said something, and it equaled a certain thing, it would perform an action...

Can you guys tell me how to make the equivalent of an if (playerenters&&timeout) or if (playerchats&&strequals()) type deal? Just so I can have a function onPlayerChats&&stuff or whatnot.

Still trying to learn the basics of GS2. I appreciate the help.
Reply With Quote
  #2  
Old 05-19-2007, 02:14 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
You have to put the if inside the function:

PHP Code:
function onTimeout(){
onPlayerEnters();
}

function 
onPlayerChats() {
if (
player.chat == "foo") { 
//do whatever
}



edit: Using the newly implemented function pointers it may be possible to override the events, no idea if this is possible though, you'd be better off sticking with the above example.
PHP Code:
this.onPlayerEnters this.onTimeout
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #3  
Old 05-19-2007, 02:14 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Good question, I was also confused at first. The solution to your problem is using flags.

Examples:

GS2:
PHP Code:
function onPlayerChats()
{
  if (
player.chat == "pie")
  {
    
pie();
  }

GS1:
PHP Code:
if (playerchats&&strequals(#c,pie)){
  
pie();

Reply With Quote
  #4  
Old 05-19-2007, 03:01 AM
oinknessx oinknessx is offline
Banned
oinknessx's Avatar
Join Date: Apr 2004
Location: United States
Posts: 646
oinknessx is on a distinguished road
Send a message via AIM to oinknessx
Well that sort of makes sense. But Rapidwolve, after you have the function of pie(); being called to start, how do you say what the pie action actually is? Do you put it like,

function pie(){
//stuff
}

Is that right?

So to make a timeout, you would put

function onTimeout(){
onPlayerEnters();
}

So then that would equal if (playerenters&&timeout), but where exactly do you put the commands to be cycled within the timeout? Just below, anywhere? Like you guys did with the playerchats stuff?

I think I'm learning something!

I tried to incorporate what you guys are saying into a script, but the light effect is static and doesn't move. -_- What's wrong here?

PHP Code:
function onTimeout(){
onCreated();
}

function 
onCreated(){
  
setimgpart("lampanimation.gif",0,0,19,35);
  
dontblock();
  
setTimer(.1);
}

function 
onTimeout(){
  
showimg(1,light2.png,x-3,y-3);
  
changeimgcolors(1,1,0.4,0,0.8);
  
changeimgzoom(1,random(.8,1));
  
setTimer(.1);

Reply With Quote
  #5  
Old 05-19-2007, 03:06 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by oinknessx View Post
Well that sort of makes sense. But Rapidwolve, after you have the function of pie(); being called to start, how do you say what the pie action actually is? Do you put it like,

function pie(){
//stuff
}

Is that right?
Yes.

Quote:
Originally Posted by oinknessx View Post
So to make a timeout, you would put

function onTimeout(){
onPlayerEnters();
}
Not neccesarily, that would just keep calling onPlayerEnters() every 'n' seconds (depending on the timer, set using setTimer(float)). Something to emulate that is:
PHP Code:
function onPlayerEnters()
{
  if (
this.timeout)
  {
        
//
  
}

Reply With Quote
  #6  
Old 05-19-2007, 03:14 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by oinknessx View Post
I tried to incorporate what you guys are saying into a script, but the light effect is static and doesn't move. -_- What's wrong here?

PHP Code:
function onTimeout(){
onCreated();
}

function 
onCreated(){
  
setimgpart("lampanimation.gif",0,0,19,35);
  
dontblock();
  
setTimer(.1);
}

function 
onTimeout(){
  
showimg(1,light2.png,x-3,y-3);
  
changeimgcolors(1,1,0.4,0,0.8);
  
changeimgzoom(1,random(.8,1));
  
setTimer(.1);

Well first of all your defining onTimeout() twice, setTimer() automatically the onTimeout event. And if you want the light to be moving, you need to have a constantly changing x/y value. (x/y - 3) stays the same
Reply With Quote
  #7  
Old 05-19-2007, 03:24 AM
oinknessx oinknessx is offline
Banned
oinknessx's Avatar
Join Date: Apr 2004
Location: United States
Posts: 646
oinknessx is on a distinguished road
Send a message via AIM to oinknessx
Well I didn't really mean moving, I meant zooming. It's supposed to zoom randomly between .8 and 1.. Not too big of a change I suppose, but it makes a little flicker and looks better than just a still light.

Also edit, here's what I cooked up after your function PIE comment, and also I took the randomly zooming part out. This seems to be a stable lamp script apart from not zooming...

PHP Code:
// NPC Created by Oinkness

function onTimeout(){
DoLamp();
}

function 
onCreated(){
  
setimgpart("lampanimation.gif",0,0,19,35);
  
dontblock();
  
setTimer(.5);
}

function 
DoLamp(){
  
showimg(1,"light2.png",x-3,y-3);
  
changeimgcolors(1,1,0.4,0,0.4);
  
changeimgzoom(1,2);

It works, but are there errors? And how exactly would I incorporate the random zoom within the changeimgzoom section?

Wait, there's no need for //#CLIENTSIDE? I thought I'd forgot it but it kills the script if I put it in.

Last edited by oinknessx; 05-19-2007 at 03:40 AM..
Reply With Quote
  #8  
Old 05-19-2007, 04:40 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Hold on before you do anything else, add setTimer(.5) inside the onTimeout event function.
PHP Code:
function onTimeout()
{
  
DoLamp();
  
setTimer(0.5);

Reply With Quote
  #9  
Old 05-19-2007, 05:37 AM
oinknessx oinknessx is offline
Banned
oinknessx's Avatar
Join Date: Apr 2004
Location: United States
Posts: 646
oinknessx is on a distinguished road
Send a message via AIM to oinknessx
Ok, I fixed the spot where that timer command was set. Thanks. I guess I can deal with it not being a randomized zoom.

Another thing I'm planning to try to script is a music system that changes the theme depending on what level you're in. I am way too newb to script a crescendo movement for the volume, so I'll basically just have hard-edged changes... In GS1, I think it would appear something as such, but I think you need a tokenize or something to chop the filename... Asterisks don't work?...

PHP Code:
if (playerenters&&strequals(#f,lots_ow*.nw)){
play lots_owtheme.mid;
}

if (
playerenters&&strequals(#f,lots_house*.nw)){
play lots_housetheme.mid;

I'm fairly certain you will say that this script is wrong, even in GS1... It eludes me how to make this pretty simple system in GS2. o_o
Reply With Quote
  #10  
Old 05-19-2007, 01:46 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by oinknessx View Post
Ok, I fixed the spot where that timer command was set. Thanks. I guess I can deal with it not being a randomized zoom.
No, no, add the zoom back it will work now we've fixed the timeout
Reply With Quote
  #11  
Old 05-22-2007, 10:40 PM
oinknessx oinknessx is offline
Banned
oinknessx's Avatar
Join Date: Apr 2004
Location: United States
Posts: 646
oinknessx is on a distinguished road
Send a message via AIM to oinknessx
Well what you said to do ended up killing the lamp. :-\

PHP Code:
function onTimeout(){
  
DoLamp();
  
setTimer(0.5);
}

function 
onCreated(){
  
setimgpart("lampanimation.gif",0,0,19,35);
  
dontblock();
}

function 
onPlayerEnters(){
onCreated();
}

function 
DoLamp(){
  
showimg(1,"light2.png",x-3,y-3);
  
changeimgcolors(1,1,0.4,0,0.4);
  
changeimgzoom(1,random(.8,1.4)); 
  
changeimgvis(1,3);

Reply With Quote
  #12  
Old 05-23-2007, 11:39 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 oinknessx View Post
Well what you said to do ended up killing the lamp. :-\

PHP Code:
function onTimeout(){
  
DoLamp();
  
setTimer(0.5);
}

function 
onCreated(){
  
setimgpart("lampanimation.gif",0,0,19,35);
  
dontblock();
}

function 
onPlayerEnters(){
onCreated();
}

function 
DoLamp(){
  
showimg(1,"light2.png",x-3,y-3);
  
changeimgcolors(1,1,0.4,0,0.4);
  
changeimgzoom(1,random(.8,1.4)); 
  
changeimgvis(1,3);

PHP Code:
function onCreated()
{
  
setImgPart"lampanimation.gif"001935 );
  
dontBlock();
  
setTimer.5 );
}
function 
onTimeOut()
{
  
showLamp();
  
setTimer.5 );
}
function 
showLamp()
{
  
showimg1"light2.png", [b]this.[/b]3, [b]this.[/b]);
  
changeimgcolors110.400.4 );
  
changeimgzoom1random.81.4 ) ); 
  
changeimgvis1);

__________________
Reply With Quote
  #13  
Old 05-23-2007, 11:47 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Rapidwolve View Post
Good question, I was also confused at first. The solution to your problem is using flags.

Examples:

GS2:
PHP Code:
function onPlayerChats()
{
  if (
player.chat == "pie")
  {
    
pie();
  }

Me learn this:

PHP Code:
function onPlayerChats () {
  if (
player.chat == "poopy scoopy") {
    
//stuffz0r!;
  
}

__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
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 06:58 PM.


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