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 02-16-2010, 09:40 AM
Jman9912 Jman9912 is offline
Registered User
Join Date: Jun 2001
Location: North Carolina
Posts: 114
Jman9912 is on a distinguished road
Send a message via AIM to Jman9912
Exclamation 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.
Reply With Quote
  #2  
Old 02-16-2010, 10:16 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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!
__________________
Reply With Quote
  #3  
Old 02-16-2010, 10:47 AM
Jman9912 Jman9912 is offline
Registered User
Join Date: Jun 2001
Location: North Carolina
Posts: 114
Jman9912 is on a distinguished road
Send a message via AIM to Jman9912
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;
  
 } 
Reply With Quote
  #4  
Old 02-16-2010, 10:53 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
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.
__________________
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 07:11 AM.


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