AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Trigger function with % chance (https://forums.alliedmods.net/showthread.php?t=294197)

Airkish 02-22-2017 04:24

Trigger function with % chance
 
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?

Natsheh 02-22-2017 05:04

Re: Trigger function with % chance
 
random_num(1, 100) <= 5

CmdKnifeRound()

Airkish 02-22-2017 05:11

Re: Trigger function with % chance
 
Quote:

Originally Posted by Natsheh (Post 2497407)
random_num(1, 100) >= 5

CmdKnifeRound()

no effect, same error.

edon1337 02-22-2017 06:36

Re: Trigger function with % chance
 
PHP Code:

new random random_num(1100)

if(
random <= 5
CmdKnifeRound(); 


georgik57 02-22-2017 08:03

Re: Trigger function with % chance
 
You have to specify the CmdKnifeRound parameters.

Post the "public CmdKnifeRound(..." line here.

OciXCrom 02-22-2017 11:54

Re: Trigger function with % chance
 
Code:
if(!random(100))

PRoSToTeM@ 02-22-2017 12:07

Re: Trigger function with % chance
 
Quote:

Originally Posted by OciXCrom (Post 2497533)
Code:
if(!random(100))

This is 1/100 chance.

Emp` 02-22-2017 12:09

Re: Trigger function with % chance
 
Code:

stock bool Chance( iNum, iMult=100 )
        return ( iNum * iMult >= random_num( 1, 100 * iMult ) );

Code:

if ( Chance( 5 ) )
{
  //...
}


edon1337 02-22-2017 12:23

Re: Trigger function with % chance
 
Quote:

Originally Posted by Emp` (Post 2497546)
Code:

stock bool Chance( iNum, iMult=100 )
        return ( iNum * iMult >= random_num( 1, 100 * iMult ) );

Code:

if ( Chance( 5 ) )
{
  //...
}


Ure a genius

Airkish 02-22-2017 14:00

Re: Trigger function with % chance
 
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?


All times are GMT -4. The time now is 18:25.

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