As a complement of this snippet, and as you may want to hook new round but after player spawns, wrote that little snippet :
HLTV event is sent during new round, that's why it is used in plugins to detect new round and to reset some stuff.
PHP Code:
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
Players have not being spawned yet, they gonna be spawned in the same frame and in the same function (
CHalfLifeMultiplay::RestartRound (thanks Arkshine for CS-SDK) ).
So at HLTV event, only survivors are alive, dead player are not spawned yet, and anyway all players gonna be respawned.
So to add/remove weapons, hook Ham_Spawn seems to be the best way.
But if you have to choose a random player or something, you may need to wait for all players have being respawned.
You could :
- set a task (bad)
- wait for round start
PHP Code:
register_logevent("LogEvent_Round_Start", 2, "1=Round_Start")
This can be ok, but depending on freezetime length and depending on your needs, you may want to execute something earlier than at round start.
- hook something else that is called during CHalfLifeMultiplay::RestartRound but after players respawns.
Gonna put a snippet for this.
So, at the end of function CHalfLifeMultiplay::RestartRound, is called function CHalfLifeMultiplay::CleanUpMap, in which pfnPlaybackEvent (which is hookable with default amxx) is called with event "events/decal_reset.sc"
This is one of last steps of function CHalfLifeMultiplay::RestartRound
The only other steps after function CleanUpMap is to give c4 to a player (if map has bombsite of), and to reset some variables related to gamerules.
Basically we could only hook pfnPlaybackEvent and check if index is "events/decal_reset.sc" index, because decals are not reset anywhere else during the game :
PHP Code:
new m_usResetDecals
public plugin_init()
{
m_usResetDecals = playback_event(1, "events/decal_reset.sc")
}
public pfn_playbackevent(flags, entid, eventid /* , Float:delay, Float:Origin[3], Float:Angles[3], Float:fparam1, Float:fparam2, iparam1, iparam2, bparam1, bparam2 */ )
{
if( eventid == m_usResetDecals )
{
// put your code here
}
}
But considering some modules (orpheu, rage, ...) could call it and trigger our hook, we gonna add another check, we gonna store the game time when HLTV is called, and then compare to actual time when PlaybackEvent is called.
Engine way :
PHP Code:
#include <amxmodx>
#include <engine>
new m_usResetDecals
new Float:g_flNewRoundTime
public plugin_init()
{
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
m_usResetDecals = playback_event(1, "events/decal_reset.sc")
}
public Event_HLTV_New_Round()
{
g_flNewRoundTime = get_gametime()
}
public pfn_playbackevent(flags, entid, eventid /* , Float:delay, Float:Origin[3], Float:Angles[3], Float:fparam1, Float:fparam2, iparam1, iparam2, bparam1, bparam2 */ )
{
if( eventid == m_usResetDecals && !floatcmp(get_gametime(), g_flNewRoundTime) )
{
// you can count players here, select random player, etc...
}
}
Fakemeta way :
PHP Code:
#include <amxmodx>
#include <fakemeta>
new m_usResetDecals
new Float:g_flNewRoundTime
public plugin_init()
{
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
m_usResetDecals = engfunc(EngFunc_PrecacheEvent, 1, "events/decal_reset.sc")
register_forward(FM_PlaybackEvent, "OnPlaybackEvent")
}
public Event_HLTV_New_Round()
{
g_flNewRoundTime = get_gametime()
}
public OnPlaybackEvent(flags, entid, eventid /* , Float:delay, Float:Origin[3], Float:Angles[3], Float:fparam1, Float:fparam2, iparam1, iparam2, bparam1, bparam2 */ )
{
if( eventid == m_usResetDecals && !floatcmp(get_gametime(), g_flNewRoundTime) )
{
// you can count players here, select random player, etc...
}
}
Note : use register_forward at HLTV event and unregister_forward when PlaybackEvent is called seems to give strange results sometime, do like this if you want, but if you get un-expected behavior, remember this.
__________________