Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Need some quick help (https://forums.graalonline.com/forums/showthread.php?t=134258024)

Jman9912 02-16-2010 09:40 AM

Need some quick help
 
Hey guys. Hoping to get a bit of help here. I'm working on a fishing system that initializes and brings up a button you have to press. if the correct button is pressed within x amount of seconds (we'll use 3 seconds), another button pops up with about 5 rounds of this. If the button is not pressed or the incorrect button is pressed, you lose.

I'm initializing the weapon and calling a timeout. The timeout runs through functions ShowButton(),CheckKeys().

showbutton determines a random number 0-3 and show the corresponding button. How can I make the button stay there for x seconds without having to call the timeout again. If that makes sense.

I'm running the timeout on a .05 timer which is constantly running the show arrow script and checking for a keydown.

I'm really sorry if this sounds confusing. If I need to elaborate more, i'll try.

xAndrewx 02-16-2010 10:16 AM

If I were scripting a system that did this I'd use
HTML Code:

scheduleevent(sleep, "onEventName", params);
to control the actions, a timeout isn't necessary. You can always cancel an event by using
HTML Code:

cancelevents("onEventName");
Goodluck! ^^

Jman9912 02-16-2010 10:47 AM

That's not a bad idea at all. I'll try to incorporate that. Right now i'm having problems with the keychecking. I know i'm doing something wrong, but can't figure out what.

PHP Code:

function fishingCast(bait
  {
    if (
this.fishing ==1
    {
      
setTimer(0.05); //Sets timer for freezing the player
      
this.arrow ShowArrows(); //Picks a random key 0-3
      
this.fishingKey GetKey(); //Check for a key being pressed
      
echo("Keypressed = " this.fishingKey);
    } 
  }
  
function 
onTimeout() 
  {
    
freezeplayer(6);
    
setTimer(5);
  }
  
  
function 
ShowArrows() 
  {
    
temp.arrow int(random(0,3)); //Random key 0-3
    
      
switch (temp.arrow
        {
        case 
"0":
        
showimg(2001"@Courier New@b@^"player.x+1.5player.y-.5);
        break;
        
        case 
"1":
        
showimg(2001"@Courier New@b@<"player.x+1.5player.y-.5);
        break;
      
        case 
"2":
        
showimg(2001"@Courier New@b@V"player.x+1.5player.y-.5);
        break;
        
        case 
"3":
        
showimg(2001"@Courier New@b@>"player.x+1.5player.y-.5);
        break;
        }
    return 
temp.arrow;
  }
  
function 
GetKey() 
{
 
temp.keyPressed NULL;
 while(
temp.keyPressed NULL
 {
    for (
temp.key 0temp.key 4temp.key++;)
    {
      if (
keydown(temp.key)) 
      {
        
temp.keyPressed temp.key;
      }
    
    }
  }
  return 
temp.keyPressed;
  
 } 


cbk1994 02-16-2010 10:53 AM

You can't use while loops like that in Graal; it will hit a max loop limit. Either way, it's best to just use the onKeyPressed event.

I would probably do it somewhat like this:

PHP Code:

//#CLIENTSIDE
function startFishing() {
  
this.isFishing true;
  
this.onNextFish();
}

function 
onNextFish() {
  
this.keyToPress int(random(04));
  
  
this.cancelEvents("nextFish");
  
this.scheduleEvent(3"nextFish"null);
}

function 
onKeyPressed(codekey) {
  if (! 
this.isFishing) {
    return;
  }
  
  for (
temp.04++) {
    if (
keydown(i)) {
      if (
this.keyToPress == i) {
        
this.caughtFish();
      }
      
      
// next fish
      
this.onNextFish();
      break;
    }
  }


You'll need to add in images and such, and I haven't tested it so it may not work for some reason, not sure.


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

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