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

Random Function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 05-11-2011 , 13:09   Random Function
Reply With Quote #1

Hello.

I want to create random choose from some variables.

I detect some random function in different plugins. For example
Code:
new name_rand = random_num(0,namesread - 1)
here.
But it`s not exactly, what i need.

For example i need to make random choose from variable 1 or 2.

I need something like this:

Code:
#include <amxmodx>

new const 1st = 57.1;
new const 2nd = 98.6;

public plugin_init() {
	register_plugin("...","...","...")
}

public client_authorized(id)
{
        set_task (random    ... How should i continue to make random action?
        return PLUGIN_CONTINUE
}
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
Rirre
Veteran Member
Join Date: Nov 2006
Old 05-11-2011 , 13:20   Re: Random Function
Reply With Quote #2

http://forums.alliedmods.net/showthr...et_task+random
Rirre is offline
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 05-11-2011 , 13:28   Re: Random Function
Reply With Quote #3

Quote:
Originally Posted by Rirre View Post
It`s not a number.

it`s constants.
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-11-2011 , 21:59   Re: Random Function
Reply With Quote #4

Use an array and index it with a random number.

Code:
new const Float:values[] = {     57.1,     98.6 }; new Float:value = values[random(sizeof(values))];
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 05-12-2011 , 11:12   Re: Random Function
Reply With Quote #5

Quote:
Originally Posted by Exolent[jNr] View Post
Use an array and index it with a random number.

Code:
new const Float:values[] = {     57.1,     98.6 }; new Float:value = values[random(sizeof(values))];
Thanks, how can i use it?

Code:
set_task (random    ... How should i continue to make random action?
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-12-2011 , 12:50   Re: Random Function
Reply With Quote #6

Show exactly what you are trying to do.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 05-12-2011 , 17:17   Re: Random Function
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
Show exactly what you are trying to do.
I am trying to make random action, from list.
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-12-2011 , 18:42   Re: Random Function
Reply With Quote #8

Quote:
Originally Posted by Mofforg View Post
I am trying to make random action, from list.
You will need to be more specific. What functions do you have already? And, what functions are the "actions".
__________________
fysiks is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-13-2011 , 02:04   Re: Random Function
Reply With Quote #9

Quote:
Originally Posted by Mofforg View Post
I am trying to make random action, from list.
Random time? Random function? Describe in more detail.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
pRoxxxDD
Junior Member
Join Date: Feb 2011
Location: Ukraine
Old 05-13-2011 , 04:17   Re: Random Function
Reply With Quote #10

Use if, else (if variable <= 2), or switch (if variable >2).

PHP Code:
if(new_rand 1)
{
       
set_task(....)

}
else
{
       
set_task(...)


PHP Code:
switch(new_rand):
{
          case 
1set_task(...)
          case 
2set_tasl(...)
          case 
nset_tasl(...)

__________________

Last edited by pRoxxxDD; 05-13-2011 at 04:19.
pRoxxxDD 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 06:10.


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