AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random part of string... ? (https://forums.alliedmods.net/showthread.php?t=192829)

Gadzislaw007 08-14-2012 13:21

Random part of string... ?
 
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.

YamiKaitou 08-14-2012 13:27

Re: Random part of string... ?
 
PHP Code:

new sound[30];
formatex(soundcharsmax(sound), "sound/hitsounds/hit%d.wav"random_num(18)); 


ConnorMcLeod 08-14-2012 14:11

Re: Random part of string... ?
 
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)



Gadzislaw007 08-14-2012 14:46

Re: Random part of string... ?
 
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)

ConnorMcLeod 08-14-2012 14:49

Re: Random part of string... ?
 
You need to precache all sounds in plugin_precache with plugin_precache native.
Sounds have to be mono encoded.

Gadzislaw007 08-14-2012 15:09

Re: Random part of string... ?
 
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


All times are GMT -4. The time now is 05:43.

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