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 06-23-2012, 03:21 AM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
Random Selection question

Hey guys, I have another question. Along with the timer question I had earlier, I added a function when the timer runs out for a random selection. It's for a Chance-type event I'm trying to make. I get it to select randomly, but the trouble I am having, is getting the TimeOut loop to stop. How would I go about this?

Here is what I have so far:
PHP Code:
function onTimeOut() {
this.randombox int(random(1,8));
this.chat this.randombox;
setTimer(0.5);

Reply With Quote
  #2  
Old 06-23-2012, 03:22 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
Not sure exactly what you're trying to do, but you can abuse return; to end a function. As long as the setTimer doesn't get called, it will stop repeatedly calling the onTimeOut function.
__________________
Reply With Quote
  #3  
Old 06-23-2012, 03:41 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
by using setTimer(0); you can cancel the onTimeout event from happening

The onTimeout event will only loop if you set a new timer for it inside the onTimeout function code snippet as well.
__________________
Reply With Quote
  #4  
Old 06-23-2012, 06:09 AM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
So would I use a scheduleevent to call a function that would set the Timer to 0?
Reply With Quote
  #5  
Old 06-23-2012, 06:12 AM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
I'm trying to loop it a few times, so it kinda names of a few random numbers before selecting a box. It's basically just a visual for the players of the event. Similar to UN's. Not sure if you guys have seen it?
Reply With Quote
  #6  
Old 06-23-2012, 06:19 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
PHP Code:
function onTimeout() {
  
// if conditions are met, return to stop the function. This means anything after
  // the return is not executed, so the setTimer() is never called
  
if (int(random(0,8)) <= 2) return;
  
setTimer(0.5);

Is what Chris was referencing.
Reply With Quote
  #7  
Old 06-23-2012, 06:29 AM
Starfire2001 Starfire2001 is offline
Unholy Nation
Starfire2001's Avatar
Join Date: Dec 2010
Location: The streets.
Posts: 156
Starfire2001 will become famous soon enough
Post

If you want to do something similar to UNs...

From whatever other function.
PHP Code:
onPickBox(25); 
PHP Code:
function onPickBox(temp.c){ 
  if(
temp.0){
    
this.randombox int(random(1,9));
    
this.chat this.randombox;
    
scheduleevent(.5,"PickBox",temp.1);
  }
  else{
    
this.chat this.randombox SPC "selected!";
  }

Note I changed your random script from int(random(1,8)) to int(random(1,9)), cause assuming you are making a standard 8 box Chance event box 8 would never be selected in your original script (never can be max number).
__________________
-Ph8
Reply With Quote
  #8  
Old 06-23-2012, 05:56 PM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
Quote:
Originally Posted by DustyPorViva View Post
Is what Chris was referencing.
Oh, I get it now :P

Quote:
Originally Posted by Starfire2001 View Post
Note I changed your random script from int(random(1,8)) to int(random(1,9)), cause assuming you are making a standard 8 box Chance event box 8 would never be selected in your original script (never can be max number).
Yes I am, thank you for the help!
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 09:05 PM.


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