Fixed ambience sound not always playing. Improved logging function.
This commit is contained in:
parent
3fe0029543
commit
527bb9be44
|
@ -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
|
2009.02.13 - 2.5.1.27
|
||||||
* Fixed bug in formatted log messages when client is negative or 0 (console).
|
* Fixed bug in formatted log messages when client is negative or 0 (console).
|
||||||
* Simplified log formatting style.
|
* Simplified log formatting style.
|
||||||
|
|
|
@ -172,6 +172,7 @@ public OnClientPutInServer(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshList();
|
RefreshList();
|
||||||
|
if (!IsFakeClient(client)) AmbienceStart(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnClientDisconnect(client)
|
public OnClientDisconnect(client)
|
||||||
|
@ -181,6 +182,7 @@ public OnClientDisconnect(client)
|
||||||
|
|
||||||
PlayerLeft(client);
|
PlayerLeft(client);
|
||||||
ZTeleResetClient(client);
|
ZTeleResetClient(client);
|
||||||
|
AmbienceStop(client);
|
||||||
|
|
||||||
for (new x = 0; x < MAXTIMERS; x++)
|
for (new x = 0; x < MAXTIMERS; x++)
|
||||||
{
|
{
|
||||||
|
@ -200,7 +202,7 @@ MapChangeCleanup()
|
||||||
|
|
||||||
tRound = INVALID_HANDLE;
|
tRound = INVALID_HANDLE;
|
||||||
tInfect = INVALID_HANDLE;
|
tInfect = INVALID_HANDLE;
|
||||||
tAmbience = INVALID_HANDLE;
|
AmbienceStopAll();
|
||||||
|
|
||||||
for (new client = 1; client <= maxclients; client++)
|
for (new client = 1; client <= maxclients; client++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
* ====================
|
* ====================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
new bool:soundValid = false;
|
new bool:AmbienceLoaded = false;
|
||||||
|
new String:AmbienceSound[64];
|
||||||
new Handle:tAmbience = INVALID_HANDLE;
|
new Float:AmbienceVolume;
|
||||||
|
new Handle:tAmbience[MAXPLAYERS + 1] = {INVALID_HANDLE, ...};
|
||||||
|
|
||||||
LoadAmbienceData()
|
LoadAmbienceData()
|
||||||
{
|
{
|
||||||
|
@ -19,79 +20,116 @@ LoadAmbienceData()
|
||||||
}
|
}
|
||||||
|
|
||||||
decl String:sound[64];
|
decl String:sound[64];
|
||||||
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], sound, sizeof(sound));
|
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], AmbienceSound, sizeof(AmbienceSound));
|
||||||
Format(sound, sizeof(sound), "sound/%s", sound);
|
Format(sound, sizeof(sound), "sound/%s", AmbienceSound);
|
||||||
|
|
||||||
soundValid = FileExists(sound, true);
|
AmbienceLoaded = FileExists(sound, true);
|
||||||
|
|
||||||
if (soundValid)
|
if (AmbienceLoaded)
|
||||||
{
|
{
|
||||||
AddFileToDownloadsTable(sound);
|
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
|
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)
|
if (!AmbienceLoaded)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
return;
|
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]);
|
new bool:ambience = GetConVarBool(gCvars[CVAR_AMBIENCE]);
|
||||||
|
|
||||||
if (!ambience)
|
if (!ambience)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
decl String:sound[64];
|
new Float:delay = GetConVarFloat(gCvars[CVAR_AMBIENCE_LENGTH]);
|
||||||
GetConVarString(gCvars[CVAR_AMBIENCE_FILE], sound, sizeof(sound));
|
if (delay <= 0.0)
|
||||||
|
|
||||||
new maxplayers = GetMaxClients();
|
|
||||||
for (new x = 1; x <= maxplayers; x++)
|
|
||||||
{
|
{
|
||||||
if (!IsClientInGame(x))
|
return;
|
||||||
{
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
StopSound(x, SNDCHAN_AUTO, sound);
|
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))
|
||||||
|
{
|
||||||
|
StopSound(client, SNDCHAN_AUTO, AmbienceSound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EmitAmbience(const String:sound[])
|
AmbienceStopAll()
|
||||||
{
|
{
|
||||||
PrecacheSound(sound);
|
for (new client = 1; client < maxclients; client++)
|
||||||
|
{
|
||||||
StopAmbience();
|
AmbienceStop(client);
|
||||||
|
}
|
||||||
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);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
|
@ -33,9 +33,7 @@ UnhookEvents()
|
||||||
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
|
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
|
||||||
{
|
{
|
||||||
ChangeLightStyle();
|
ChangeLightStyle();
|
||||||
|
AmbienceRestartAll();
|
||||||
RestartAmbience();
|
|
||||||
|
|
||||||
RefreshList();
|
RefreshList();
|
||||||
|
|
||||||
if (tRound != INVALID_HANDLE)
|
if (tRound != INVALID_HANDLE)
|
||||||
|
|
|
@ -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)
|
FormatTextString(String:text[], maxlen)
|
||||||
{
|
{
|
||||||
Format(text, maxlen, "@green[%t] @default%s", "ZR", text);
|
Format(text, maxlen, "@green[%t] @default%s", "ZR", text);
|
||||||
|
@ -105,7 +109,13 @@ stock ZR_LogMessage(any:...)
|
||||||
LogMessage(phrase);
|
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:buffer[2048];
|
||||||
decl String:text[2048];
|
decl String:text[2048];
|
||||||
|
@ -115,15 +125,26 @@ stock ZR_LogMessageFormatted(client, const String:module[], const String:block[]
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (full)
|
switch (type)
|
||||||
{
|
{
|
||||||
VFormat(buffer, sizeof(buffer), message, 6);
|
case LOG_FORMAT_TYPE_SIMPLE:
|
||||||
Format(text, sizeof(text), "Log (%s : %s) -- %s", module, block, buffer);
|
{
|
||||||
}
|
VFormat(buffer, sizeof(buffer), message, 6);
|
||||||
else
|
Format(text, sizeof(text), "Log -- %s", message);
|
||||||
{
|
LogMessage(text);
|
||||||
VFormat(buffer, sizeof(buffer), message, 6);
|
}
|
||||||
Format(text, sizeof(text), "Log -- %s", message);
|
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))
|
if (LogHasFlag(LOG_TO_ADMINS))
|
||||||
|
@ -134,8 +155,6 @@ stock ZR_LogMessageFormatted(client, const String:module[], const String:block[]
|
||||||
{
|
{
|
||||||
PrintToConsole(client, "[ZR] %s", text);
|
PrintToConsole(client, "[ZR] %s", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogMessage(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stock ZR_ReplyToCommand(client, any:...)
|
stock ZR_ReplyToCommand(client, any:...)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user