Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
|
07-14-2016
, 11:10
Re: CS:GO Music Kit
|
#12
|
Quote:
Originally Posted by hellmonja
I know how you guys hate hardcoding but I had to hardcode variable sounds' character length for now. When I use charmax() is gives me errors. (line 237)
|
I just used charsmax and compiles. Note, you used the sound as sound[40], and when formatting it:
Code:
formatex(sound, 40, "%s%s", FOLDER[iFolder], WONROUND);
It is not 40, it is 39 because one last space is used always as '^0' to determine the end of the string.
40 is also a little to critic, because you are using things bigger as 38 chars, them it almost do not fit in.
And as it is supposed in the future let the users to configure the sounds by config files, would be nice to allow
them to write paths as big as 96 or 128 characters length.
Spoiler
Quote:
Originally Posted by hellmonja
- Made 'iFolder' global and it is set every New Round
|
Looks nice, so now I do not listen to the same sound every time on new rounds.
Quote:
Originally Posted by hellmonja
I did the stuff you asked and took some liberties of my own:
|
Sure, everything as mostly examples just to give you the idea, as text is mostly ambiguous and open mostly to interpretations and some times automatic translators problems.
Quote:
Originally Posted by hellmonja
- I put the task removers on End Round instead of New Round in case the task runs after round has ended
|
Good thing.
Quote:
Originally Posted by addons_zz
This line below is not the round end event. It is called very more often than that:
Code:
register_message(get_user_msgid("TextMsg"), "Event_End_Round");
|
But, this message event stills existing:
Code:
// Sound is played when the round ends. Often this means a team has won but it can also be a draw
public Event_End_Round(id)
{
if(get_pcvar_num(cvar_musickit_on) == 0)
return
// The 1st round is when players are still connecting and game has not commenced. To prevent the sound from playing after that, we do this check
if(bool_firstround == 1)
{
bool_firstround = 0;
return
}
// We get what type of End Round we get...
static textmsg[22];
get_msg_arg_string(2, textmsg, charsmax(textmsg));
//...and play the appropriate sound to each player according to their team
if(equali(textmsg, "#Terrorists_Win")) //Terrorists Wins
Victory(CS_TEAM_T);
else if(equali(textmsg, "#CTs_Win")) //Counter-Terrorists Wins
Victory(CS_TEAM_CT);
else if(equali(textmsg, "#Round_Draw")) //No one wins
Victory(CS_TEAM_UNASSIGNED);
else if(equali(textmsg, "#Target_Bombed")) //C4 explodes, eliminates target
Victory(CS_TEAM_T);
else if(equali(textmsg, "#Hostages_Not_Rescued")) //Time ran out and hostages not rescued
Victory(CS_TEAM_T);
else if(equali(textmsg, "#VIP_Assassinated") || equali(textmsg, "#VIP_Not_Escaped")) //VIP killed or time ran out and VIP has not escaped
Victory(CS_TEAM_T);
else if(equali(textmsg, "#VIP_Escaped")) //VIP escapes
Victory(CS_TEAM_CT);
}
Registering log events to each one of them seems more appropriate then several if/else's on a general event as 'register_message(get_user_msgid("TextMsg")'.
Example:
Code:
public plugin_init()
{
register_logevent("Event_Draw" , 4, "1=Round_Draw")
register_logevent("Event_Target_Bombed", 6, "3=Target_Bombed")
...
}
public Event_Draw()
{
Victory(CS_TEAM_UNASSIGNED);
}
public Event_Target_Bombed()
{
Victory(CS_TEAM_T);
}
...
You can also format the sound before call 'Victory(1)', them you can set a different sound for each type/kind of victory. Example:
Code:
#define MAX_SOUND_PATH 96
public Event_Draw()
{
new wonSound [MAX_SOUND_PATH]
new lostSound[MAX_SOUND_PATH]
formatex(wonSound, charsmax(wonSound), "%s%s", FOLDER[iFolder], WONROUND_DRAW);
formatex(lostSound,charsmax(lostSound), "%s%s", FOLDER[iFolder], LOSTROUND_DRAW);
Victory(CS_TEAM_UNASSIGNED, wonSound, lostSound);
}
public Event_TerroristWin()
{
new wonSound [MAX_SOUND_PATH]
new lostSound[MAX_SOUND_PATH]
formatex(wonSound, charsmax(wonSound), "%s%s", FOLDER[iFolder], WONROUND_BOMB);
formatex(lostSound,charsmax(lostSound), "%s%s", FOLDER[iFolder], LOSTROUND_BOMB);
Victory(CS_TEAM_T, wonSound, lostSound);
}
// Function that plays 'victory' or 'losing' sounds for each team
stock Victory(CsTeams:winning_team, winnerSound[], loserSound[])
{
if(winning_team) // If one team wins
{
new players[32], id, pnum;
get_players(players, pnum, "c");
for(new i = 0; i < pnum; i++) // Cycling thru all players in-game
{
id = players[i];
// We format the name of the sound file by merging two strings:
// the set destination folder and the name of the mp3 file itself and saves it in 'sound' variable...
if(cs_get_user_team(id) == winning_team)
PLAY_ENDROUND_SOUND(id, winnerSound); // ...then uses that variable to play out sound
else
PLAY_ENDROUND_SOUND(id, loserSound); // ...then uses that variable to play out sound
}
}
else // When no one wins, everybody loses
{
PLAY_ENDROUND_SOUND(0, loserSound);
}
// Removing set tasks
remove_task(TASKID_ROUND_TEN);
remove_task(TASKID_BOMB_TEN);
// Resetting values for next round
bool_endofround = 1;
bool_bomb_planted = 0;
}
Which could be a macro, to save repeating code everywhere:
Code:
#define MAX_SOUND_PATH 96
/**
* To format the sound properly. It creates to new variables 'wonSound[MAX_SOUND_PATH]' and
* 'lostSound[MAX_SOUND_PATH]' to be used as the win and lost sounds.
*
* @param folderPrefix
* @param winnerSound
* @param loserSound
*/
#define FORMAT_SOUND(%1,%2,%3) \
new wonSound [MAX_SOUND_PATH]; \
new lostSound[MAX_SOUND_PATH]; \
formatex(wonSound, charsmax(wonSound), "%s%s", %1, %2); \
formatex(lostSound,charsmax(lostSound), "%s%s", %1, %3)
public Event_Draw()
{
FORMAT_SOUND(FOLDER[iFolder], WONROUND_DRAW, LOSTROUND_DRAW);
Victory(CS_TEAM_UNASSIGNED, wonSound, lostSound);
}
public Event_TerroristWin()
{
FORMAT_SOUND(FOLDER[iFolder], WONROUND_BOMB, LOSTROUND_BOMB);
Victory(CS_TEAM_T, wonSound, lostSound);
}
Update:
Just remenber, this kind of macro cannot be used on open if, while, etc.
Example:
Code:
if( win )
FORMAT_SOUND(FOLDER[iFolder], WONROUND_BOMB, LOSTROUND_BOMB);
else
FORMAT_SOUND(FOLDER[iFolder], WONROUND, LOSTROUND);
Because it would expand to:
Code:
if( win )
new wonSound [MAX_SOUND_PATH];
new lostSound[MAX_SOUND_PATH];
formatex(wonSound, charsmax(wonSound), "%s%s", FOLDER[iFolder], WONROUND_BOMB);
formatex(lostSound,charsmax(lostSound), "%s%s", FOLDER[iFolder], LOSTROUND_BOMB);
else
new wonSound [MAX_SOUND_PATH];
new lostSound[MAX_SOUND_PATH];
formatex(wonSound, charsmax(wonSound), "%s%s", FOLDER[iFolder], WONROUND);
formatex(lostSound,charsmax(lostSound), "%s%s", FOLDER[iFolder], LOSTROUND);
Which is wrong for two things.
First, you are doing new 'wonSound' and 'lostSound' on the if scope, then you cannot you it out of it.
Second, there are missing braces the if and else body.
The second problem ca be solved, doing like this:
Code:
#define MAX_SOUND_PATH 96
new const bool:g_dummy_value = false;
#define FORMAT_SOUND(%1,%2,%3) \
do \
{ \
new wonSound [MAX_SOUND_PATH]; \
new lostSound[MAX_SOUND_PATH]; \
formatex(wonSound, charsmax(wonSound), "%s%s", %1, %2); \
formatex(lostSound,charsmax(lostSound), "%s%s", %1, %3); \
} while( g_dummy_value )
But the first problem, is not that easy, it would require to take out the new's form the macro, and do it by yourself.
Example:
Code:
#define MAX_SOUND_PATH 96
new const bool:g_dummy_value = false;
#define FORMAT_SOUND(%1,%2,%3) \
do \
{ \
formatex(wonSound, charsmax(wonSound), "%s%s", %1, %2); \
formatex(lostSound,charsmax(lostSound), "%s%s", %1, %3); \
} while( g_dummy_value )
new wonSound [MAX_SOUND_PATH];
new lostSound[MAX_SOUND_PATH];
if( win )
FORMAT_SOUND(FOLDER[iFolder], WONROUND_BOMB, LOSTROUND_BOMB);
else
FORMAT_SOUND(FOLDER[iFolder], WONROUND, LOSTROUND);
__________________
Last edited by addons_zz; 07-19-2016 at 20:56.
Reason: update boring
|
|