New Round / Player Spawn / Round Start / Round End - do Not mess it
Intro
I posting this because i saw so numerous mistakes/questions at this area of srcipting. This is the one of the common problems amongst the coders and even not only beginners! New Round / Player Spawn / Round Start / Round End is a different things so read the below explanations and do not mess them. Usual call order of the events is listed below:
1. New Round The "New Round" is happen at the "Freeze Time" start. The "Freeze Time" is a time in Counter-Strike when all players are "freezed" which means that they can't walk and do a primary attacks. In the past years the most common way that was used to determine this event was the use of the "RoundTime" event with a "Time" message argument check, but there was a certain issues which makes this metod inefficient:
PHP Code:
Note that this event is not called for very first round, i.e. on map start. If you need to catch that moment as well then in the most cases it's enough to use the plugin_init() or plugin_cfg() forward functions. Also i was amazed at how many mistakes was made even by the "expirienced" coders in try to detect the "New Round"! The most common mistake was: PHP Code:
2. Player Spawn I think no need to explain what the "Player Spawn" is. But many of the coders still do not know how to detect this event correctly. If you are using AMX Mod X v1.8 or higher, or if you have the "Ham Sandwich" module installed the most simple and efficient way of the "Player Spawn" detection is a hook of the "Spawn" function itself: PHP Code:
PHP Code:
You should note that the use of that method may even lead to a server crash. It could happen because the plugin actions is performed on a player in the middle of his spawn process. The example of such "dangerous" action is a call of the strip_user_weapons() fun module's function. Many of plugin writers does know that the "ResetHUD" event is called on a player spawn but not all of them does know that this event is also called when a player is enter a server (at least in Counter-Strike), on "fullupdate" client command execution, demo recording and round restart attempt (on Counter-Strike's "sv_restartround" / "sv_restart" CVar change for alive players). So to use the "ResetHUD" to detect the "Player Spawn" we will need to filter out all that actions. The moment when a player is joined a server can be filtered out by registering the "ResetHUD" event with a "e" flag which means that the registered function will be called on alive players. Note that sometimes that "e" flag will also allow a calls of the registered function on a dead players as well (this is a bug of the AMX Mod X core that has been fixed in version 1.80). So it's recommended to do the "alive" check inside of the registered function itself. The execution of the "fullupdate" client command and the start of a demo recording can be filtered out by blocking the command: PHP Code:
As for round restart attempt, probably some of you does think that it's not necessary to filter this event out because it's always called right before "New Round". This is incorrect - not always, it's possible to set "sv_restartround" / "sv_restart" CVar value for example to 60 so new round will be delayed for one full minute! Therefore to filter this out as well on round restart attempt for every alive player we will have to skip the call of the registered to the "ResetHUD" event function. The result code that is able to detect the "Player Spawn" is shown below: PHP Code:
3. Round Start The "Round Start" is happen at the "Freeze Time" end. Many of the coders does think that the "Round Start" and "New Round" is the same event and doing a things that is related to the "New Round" in "Round Start" but this is incorrect. Some of the coders especially in the past have used the "RoundTime" event to detect the "Round Start", but again this is inefficient method (the details can be found in the "New Round" section of the article). The correct method that can be used to detect the "Round Start" is shown below: PHP Code:
4. Round End The "Round End" is happen right at the moment when one of the teams is completed objectives: all players in the opposite team is killed, all hostages is rescued, time of the round is up, etc. Some of the coders does think that the "Round End" and "New Round" is the same event and doing a things that is related to the "New Round" in the "Round End" but this is incorrect. The correct method that can be used to detect the "Round End" is shown below: PHP Code:
Still confused? Still confused and don't really sure which from the above events should be used in your plugin? Review the below examples that may help you to understand the things better.
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
*Clap clap clap* :D
Thanks, I was wondering why ResetHUD activated so many times, (I added some print_console, and logs to show debug msg's, they kept popping up, several times over.) :P |
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
Ughhh... I'd wish to know who was that guy who gave to the AMX/X coders this line:
Code:
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
nice tut VEN :)
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
I've been looking for clarification on this topic. It's nice to see someone took the time to lay it out for us. Is it worthy of a wiki entry?
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
Quote:
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
Quote:
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
For those of you that use fakemeta, you can do this:
Code:
Never tested this before though, so someone let me know if I'm wrong. |
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
Does not work AFAIK
|
Re: New Round/Player Spawn/Round Start/Round End - do Not mess it
AFAIK?
|
All times are GMT -4. The time now is 10:50. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.