Raised This Month: $12 Target: $400
 3% 

Proper File Download and Usage


Post New Thread Reply   
 
Thread Tools Display Modes
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
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 05-01-2009 , 19:52   Re: Proper File Download and Usage
Reply With Quote #2

Very useful, awesome post.
__________________
msleeper is offline
Cooltad
Veteran Member
Join Date: Apr 2008
Old 05-01-2009 , 20:01   Re: Proper File Download and Usage
Reply With Quote #3

It's mainly for if people have trouble using sound plugins like I have, or download and precache plugins. For me and many others, the current plugins available for those things are not 100% and don't work for everyone.

This, however, will always work without bugs.

Maybe it's not as easy as an already-made plugin, but I personally think it's better for everyone to know how to modify plugins to an extent.
__________________
Please, give me some rep if you found what I posted useful. :]
Cooltad is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-01-2009 , 20:09   Re: Proper File Download and Usage
Reply With Quote #4

To check if the client disconnecting is a bot, you could probably do if(IsFakeClient(client)) to check. If that doesnt work, you can just store the bots indexes in an array, and check if the client disconnecting was one of them. I think the original method will work, but I vaguely remember not being able to do much with the clients index on disconnect events.
__________________
CrimsonGT is offline
Cooltad
Veteran Member
Join Date: Apr 2008
Old 05-01-2009 , 20:11   Re: Proper File Download and Usage
Reply With Quote #5

Well, I am currently using that original method, but I was just wondering if there was more to do. So far I haven't had any error problems with it, though.
__________________
Please, give me some rep if you found what I posted useful. :]
Cooltad 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 15:40.


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