Raised This Month: $ Target: $400
 0% 

Proper File Download and Usage


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Cooltad
Veteran Member
Join Date: Apr 2008
Old 05-01-2009 , 19:43   Proper File Download and Usage
Reply With Quote #1

This snippet is mainly for sound files and playing them, but can be applied in theory to other files and actions.
Code:
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>
#define MAX_FILE_LEN 80
new Handle:g_CvarSoundName9 = INVALID_HANDLE;
new String:g_soundName9[MAX_FILE_LEN];

public OnPluginStart()
{
    g_CvarSoundName9 = CreateConVar("sm_join_sound9", "t3clan_custom/end1.mp3", "");
	HookEvent("round_end", RoundEndEvent);
}

public OnMapStart()
{
    GetConVarString(g_CvarSoundName9, g_soundName9, MAX_FILE_LEN);
    decl String:buffer9[MAX_FILE_LEN];
    PrecacheSound(g_soundName9, true);
    Format(buffer9, sizeof(buffer9), "sound/%s", g_soundName9);
    AddFileToDownloadsTable(buffer9);

//OR if precaching an existing sound that's not needing to be downloaded:
    PrecacheSound("player/crit_hit4.wav");
}

public Action:RoundEndEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    for(new i = 1; i <= GetMaxClients(); i++)
    if(IsClientInGame(i) && !IsFakeClient(i))
    {
        EmitSoundToClient(i,g_soundName9, SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_NORMAL);
    }
}

public OnEventShutdown()
{
	UnhookEvent("round_end", RoundEndEvent);
}
Oh, and I was wondering, does anyone know how to check for when a bot disconnects? Or rather, that the client that left the game is not a bot?

Also, it seems that if you precache the sound, it doesn't matter what kbps is has, channel, etc, It will play it (that I know of so far) if it's either .wav or .mp3, haven't tried any other type.
This code could also be useful if you wanna force the download and precache of a certain sound file, then have modified sound_weapon etc file to change the sound on a specific weapon action.
__________________
Please, give me some rep if you found what I posted useful. :]
Cooltad is offline
 



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 18:09.


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