Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Help with && (and) (https://forums.graalonline.com/forums/showthread.php?t=74050)

oinknessx 05-19-2007 02:11 AM

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

JkWhoSaysNi 05-19-2007 02:14 AM

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


Rapidwolve 05-19-2007 02:14 AM

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();



oinknessx 05-19-2007 03:01 AM

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! :D

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



Rapidwolve 05-19-2007 03:06 AM

Quote:

Originally Posted by oinknessx (Post 1309323)
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 (Post 1309323)
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)
  {
        
//
  
}



Rapidwolve 05-19-2007 03:14 AM

Quote:

Originally Posted by oinknessx (Post 1309323)
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

oinknessx 05-19-2007 03:24 AM

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.

Rapidwolve 05-19-2007 04:40 AM

Hold on before you do anything else, add setTimer(.5) inside the onTimeout event function.
PHP Code:

function onTimeout()
{
  
DoLamp();
  
setTimer(0.5);



oinknessx 05-19-2007 05:37 AM

Ok, I fixed the spot where that timer command was set. Thanks. :D 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

Rapidwolve 05-19-2007 01:46 PM

Quote:

Originally Posted by oinknessx (Post 1309403)
Ok, I fixed the spot where that timer command was set. Thanks. :D 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

oinknessx 05-22-2007 10:40 PM

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



cbk1994 05-23-2007 11:39 PM

Quote:

Originally Posted by oinknessx (Post 1310795)
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);



Switch 05-23-2007 11:47 PM

Quote:

Originally Posted by Rapidwolve (Post 1309298)
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!;
  
}




All times are GMT +2. The time now is 11:29 PM.

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