Raised This Month: $ Target: $400
 0% 

Random chance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bitl
Senior Member
Join Date: Jul 2012
Old 05-24-2013 , 18:14   Random chance
Reply With Quote #1

How do I do a chance (example 1 out of 10) then activate an event?

Code:
for (new i=1; i<=10; i++)
    {
        //something
    }
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.
Bitl is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 05-24-2013 , 18:53   Re: Random chance
Reply With Quote #2

Quote:
Originally Posted by Bitl View Post
How do I do a chance (example 1 out of 10) then activate an event?

Code:
for (new i=1; i<=10; i++)
    {
        //something
    }
Example like this:
PHP Code:
new chance GetRandomInt(110// Gets Random Number from 1 to 10
if(chance == 1
{
 
/// STUFF THAT ACTIVATES EVENT

__________________
...

Last edited by Oshizu; 05-24-2013 at 18:54.
Oshizu is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 05-24-2013 , 21:21   Re: Random chance
Reply With Quote #3

Though if you're going to use a lot of if-statements you should probably use a switch instead.
__________________
11530 is offline
pilger
Senior Member
Join Date: Sep 2010
Old 05-24-2013 , 22:25   Re: Random chance
Reply With Quote #4

Quote:
Originally Posted by 11530 View Post
Though if you're going to use a lot of if-statements you should probably use a switch instead.
Here's a pretty decent explanation of how the switch works: http://wiki.alliedmods.net/Introduct...tch_Statements
pilger is offline
JackieChan
AlliedModders Donor
Join Date: Nov 2009
Old 05-25-2013 , 02:57   Re: Random chance
Reply With Quote #5

PHP Code:
new random GetRandomInt(1,10);
switch(
random)
{
     case 
1:
     {
           
//DO STUFF
     
}

__________________
JackieChan is offline
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 -4. The time now is 13:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode