AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ambience Sound + Loop (https://forums.alliedmods.net/showthread.php?t=108430)

drumzplaya13 11-05-2009 09:15

Ambience Sound + Loop
 
I have tried variations of trying to fix this but maybe I am just not seeing something. The warning is Warning: Loose indentation on line 53

Line 53 is... fclose(f); at the end of the part of the code.

PHP Code:

{   
         new 
Data[160]         
         new 
Map[32]         
         new 
Sound[64];         
         new 
Duration[32];                 

         
fgets(fData160);         
         
parse(DataMap20Sound64Duration32); 

         if(
equali(gMapMap) && strlen(Sound) > && strlen(Duration) > 0
         {             
            
gSound Sound             
            gDuration 
Duration             
            gFoundMap 
true;                     

            return;         
         }     
     }        
     
fclose(f); 


Does that mean I have an extra } or that fclose(f); isnt in the correct place?

hleV 11-05-2009 09:43

Re: Warning: Loose indentation on line 53
 
PHP Code:

         }     
     }        
     
fclose(f);


:arrow:
PHP Code:

         }       
 
         
fclose(f);



drumzplaya13 11-05-2009 09:44

Re: Warning: Loose indentation on line 53
 
I did that and it gave me 3 errors than.

Code:

Warning: Loose indentation on line 53
Warning: Loose indentation on line 56
Error: Invalid expression, assumed zero on line 56
Error: Undefined symbol "PlaySound" on line 56
Error: Expected token: "}", but found "-end of file-" on line 70

Edit: Fixed.

matsi 11-05-2009 10:07

Re: Warning: Loose indentation on line 53
 
Quote:

Originally Posted by drumzplaya13 (Post 981468)
I did that and it gave me 3 errors than.

Code:

Warning: Loose indentation on line 53
Warning: Loose indentation on line 56
Error: Invalid expression, assumed zero on line 56
Error: Undefined symbol "PlaySound" on line 56
Error: Expected token: "}", but found "-end of file-" on line 70

Edit: Fixed.

Error: Expected token: "}", but found "-end of file-" on line 70

Look at the end of the file and you see there is } missing. And what do you have in 56 line?

drumzplaya13 11-05-2009 10:14

Re: Warning: Loose indentation on line 53
 
Quote:

Originally Posted by matsi (Post 981473)
Error: Expected token: "}", but found "-end of file-" on line 70

Look at the end of the file and you see there is } missing. And what do you have in 56 line?

I fixed the compile, the plugin doesnt seem to work as it is suppose to though. Here is the code.


PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Ambience Sounds"
#define VERSION "1.0"
#define AUTHOR "Jon"

new gCvarMethod;

new 
gSound[64];
new 
gDuration[32];
new 
gMap[32];

new 
bool:gFoundMap;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
gCvarMethod register_cvar("amx_ambience_method""0"
    
    
set_task(20.0"PlaySound")
    
    
get_mapname(gMap31)
}

public 
plugin_cfg()
{
    new 
configfile[96];
    
get_configsdir(configfile96);
    
add(configfile96"/ambience_sounds.ini");
    
    new 
fopen(configfile"rt");
    
    while (!
feof(f))
    {
        new 
Data[160]
        new 
Map[32]
        new 
Sound[64];
        new 
Duration[32];
        
        
fgets(fData160);
        
parse(DataMap20Sound64Duration32);
        
        if(
equali(gMapMap) && strlen(Sound) > && strlen(Duration) > 0)
        {
            
gSound Sound
            gDuration 
Duration
            gFoundMap 
true;
        
            return;
        }
    }
    
    
fclose(f);
}

