Fixed ambience sound not always playing. Improved logging function.

This commit is contained in:
richard 2009-02-15 22:25:17 +01:00
parent 3fe0029543
commit 527bb9be44
5 changed files with 125 additions and 64 deletions

View File

@ -1,3 +1,7 @@
2009.02.15 - 2.5.1.x
* Fixed ambience sound not always playing. Changed ambience module to play a ambience sound per client, when they connect.
* Improved logging function.
2009.02.13 - 2.5.1.27
* Fixed bug in formatted log messages when client is negative or 0 (console).
* Simplified log formatting style.

View File

@ -172,6 +172,7 @@ public OnClientPutInServer(client)
}
RefreshList();
if (!IsFakeClient(client)) AmbienceStart(client);
}
public OnClientDisconnect(client)
@ -181,6 +182,7 @@ public OnClientDisconnect(client)
PlayerLeft(client);
ZTeleResetClient(client);
AmbienceStop(client);
for (new x = 0; x < MAXTIMERS; x++)
{
@ -200,7 +202,7 @@ MapChangeCleanup()
tRound = INVALID_HANDLE;
tInfect = INVALID_HANDLE;
tAmbience = INVALID_HANDLE;
AmbienceStopAll();
for (new client = 1; client <= maxclients; client++)
{

View File

@ -6,9 +6,10 @@
* ====================
*/
new bool:soundValid = false;
new Handle:tAmbience = INVALID_HANDLE;
new bool:AmbienceLoaded = false;
new String:AmbienceSound[64];
new Float:AmbienceVolume;
new Handle:tAmbience[MAXPLAYERS + 1] = {INVALID_HANDLE, ...};
LoadAmbienceData()
{
@ -19,79 +20,116 @@ LoadAmbienceData()
}
decl String:sound[64];
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], sound, sizeof(sound));
Format(sound, sizeof(sound), "sound/%s", sound);
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], AmbienceSound, sizeof(AmbienceSound));
Format(sound, sizeof(sound), "sound/%s", AmbienceSound);
soundValid = FileExists(sound, true);
AmbienceLoaded = FileExists(sound, true);
if (soundValid)
if (AmbienceLoaded)
{
AddFileToDownloadsTable(sound);
PrecacheSound(AmbienceSound);
AmbienceVolume = GetConVarFloat(gCvars[CVAR_AMBIENCE_VOLUME]);
if (AmbienceVolume <= 0.0)
{
// No reason to play ambience sound if it's muted.
AmbienceLoaded = false;
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_AMBIENCE)) ZR_LogMessageFormatted(-1, "ambience", "startup", "Ambience volume is muted or invalid.", LOG_FORMAT_TYPE_ERROR);
}
if (LogFlagCheck(LOG_DEBUG, LOG_MODULE_AMBIENCE)) ZR_LogMessageFormatted(-1, "ambience", "startup", "Ambience sound loaded.");
}
else
{
ZR_LogMessage("Ambient sound load failed", sound);
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_AMBIENCE))
{
decl String:log_message[256];
ZR_TranslateMessage(log_message, sizeof(log_message), "Ambience sound load failed", sound);
ZR_LogMessageFormatted(-1, "ambience", "startup", log_message, true);
}
}
}
RestartAmbience()
AmbienceStart(client)
{
if (tAmbience != INVALID_HANDLE)
{
CloseHandle(tAmbience);
}
CreateTimer(0.0, AmbienceLoop, _, TIMER_FLAG_NO_MAPCHANGE);
}
public Action:AmbienceLoop(Handle:timer)
{
new bool:ambience = GetConVarBool(gCvars[CVAR_AMBIENCE]);
if (!ambience || !soundValid)
if (!AmbienceLoaded)
{
return;
}
decl String:sound[64];
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], sound, sizeof(sound));
EmitAmbience(sound);
new Float:delay = GetConVarFloat(gCvars[CVAR_AMBIENCE_LENGTH]);
tAmbience = CreateTimer(delay, AmbienceLoop, _, TIMER_FLAG_NO_MAPCHANGE);
}
StopAmbience()
{
new bool:ambience = GetConVarBool(gCvars[CVAR_AMBIENCE]);
if (!ambience)
{
return;
}
decl String:sound[64];
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], sound, sizeof(sound));
new maxplayers = GetMaxClients();
for (new x = 1; x <= maxplayers; x++)
new Float:delay = GetConVarFloat(gCvars[CVAR_AMBIENCE_LENGTH]);
if (delay <= 0.0)
{
if (!IsClientInGame(x))
return;
}
if (!IsClientConnected(client) || !IsClientInGame(client))
{
return;
}
if (LogFlagCheck(LOG_DEBUG, LOG_MODULE_AMBIENCE)) ZR_LogMessageFormatted(client, "ambience", "start", "Starting ambience on client %d...", _, client);
AmbiencePlay(client);
tAmbience[client] = CreateTimer(delay, AmbienceTimer, client, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
}
AmbienceStop(client)
{
if (tAmbience[client] != INVALID_HANDLE)
{
KillTimer(tAmbience[client]);
tAmbience[client] = INVALID_HANDLE;
if (IsClientConnected(client) && IsClientInGame(client))
{
continue;
StopSound(client, SNDCHAN_AUTO, AmbienceSound);
}
StopSound(x, SNDCHAN_AUTO, sound);
}
}
EmitAmbience(const String:sound[])
AmbienceStopAll()
{
PrecacheSound(sound);
for (new client = 1; client < maxclients; client++)
{
AmbienceStop(client);
}
}
AmbienceRestart(client)
{
AmbienceStop(client);
AmbienceStart(client);
}
AmbienceRestartAll()
{
for (new client = 1; client < maxclients; client++)
{
AmbienceRestart(client);
}
}
public Action:AmbienceTimer(Handle:timer, any:client)
{
new bool:ambience = GetConVarBool(gCvars[CVAR_AMBIENCE]);
if (!ambience || !AmbienceLoaded)
{
KillTimer(tAmbience[client]);
tAmbience[client] = INVALID_HANDLE;
return;
}
StopAmbience();
new Float:volume = GetConVarFloat(gCvars[CVAR_AMBIENCE_VOLUME]);
EmitSoundToAll(sound, SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, volume, SNDPITCH_NORMAL, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
AmbiencePlay(client);
}
AmbiencePlay(client)
{
EmitSoundToClient(client, AmbienceSound, SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, AmbienceVolume, SNDPITCH_NORMAL, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
if (LogFlagCheck(LOG_DEBUG, LOG_MODULE_AMBIENCE)) ZR_LogMessageFormatted(client, "ambience", "play", "Playing ambience sound on client %d.", _, client);
}

View File

@ -33,9 +33,7 @@ UnhookEvents()
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
ChangeLightStyle();
RestartAmbience();
AmbienceRestartAll();
RefreshList();
if (tRound != INVALID_HANDLE)

View File

@ -6,6 +6,10 @@
* ====================
*/
#define LOG_FORMAT_TYPE_SIMPLE 0 // Simple log message, no module or block info.
#define LOG_FORMAT_TYPE_FULL 1 // Full log message, with module and block info.
#define LOG_FORMAT_TYPE_ERROR 2 // Full log message, but log to error log instead.
FormatTextString(String:text[], maxlen)
{
Format(text, maxlen, "@green[%t] @default%s", "ZR", text);
@ -105,7 +109,13 @@ stock ZR_LogMessage(any:...)
LogMessage(phrase);
}
stock ZR_LogMessageFormatted(client, const String:module[], const String:block[], const String:message[], bool:full = false, any:...)
stock ZR_TranslateMessage(String:buffer[], maxlen, any:...)
{
SetGlobalTransTarget(LANG_SERVER);
VFormat(buffer, maxlen, "%t", 3);
}
stock ZR_LogMessageFormatted(client, const String:module[], const String:block[], const String:message[], type = LOG_FORMAT_TYPE_FULL, any:...)
{
decl String:buffer[2048];
decl String:text[2048];
@ -115,15 +125,26 @@ stock ZR_LogMessageFormatted(client, const String:module[], const String:block[]
return;
}
if (full)
switch (type)
{
VFormat(buffer, sizeof(buffer), message, 6);
Format(text, sizeof(text), "Log (%s : %s) -- %s", module, block, buffer);
}
else
{
VFormat(buffer, sizeof(buffer), message, 6);
Format(text, sizeof(text), "Log -- %s", message);
case LOG_FORMAT_TYPE_SIMPLE:
{
VFormat(buffer, sizeof(buffer), message, 6);
Format(text, sizeof(text), "Log -- %s", message);
LogMessage(text);
}
case LOG_FORMAT_TYPE_FULL:
{
VFormat(buffer, sizeof(buffer), message, 6);
Format(text, sizeof(text), "Log (%s : %s) -- %s", module, block, buffer);
LogMessage(text);
}
case LOG_FORMAT_TYPE_ERROR:
{
VFormat(buffer, sizeof(buffer), message, 6);
Format(text, sizeof(text), "Log (%s : %s) -- %s", module, block, buffer);
LogError(text);
}
}
if (LogHasFlag(LOG_TO_ADMINS))
@ -134,8 +155,6 @@ stock ZR_LogMessageFormatted(client, const String:module[], const String:block[]
{
PrintToConsole(client, "[ZR] %s", text);
}
LogMessage(text);
}
stock ZR_ReplyToCommand(client, any:...)