Raised This Month: $ Target: $400
 0% 

Percentage Chance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Amonel
Senior Member
Join Date: May 2009
Old 05-22-2010 , 18:24   Percentage Chance
Reply With Quote #1

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...)
Amonel is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 05-22-2010 , 19:40   Re: Percentage Chance
Reply With Quote #2

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
__________________
+|- KARMA Respectively


Last edited by HLM; 05-22-2010 at 19:45.
HLM is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-22-2010 , 19:44   Re: Percentage Chance
Reply With Quote #3

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

__________________

Last edited by hleV; 05-23-2010 at 17:30.
hleV is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-22-2010 , 20:45   Re: Percentage Chance
Reply With Quote #4

I use this:

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

@hlev
That's confusing.
__________________

Last edited by fysiks; 05-22-2010 at 20:47.
fysiks is offline
Amonel
Senior Member
Join Date: May 2009
Old 05-23-2010 , 06:48   Re: Percentage Chance
Reply With Quote #5

thanks hlev

@fysiks: you can edit it :}
Amonel is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-23-2010 , 16:32   Re: Percentage Chance
Reply With Quote #6

Quote:
Originally Posted by Amonel View Post
@fysiks: you can edit it :}
What?
__________________
fysiks is offline
Amonel
Senior Member
Join Date: May 2009
Old 05-23-2010 , 17:14   Re: Percentage Chance
Reply With Quote #7

he used cvar so that you can change the message and % chance when i want

nvmd..
Amonel is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-23-2010 , 17:16   Re: Percentage Chance
Reply With Quote #8

Quote:
Originally Posted by Amonel View Post
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
__________________
fysiks 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 05:23.


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