public 
PlaySound()
{
    if(!
gFoundMap)
        return;
        
    if(
get_pcvar_num(gCvarMethod) == 1)
        
client_cmd(0"spk %s"gSound)
        
    else
         
client_cmd(0"mp3 play %s"gSound)
    
    
set_task(float(str_to_num(gDuration)) + 5.0"PlaySound")



drumzplaya13 11-05-2009 10:21

Re: Warning: Loose indentation on line 53
 
Quote:

Originally Posted by matsi (Post 981473)
Error: Expected token: "}", but found "-end of file-" on line 70

Look at the end of the file and you see there is } missing. And what do you have in 56 line?

I fixed the compile, the plugin doesnt seem to work as it is suppose to though. Here is the code. What I am trying to do is have a .wav file that plays as ambience and loops the whole time I am on a specific map.


PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Ambience Sounds"
#define VERSION "1.0"
#define AUTHOR "Jon"

new gCvarMethod;

new 
gSound[64];
new 
gDuration[32];
new 
gMap[32];

new 
bool:gFoundMap;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
gCvarMethod register_cvar("amx_ambience_method""0"
    
    
set_task(20.0"PlaySound")
    
    
get_mapname(gMap31)
}

public 
plugin_cfg()
{
    new 
configfile[96];
    
get_configsdir(configfile96);
    
add(configfile96"/ambience_sounds.ini");
    
    new 
fopen(configfile"rt");
    
    while (!
feof(f))
    {
        new 
Data[160]
        new 
Map[32]
        new 
Sound[64];
        new 
Duration[32];
        
        
fgets(fData160);
        
parse(DataMap20Sound64Duration32);
        
        if(
equali(gMapMap) && strlen(Sound) > && strlen(Duration) > 0)
        {
            
gSound Sound
            gDuration 
Duration
            gFoundMap 
true;
        
            return;
        }
    }
    
    
fclose(f);
}

public 
PlaySound()
{
    if(!
gFoundMap)
        return;
        
    if(
get_pcvar_num(gCvarMethod) == 1)
        
client_cmd(0"spk %s"gSound)
        
    else
         
client_cmd(0"mp3 play %s"gSound)
    
    
set_task(float(str_to_num(gDuration)) + 5.0"PlaySound")



Jon 11-05-2009 11:00

Re: Ambience Sound + Loop
 
Not tested.

PHP Code:

// SYNTAX: "map" "sound path" "duration"
// Don't include "sound/" in the sound path

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>

#define PLUGIN "Ambience Sounds"
#define VERSION "1.0"
#define AUTHOR "Jon"

new const gClass[ ] = "SoundThinker"

new gSoundFormatFloat:gDurationgSound32 ]

public 
plugin_init( )
{
    
register_pluginPLUGINVERSIONAUTHOR )
    
    new 
Data96 ]
    
get_configsdirData95 )
    
addData95"/ambience_sounds.ini" )
    
    new 
CurMap32 ], Map32 ], Duration], fopenData"rt" )
    
get_mapnameCurMap31 )
    
    while( !
feof) )
    {
        
fgetsfData95 )
        
trimData )
        
        if( !
Data] || Data] == ';' || Data] == '/' && Data] == '/' )
            continue
        
        
parseDataMap31gSound31Duration)
        
        if( 
equalCurMapMap ) )
        {
            if( 
containigSound".mp3" ) != -)
            {
                
gSoundFormat true
                
                engfunc
EngFunc_PrecacheGenericgSound )
            }
            
            else
                
engfuncEngFunc_PrecacheSoundgSound )
            
            
gDuration str_to_floatDuration ) + 1
            
            register_think
gClass"SoundThink" )
            
            new 
Ent create_entity"info_target" )
            
            
entity_set_stringEntEV_SZ_classnamegClass )
            
entity_set_floatEntEV_FL_nextthinkget_gametime( ) + 15.0 )
            
            break
        }
    }
    
    
fclose)
}

public 
SoundThinkEnt )
{
    if( !
is_valid_entEnt ) )
        return 
PLUGIN_CONTINUE
    
    
if( gSoundFormat )
    {
        
client_cmd0"mp3 stop" )
        
client_cmd0"mp3 play sound/%s"gSound )
    }
    
    else
        
