Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   gs2 obstacles (https://forums.graalonline.com/forums/showthread.php?t=61726)

prozac424242 10-13-2005 06:12 PM

gs2 obstacles
 
I am getting the hang of gs2, but there are a couple of situations that I have not been able to find a way around.

(all examples //#CLIENTSIDEd)

Old gscript : you can check for created and playerenters in one line
NPC Code:

if (created || playerenters)
{
loadmap mymap; // or whatever;
}



but how do you check for multiple events with gs2 other than this cumbersome repetition?
NPC Code:

function onCreated()
{
loadmap mymap;
}

function onPlayerenters()
{
loadmap mymap;
}




Also, how do you have two separate timeout loops in one npc that operate intependently depending on a boolean flag (variable that is 1 or 0)

Old gscript example
NPC Code:

if (created)
{
this.on=0;
timeout=.05;
}

if (timeout && this.on==0)
{
if (event happens like a keydown to switch flag to the other loop)
{
this.on=1;
}
timeout=.05;
}

if (timeout && this.on==1)
{
if (event like a different keydown to switch to the initial loop)
{
this.on=0;
}
timeout=.05;
}



This script woked fine, and then it was unchanged when my server was switched to gscript2, then it did not function in switching to the second timeout loop.
I tried switching it to gscript2, even changing the flag to a client.string and breaking the timeout loops into two separate npcs and it still did not work.
Why not???

example of gs2
NPC Code:

function onCreated()
{
this.on=0;
timeout=.05;
}

function onTimeout()
{
if (this.on==0)
{
if (keydown event triggered)
{
this.on=1;
}
}

if (this.on==1)
{
if (keydown event triggered)
{
this.on=0;
}
}
timeout=.05;
}



I also tried it with 2 separate timeout loops

NPC Code:

function onCreated()
{
this.on=0;
timeout=.05;
}

function onTimeout()
{
if (this.on==0)
{
if (keydown event triggered)
{
this.on=1;
}
}
timeout=.05;
}

function onTimeout()
{
if (this.on==1)
{
if (keydown event triggered)
{
this.on=0;
}
}
timeout=.05;
}




and neither one of those worked ... what am I doing wrong???
the first timeout is to see if an "on" key is pressed and to hide images,
The second timeout is to show the images and allow the image positions to be changed through a function if other keys are pressed, and to see if the "off" key is pressed.

Any help would be appreciated

Silent 10-13-2005 07:06 PM

Quote:

Originally Posted by prozac424242
NPC Code:

if (created || playerenters)
{
loadmap mymap; // or whatever;
}



but how do you check for multiple events with gs2 other than this cumbersome repetition?

PHP Code:

function onCreated () {
  
doloadmap();
}

function 
onPlayerenters() {
  
doloadmap();
}

function 
doloadmap() {
  
loadmap("mymap");


I hope this isn't a literal example though - you only need to load the map once

napo_p2p 10-13-2005 07:19 PM

Quote:

Originally Posted by Silent
PHP Code:

function onCreated () {
  
doloadmap();
}

function 
onPlayerenters() {
  
doloadmap();
}

function 
doloadmap() {
  
loadmap("mymap");


I hope this isn't a literal example though - you only need to load the map once

Can also try something like:
PHP Code:

function onCreated()
{
  
loadMap("myMap");
}

function 
onPlayerEnters()
{
  
onCreated();


As for the timeouts, those aren't really 'loops', as you don't have 'timeout = 0.05;' or setTimer(0.05);

prozac424242 10-13-2005 07:46 PM

oops - forgot to add the timeout reset!
re-read the code above, it now shows the timeouts as loops where appropriate.

Rick 10-13-2005 08:39 PM

HTML Code:

//#CLIENTSIDE
function onCreated()
{
  this.on = false;
  this.setTimer(0.05);
}

function onTimeout()
{
  if (this.on == false)
  {
    if (someCheck())
    {
      this.on = true;
    }
  }
  else
  {
    if (someOtherCheck())
    {
      this.on = false;
    }
  }
 
  this.setTimer(0.05);
}


napo_p2p 10-14-2005 04:08 AM

Just a general question...

Is it bad if you don't use this.setTimer(float)?
(ex: setTimer(float);)

I'm guessing that it wouldn't be, since commands without the "this." prefix are already being called to the current 'object'?

Rick 10-14-2005 07:45 AM

Quote:

Originally Posted by napo_p2p
Just a general question...

Is it bad if you don't use this.setTimer(float)?
(ex: setTimer(float);)

I'm guessing that it wouldn't be, since commands without the "this." prefix are already being called to the current 'object'?

Correct.

I do it in accordance to Era's Scripting Guidelines.

ChibiChibiLuc 10-15-2005 03:01 AM

object.catchevent(name,event,newevent);

It calls 'newevent' every time 'event' is called.
It's main use is in GUI Controls, when you use a for() to create multiple buttons. You can use a catchevent to make clicking each button call the same event.

npc.catchevent(#N,"onPlayerEnters","onCreated");
This calls 'onCreated' each time 'onPlayerEnters' is called.

By the way, I only think npc. is required when it's used in an NPC Weapon. I don't know for sure, as I haven't tried it without the npc. prefix.

prozac424242 10-15-2005 06:16 AM

New question: I have tried for hours to get a very simple thing to work:
when you enter a level, your y is set to 0 and is increased through a timeout.
this part works fine.
What I can't get to work is when the playery is greater than 55 it warps the player to another level.

Since the timeout and playery manipulation is clientside,
and setlevel2 is serverside, I need a triggeraction, right?
I have tried to no avail:
-putting the whole script as a serverside event
-doing a triggeraction in the npc that is in the level on the npc's x and y, and above the clientside line in the npc, placing the actionserverside and setlevel commands
-leaving the triggeraction in the npc in the level but moving the action part into a weapon npc with a unique action name
-moving the entire script into the weapon npc and the level adds the weapon npc when you enter the level
-adding a warp box at the bottom of the level

nothing works!!! the player goes from the top to the bottom of the level (y increases) but it will not warp the player - the triggeraction never gets to the serverside command regardless of where the setlevel2 command is.

please help!


All times are GMT +2. The time now is 04:59 AM.

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