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:
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:
// Sound is played when the round ends. Often this means a team has won but it can also be a drawpublic 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 checkif(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 teamif(equali(textmsg, "#Terrorists_Win"))//Terrorists Wins
Victory(CS_TEAM_T);
elseif(equali(textmsg, "#CTs_Win"))//Counter-Terrorists Wins
Victory(CS_TEAM_CT);
elseif(equali(textmsg, "#Round_Draw"))//No one wins
Victory(CS_TEAM_UNASSIGNED);
elseif(equali(textmsg, "#Target_Bombed"))//C4 explodes, eliminates target
Victory(CS_TEAM_T);
elseif(equali(textmsg, "#Hostages_Not_Rescued"))//Time ran out and hostages not rescued
Victory(CS_TEAM_T);
elseif(equali(textmsg, "#VIP_Assassinated") || equali(textmsg, "#VIP_Not_Escaped"))//VIP killed or time ran out and VIP has not escaped
Victory(CS_TEAM_T);
elseif(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:
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 96public 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 teamstock 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 soundelse
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 tasksremove_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:
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:
I'm sorry. I don't understand any of it. If you're referring to how the 'startaction' sound begins to play after the player has moved then I'm sorry to say that I won't try to replicate that anytime soon. I'm trying to keep my plugin as simple as possible and finish it. Then I'll begin adding the fancy stuff.
Quote:
Originally Posted by addons_zz
Registering log events to each one of them seems more appropriate
I was thinking of a better way and thought trying to hook everything in the TeamScore event. But it keeps crashing. I'm using this:
Also, is a convention to use UPPERCASE letters for constants. Exemple:
Told you before, coding style should not be part of a review. You can give suggestions, but don't present them as general truth and a big deal. Such convention likely doesn't matter.
Being consistent is the only thing that matter regarding coding style.
Quote:
I do not see any comments on you code or documentation on your code.
They help to understand the system and to develop them. See what do you think about this mime.
Should not be part of a review, up to the coder.
Quote:
Let us see. This line:
Code:
client_cmd(id, "mp3 play ^"%s^"", WONROUND);
It is very repetitive and that is not good. I do it sometimes when I am not paying attention. But when I see them, I create a stock for them, or macro. On this case, a macro would fit good. I am thinking something like this:
It's a native call for God Sake, how it's not good? One should avoid duplicating code, but when it comes to a simple native call, there is nothing wrong. Creating a macro is stupid and could actually decrease readability.
Quote:
But, this message event stills existing:
register_message(get_user_msgid("TextMsg"), "Event_End_Round");
Why are you so turned on about this? Apart of function name not being the best choose, it's okay.
I did not read all, because you are mostly suggesting macros when there is no valid reason to do so or a simple private function would be likely more appropiate.
As I said before, plugin needs to be changed if you want it to be reviewed and approved. Since section needs to be cleaned I'll unapprove it for now. Do what I suggested in previous post and if you are not sure how to design this or need some help, ask.
As I said before, plugin needs to be changed if you want it to be reviewed and approved. Since section needs to be cleaned I'll unapprove it for now.
That's ok. I think it's for the best. It actually didn't occur to me that this belonged to those ideas that won't get approved. If I'd known, I wouldn't have submitted it.
I'd probably discontinue this here and move development some place else. I want to keep it simple for now, just trying to get a feel of making my own plugins from scratch so the config file feature is actually a far off goal for now.
Besides, regarding functionality, it works pretty great. I just can't get that TeamScore thingy to work. Would've made for cleaner code. Anyway, thanks, both of you. I still a learned a lot from this and that's never a bad thing...
Just because it's unapproved doesn't mean you should stop working on this.
Quote:
so the config file feature is actually a far off goal for now.
What are you waiting? Make it your current goal. If you never use new stuff you will never progress. Go on scripting help, read tutorials, ask here, whatever you need.
Just because it's unapproved doesn't mean you should stop working on this.
What are you waiting? Make it your current goal. If you never use new stuff you will never progress. Go on scripting help, read tutorials, ask here, whatever you need.
I will. It's just that a lot of stuff's actually going on in my life now: work, kids, some prospect for new business, trying to budget everything and what not. Coding time is mostly stolen time so it's hard for me to finish something. With just one plugin under my belt (thankfully, approved) finishing simple stuff would really give me some confidence and a sense of accomplishment. Then I can work around it and add more features.
Honestly, even in this 'simple' form, optimizing it has been complicated for me...
addons_zz:
Should not be part of a review, up to the coder.
You are right. It must not, it is boring. I just said it because he was beginning. I should explicated better what is what.
Quote:
Originally Posted by HamletEagle
It's a native call for God Sake, how it's not good? One should avoid duplicating code, but when it comes to a simple native call, there is nothing wrong. Creating a macro is stupid and could actually decrease readability.
Yes, it can deteriorate badly if overused/misused. On this case looked like good fitting.
Quote:
Originally Posted by HamletEagle
Why are you so turned on about this? Apart of function name not being the best choose, it's okay.
This is a often called event he is registering just to manually hook (by if's) round drawn, round end, etc.
I am just saying to hook the log_events as round_drawn, team_win, etc, instead use ifs on that more general and called event.
Quote:
Originally Posted by hellmonja
That's ok. I think it's for the best. It actually didn't occur to me that this belonged to those ideas that won't get approved. If I'd known, I wouldn't have submitted it.
I think you got it wrong, was good you submitted it. He is just saing that you plugin will be on another forum section until you finish it your work.
It is only/just a label to your work today. As your code evolves, its labels can evolves also.
Quote:
Originally Posted by hellmonja
Honestly, even in this 'simple' form, optimizing it has been complicated for me...
From my experience, everything I got done took lots of time to learn and apply.
You will work like 8 hours just to write a couple of new lines. Usually, some times you
write a lot, but later you delete almost all, because you find out how to generalize the a idea
and place it inside function/macro and use it elsewhere.
Welcome to the programming world. It is nothing like in the movies where the guy writes code on the light speed.
Settings are now individualized. Players can choose their kits mid game without affecting others.
You can now have up to 99 kits.
Flexible system that registers console commands by how many kits you have.
Various bugs and fixes.
I don't know how many of you get around Gamebanana, but I've uploaded this at GB a couple of days ago. It works fine and so far doing ok. But I came back here because I recognize it can still be improved. Therefore, I humbly offer this plugin at the mercy of the sages of Allied Modders...