Raised This Month: $40 Target: $400
 10% 

New Round / Player Spawn / Round Start / Round End - do Not mess it


Post New Thread Reply   
 
Thread Tools Display Modes
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-14-2013 , 04:08   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #91

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(flagsentideventid /* , 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(flagsentideventid /* , 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_PrecacheEvent1"events/decal_reset.sc")
    
register_forward(FM_PlaybackEvent"OnPlaybackEvent")
}

public 
Event_HLTV_New_Round()
{
    
g_flNewRoundTime get_gametime()
}

public 
OnPlaybackEvent(flagsentideventid /* , 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.
__________________
- tired and retired -

Last edited by ConnorMcLeod; 04-14-2013 at 04:10.
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-14-2013 , 04:47   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #92

lol, while reading, I was going to say "whoa he forgot he could be called with modules", then, next line "But considering some modules.." . I guess it should be enough safe.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-14-2013 , 08:11   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #93

Other possible method is to hook FM_StartFrame on HLTV and to unhook when it is called, as VEN did in armoury invisibility plugin.
__________________
- tired and retired -
ConnorMcLeod is offline
avril-lavigne
Banned
Join Date: Apr 2009
Old 02-26-2014 , 15:35   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #94

In addition if you hook Bartime , \you ll also be able to catch player spawn
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-26-2014 , 16:50   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #95

Which is unreliable as hell, as resetting Bartime could be called from everywhere and unrelated to player's spawn. Better to stick to the most reliable way, hooking the virtual function itself using Ham_Spawn.
__________________
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-27-2014 , 13:04   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #96

Quote:
Originally Posted by avril-lavigne View Post
In addition if you hook Bartime , \you ll also be able to catch player spawn
what a great help
__________________
Accepting paid work for clans and communities. !Plugins & Models!
Don't hesitate to contact me.
bibu is offline
1ka
Senior Member
Join Date: Jun 2012
Old 01-25-2015 , 12:26   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #97

Please, I need "Server Start" event, (only start, not map change)
for log, "Server started at this time." logged only when started server.
__________________
Sorry for my bad english.

Last edited by 1ka; 01-25-2015 at 12:33.
1ka is offline
Old 02-16-2015, 08:33
blackkky
This message has been deleted by Brad. Reason: spamish
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:21.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode