Raised This Month: $12 Target: $400
 3% 

Trigger function with % chance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 02-22-2017 , 04:24   Trigger function with % chance
Reply With Quote #1

I want function to be triggered with 5% chance but I'm getting error

PHP Code:
number of arguments doesn't match definition 
So what I'm doing (or at least I think it should do like that)
Every round start it gets a random number from 1 to 100 if number is equal or below 5 then it does CmdKnifeRound

PHP Code:
public RoundStart() {
    if(
random_num1100) <= 5) {
        
CmdKnifeRound;
    }

Any help?
__________________
Airkish is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-22-2017 , 05:04   Re: Trigger function with % chance
Reply With Quote #2

random_num(1, 100) <= 5

CmdKnifeRound()
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-22-2017 at 09:07.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 02-22-2017 , 05:11   Re: Trigger function with % chance
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
random_num(1, 100) >= 5

CmdKnifeRound()
no effect, same error.
__________________
Airkish is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-22-2017 , 06:36   Re: Trigger function with % chance
Reply With Quote #4

PHP Code:
new random random_num(1100)

if(
random <= 5
CmdKnifeRound(); 
__________________
edon1337 is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 02-22-2017 , 08:03   Re: Trigger function with % chance
Reply With Quote #5

You have to specify the CmdKnifeRound parameters.

Post the "public CmdKnifeRound(..." line here.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-22-2017 , 11:54   Re: Trigger function with % chance
Reply With Quote #6

Code:
if(!random(100))
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 02-22-2017 , 12:07   Re: Trigger function with % chance
Reply With Quote #7

Quote:
Originally Posted by OciXCrom View Post
Code:
if(!random(100))
This is 1/100 chance.
__________________

Last edited by PRoSToTeM@; 02-22-2017 at 12:07.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 02-22-2017 , 12:09   Re: Trigger function with % chance
Reply With Quote #8

Code:
stock bool Chance( iNum, iMult=100 )
	return ( iNum * iMult >= random_num( 1, 100 * iMult ) );
Code:
if ( Chance( 5 ) )
{
   //...
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-22-2017 , 12:23   Re: Trigger function with % chance
Reply With Quote #9

Quote:
Originally Posted by Emp` View Post
Code:
stock bool Chance( iNum, iMult=100 )
	return ( iNum * iMult >= random_num( 1, 100 * iMult ) );
Code:
if ( Chance( 5 ) )
{
   //...
}
Ure a genius
__________________
edon1337 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 02-22-2017 , 14:00   Re: Trigger function with % chance
Reply With Quote #10

PHP Code:
public RoundStart(id) {
    new 
random random_num(1100);

    if(
random <= 5
    
CmdKnifeRound(id);  

I added (id) and it works.

Should I replace this to Emp`'s code and what would be the difference?
__________________

Last edited by Airkish; 02-22-2017 at 14:02.
Airkish is offline
Reply


Thread Tools
Display Modes

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 20:12.


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