client_cmd0"spk sound/%s"gSound )
    
    
    
entity_set_floatEntEV_FL_nextthinkget_gametime( ) + gDuration )
    
    return 
PLUGIN_CONTINUE



drumzplaya13 11-05-2009 12:53

Re: Ambience Sound + Loop
 
Quote:

Originally Posted by Jon (Post 981513)
Not tested.

PHP Code:

// SYNTAX: "map" "sound path" "duration"
// Don't include "sound/" in the sound path

#include <amxmodx>
#include <amxmisc>
#include <engine>

#define PLUGIN "Ambience Sounds"
#define VERSION "1.0"
#define AUTHOR "Jon"

new const gClass[ ] = "SoundThinker"

new gSoundFormatFloat:gDurationgSound32 ]

public 
plugin_init( )
{
    
register_pluginPLUGINVERSIONAUTHOR )
    
    new 
Data96 ]
    
get_configsdirData95 )
    
addData95"/ambience_sounds.ini" )
    
    new 
CurMap32 ], Map32 ], Duration], fopenData"rt" )
    
get_mapnameCurMap31 )
    
    while( !
feof) )
    {
        
fgetsfData95 )
        
trimData )
        
        if( !
Data] || Data] == ';' || Data] == '/' && Data] == '/' )
            continue
        
        
parseDataMap31gSound31Duration)
        
        if( 
equalCurMapMap ) )
        {
            if( 
containigSound".mp3" ) != -)
            {
                
gSoundFormat true
            
}
            
            
gDuration str_to_floatDuration ) + 1
            
            register_think
gClass"SoundThink" )
            
            new 
Ent create_entity"info_target" )
            
            
entity_set_stringEntEV_SZ_classnamegClass )
            
entity_set_floatEntEV_FL_nextthinkget_gametime( ) + 15.0 )
            
            break
        }
    }
    
    
fclose)
}

public 
SoundThinkEnt )
{
    if( !
is_valid_entEnt ) )
        return 
PLUGIN_CONTINUE
    
    
if( gSoundFormat )
    {
        
client_cmd0"mp3 stop" )
        
client_cmd0"mp3 play sound/%s"gSound )
    }
    
    else
        
client_cmd0"spk sound/%s"gSound )
    
    
    
entity_set_floatEntEV_FL_nextthinkget_gametime( ) + gDuration )
    
    return 
PLUGIN_CONTINUE



I am about to try it, but just from looking at the code it doesnt look like it supports .wav files.

EDIT: Tried it, I get this error and my game crashes. COM_LoadFile:not enough space for /sound/ambience/music.wav

The plugin not support .wav files? I am about to try with a .mp3 file.

Is there a max amount of length the ambience sound can be? Mine is 3 minutes and 10 seconds, that might also be the problem?

EDIT AGAIN: MP3 doesnt 'work' but it doesnt crash my server either. I am ingame but no ambience music is playing...

Jon 11-05-2009 13:15

Re: Ambience Sound + Loop
 
Show me what you put in the file. It should support .wav.

Edit: I tested it and it works.

drumzplaya13 11-05-2009 13:18

Re: Ambience Sound + Loop
 
Quote:

Originally Posted by Jon (Post 981632)
Show me what you put in the file.


Old file before you fixed it.

Code:

;For mp3 files you need full path
;EXAMPLE:
;-For wavs use:
;de_dust2 ambience/ambience.wav 100
;-For mp3 use:
;de_dust2 sound/ambience/ambience.mp3 100

de_dust2_cz ambience/FaceClassicTheme.mp3 100

file now that it doesnt support .wav files it looks like...


Code:

;For mp3 files you need full path
;EXAMPLE:
;-For mp3 use:
;de_dust2 ambience/ambience.mp3 100

de_dust2_cz ambience/theme.mp3 190

my file is 3 minutes and 10 seconds so 190 seconds for the file.


All times are GMT -4. The time now is 17:32.

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