Raised This Month: $ Target: $400
 0% 

Code for random...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ctcwired
Member
Join Date: Aug 2007
Old 01-06-2008 , 19:00   Code for random...
Reply With Quote #1

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!
__________________
I run a server, I make maps. My server looks like this \/ \/
www.xanacreations.com +karma if I was good!
______________
Ctcwired is offline
Send a message via AIM to Ctcwired Send a message via Skype™ to Ctcwired
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-06-2008 , 19:09   Re: Code for random...
Reply With Quote #2

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
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Ctcwired
Member
Join Date: Aug 2007
Old 01-06-2008 , 19:18   Re: Code for random...
Reply With Quote #3

Will this select all 3 at random??
__________________
I run a server, I make maps. My server looks like this \/ \/
www.xanacreations.com +karma if I was good!
______________
Ctcwired is offline
Send a message via AIM to Ctcwired Send a message via Skype™ to Ctcwired
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-06-2008 , 19:22   Re: Code for random...
Reply With Quote #4

Just like that, it's enough...

Code:
server_cmd("amx_play holdmusic%d.mp3", random_num(1, 3));
__________________
Arkshine is offline
Ctcwired
Member
Join Date: Aug 2007
Old 01-06-2008 , 19:25   Re: Code for random...
Reply With Quote #5

Why (1, 3)??
I want holdmusic, holdmusic2 and holdmusic3

THREE! Not 2 and 3
__________________
I run a server, I make maps. My server looks like this \/ \/
www.xanacreations.com +karma if I was good!
______________
Ctcwired is offline
Send a message via AIM to Ctcwired Send a message via Skype™ to Ctcwired
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-06-2008 , 19:34   Re: Code for random...
Reply With Quote #6

Then rename holdmusic to holdmusic1.. This way you reduce code... It's not a big deal and better to do that... Oo
__________________

Last edited by Arkshine; 01-06-2008 at 19:38.
Arkshine is offline
Ctcwired
Member
Join Date: Aug 2007
Old 01-06-2008 , 19:51   Re: Code for random...
Reply With Quote #7

So if it is:
holdmusic1
holdmusic2
holdmusic3

Than
PHP Code:
server_cmd("amx_play holdmusic%d.mp3"random_num(13)); 
Will work?
__________________
I run a server, I make maps. My server looks like this \/ \/
www.xanacreations.com +karma if I was good!
______________
Ctcwired is offline
Send a message via AIM to Ctcwired Send a message via Skype™ to Ctcwired
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-06-2008 , 19:56   Re: Code for random...
Reply With Quote #8

yep.
__________________
Arkshine is offline
Ctcwired
Member
Join Date: Aug 2007
Old 01-07-2008 , 23:28   Re: Code for random...
Reply With Quote #9

Curious....

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

server_cmd("amx_play holdmusic%d.mp3", random_num(1, 4));
__________________
I run a server, I make maps. My server looks like this \/ \/
www.xanacreations.com +karma if I was good!
______________
Ctcwired is offline
Send a message via AIM to Ctcwired Send a message via Skype™ to Ctcwired
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 01-08-2008 , 05:50   Re: Code for random...
Reply With Quote #10

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.

Last edited by purple_pixie; 01-08-2008 at 06:05.
purple_pixie 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 11:12.


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