Raised This Month: $ Target: $400
 0% 

Random choose between possibilities?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chescos
Member
Join Date: Aug 2011
Old 01-30-2015 , 14:00   Random choose between possibilities?
Reply With Quote #1

Hey,

I wanna print a message to chat, it should be randomly chosen out of various possibilities, like I make "message1", "message2", "message3" and one of those gets randomly chosen to be printed in chat. How is this possile?

Regards
chescos is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-30-2015 , 14:04   Re: Random choose between possibilities?
Reply With Quote #2

Use the GetRandomInt function.

It takes two arguments: The first valid value and the last valid value.

So, if you wanted a choice between the numbers 1 and 3...

PHP Code:
switch (GetRandomInt(13))
{
    case 
1:
    {
    }

    case 
2:
    {
    }

    case 
3:
    {
    }

Note that cases can also be combined. So if you wanted something to happen 3 out of 10 times you could use GetRandomInt(1, 10) with case 1, 2, 3: and default:
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-30-2015 at 14:06. Reason: Forgot the link
Powerlord is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-30-2015 , 14:17   Re: Random choose between possibilities?
Reply With Quote #3

https://wiki.alliedmods.net/Introduction_to_SourcePawn
https://wiki.alliedmods.net/Introduc...rceMod_Plugins
KissLick 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 01:05.


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