AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Code for random... (https://forums.alliedmods.net/showthread.php?t=65366)

Ctcwired 01-06-2008 19:00

Code for random...
 
Ok... I have this in my script...
PHP Code:

        server_cmd"amx_play holdmusic.mp3" 

This command is executing great... When it is time to... it executes
amx_play holdmusic.mp3

I added holdmusic2.mp3 and holdmusic3.mp3.....

I would like to change this command to a random state....
sometimes it does amx_play holdmusic.mp3
sometimes amx_play holdmusic2.mp3
and sometimes amx_play holdmusic3.mp3

Can someone give me the command that does random?? Or a small script that does random.... this command only needs to be executed once per map change... and the rest of the plugin is already getting to and executing this command but I want to make it execute 3 different commands at random...

Thanks!:up:

Exolent[jNr] 01-06-2008 19:09

Re: Code for random...
 
Code:

new num = random_num(1, 3);
new string[2] = num_to_str(num, string, 1);
server_cmd("amx_play holdmusic%s.mp3", (num > 1) ? string : "");

just an example

Ctcwired 01-06-2008 19:18

Re: Code for random...
 
Will this select all 3 at random??

Arkshine 01-06-2008 19:22

Re: Code for random...
 
Just like that, it's enough...

Code:
server_cmd("amx_play holdmusic%d.mp3", random_num(1, 3));

Ctcwired 01-06-2008 19:25

Re: Code for random...
 
Why (1, 3)??
I want holdmusic, holdmusic2 and holdmusic3

THREE! Not 2 and 3

Arkshine 01-06-2008 19:34

Re: Code for random...
 
Then rename holdmusic to holdmusic1.. This way you reduce code... It's not a big deal and better to do that... Oo

Ctcwired 01-06-2008 19:51

Re: Code for random...
 
So if it is:
holdmusic1
holdmusic2
holdmusic3

Than
PHP Code:

server_cmd("amx_play holdmusic%d.mp3"random_num(13)); 

Will work?

Arkshine 01-06-2008 19:56

Re: Code for random...
 
yep.

Ctcwired 01-07-2008 23:28

Re: Code for random...
 
Curious....

If I wanted to have a holdmusic4.mp3 than would I use:

server_cmd("amx_play holdmusic%d.mp3", random_num(1, 4));

purple_pixie 01-08-2008 05:50

Re: Code for random...
 
Replace "curious" with "retarded" and that post's nothing but accurate.

EDIT: That may have been a little harsh ...

Yes, that's what you want.

random(x,y) returns an integer that could be x, y, or any integer between them.


All times are GMT -4. The time now is 11:12.

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