AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Percentage Chance (https://forums.alliedmods.net/showthread.php?t=127584)

Amonel 05-22-2010 18:24

Percentage Chance
 
for example i have a text "blablabla" and i want to print it at the end of rounds.

i want to make 35% probable that that message will be printed :/


(like in warcraft mode.. for example your have 10% chance of becoming a mole...)

HLM 05-22-2010 19:40

Re: Percentage Chance
 
this isnt "true" random, but im pretty sure this is exactly what your are looking for

PHP Code:

new randomnum random_num(1,100)
if(
randomnum <= 35)
    
client_print(0,print_chat,"%s",blahblah

edit: as for the round end part, I dont know, sorry :(

hleV 05-22-2010 19:44

Re: Percentage Chance
 
PHP Code:

#include <amxmodx>
 
#define chance(%1) ( %1 > random(100) ) // %1 = probability
 
new g_Textg_Chance;
 
public 
plugin_init()
{
        
register_plugin("End Round Message""1.1""hleV");
 
        
g_Text register_cvar("erm_text""Default Text");
        
g_Chance register_cvar("erm_chance""35");
 
        
register_logevent("RoundEnd"2"1=Round_End");
}
 
public 
RoundEnd()
{
        if (
chance(get_pcvar_num(g_Chance)))
                return;
 
        new 
Text[128];
        
get_pcvar_string(g_TextText127);
 
        
client_print(0print_chatText);



fysiks 05-22-2010 20:45

Re: Percentage Chance
 
I use this:

Code:

#define chance(%1) ( %1 > random(100) ) // %1 = probability
Example Here.

@hlev
That's confusing.

Amonel 05-23-2010 06:48

Re: Percentage Chance
 
thanks hlev :)

@fysiks: you can edit it :}

fysiks 05-23-2010 16:32

Re: Percentage Chance
 
Quote:

Originally Posted by Amonel (Post 1188645)
@fysiks: you can edit it :}

What?

Amonel 05-23-2010 17:14

Re: Percentage Chance
 
he used cvar so that you can change the message and % chance when i want :)

nvmd.. :)

fysiks 05-23-2010 17:16

Re: Percentage Chance
 
Quote:

Originally Posted by Amonel (Post 1189220)
he used cvar so that you can change the message and % chance when i want :)

nvmd.. :)

Yes but the logic is backward. So, when you go to write another plugin with "chance" it will probably confuse you unless you come back here and copy it again.

My code is an example. This is Scripting Help and not a Request forum.

He just gave you a fish for dinner. I was trying to teach you how to fish. IMO :)


All times are GMT -4. The time now is 05:23.

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