Raised This Month: $ Target: $400
 0% 

Random part of string... ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-14-2012 , 13:21   Random part of string... ?
Reply With Quote #1

Didn't know how name the topic properly.
...
Hi. I'd love to know if there is a possibility to create string with part, which will be a random number.
I wanna to play sound by random.
Sounds names are like hit1.wav, hit2.wav, hit3.wav etc...
I wanna to create string named
PHP Code:
"sound/hitsounds/hit%d.wav" 
where
PHP Code:
%random_num
How do i do such a variable string?
I wanna make one emitsound command, instead of making switch with 8 cases.
Is this possbile? I guess yes. But I don't know this language that much to create strings properly.

Last edited by Gadzislaw007; 08-14-2012 at 13:21.
Gadzislaw007 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-14-2012 , 13:27   Re: Random part of string... ?
Reply With Quote #2

PHP Code:
new sound[30];
formatex(soundcharsmax(sound), "sound/hitsounds/hit%d.wav"random_num(18)); 
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Old 08-14-2012, 13:28
DjOptimuS
This message has been deleted by DjOptimuS.
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-14-2012 , 14:11   Re: Random part of string... ?
Reply With Quote #3

You don't need to format :

PHP Code:
{
    new 
sound[25] = "sound/hitsounds/hitX.wav"
    
sound[19] = '0' random_num(18)

I think you mustn't include sound/ into sound path :

PHP Code:
{
    new 
sound[19] = "hitsounds/hitX.wav"
    
sound[13] = '0' random_num(18)

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Old 08-14-2012, 14:37
Gadzislaw007
This message has been deleted by Gadzislaw007. Reason: refresh
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-14-2012 , 14:46   Re: Random part of string... ?
Reply With Quote #4

Well, both ways look correct.
Thanks for helping me guys.

But it still doesn't work xD
PHP Code:
public hitsound(id)
{
    if (
random_num(1,5) == 5)
    {
        new 
sound[23] = "gad/hitsounds/hitX.wav" 
        
sound[17] = '0' random_num(18
        
emit_sound(idCHAN_BODYsoundVOL_NORMATTN_NORM0PITCH_NORM)

    }
    

the public hitsound(id) function is being called for sure, but the sound doesn't go on
it although works with console (spk sound/gad/hitsound/hit1.wav)

Last edited by Gadzislaw007; 08-14-2012 at 14:46.
Gadzislaw007 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-14-2012 , 14:49   Re: Random part of string... ?
Reply With Quote #5

You need to precache all sounds in plugin_precache with plugin_precache native.
Sounds have to be mono encoded.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-14-2012 , 15:09   Re: Random part of string... ?
Reply With Quote #6

I did. Don't worry. In other cases than this random string they work.
If I put just
PHP Code:
public hitsound(id)
{
    if (
random_num(1,5) == 5)
    {
        
emit_sound(idCHAN_BODY"gad/hitsounds/hit1.wav"VOL_NORMATTN_NORM0PITCH_NORM)

    }
    

instead, it works

Last edited by Gadzislaw007; 08-14-2012 at 15:10.
Gadzislaw007 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:43.


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