Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Random Selection question (https://forums.graalonline.com/forums/showthread.php?t=134266710)

Stowen 06-23-2012 03:21 AM

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



cbk1994 06-23-2012 03:22 AM

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.

Chompy 06-23-2012 03:41 AM

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.

Stowen 06-23-2012 06:09 AM

So would I use a scheduleevent to call a function that would set the Timer to 0?

Stowen 06-23-2012 06:12 AM

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?

DustyPorViva 06-23-2012 06:19 AM

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.

Starfire2001 06-23-2012 06:29 AM

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

Stowen 06-23-2012 05:56 PM

Quote:

Originally Posted by DustyPorViva (Post 1698177)
Is what Chris was referencing.

Oh, I get it now :P

Quote:

Originally Posted by Starfire2001 (Post 1698179)
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! :)


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

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