Author
|
Message
|
Veteran Member
Join Date: Jan 2012
Location: Russia
|
12-01-2016
, 10:10
Right way of gameevents
|
#1
|
Hellow, somebody can help me pls, do i use event hook in right way or i need add additional include to code? or it wrong method? I need it for CS:GO. Thanks a million
extension.cpp
Spoiler
PHP Code:
#include "events.hpp"
// Global server variables bool g_IsNewRound = false; bool g_IsEndRound = false; bool g_IsOnRound = false;
RoundStart g_OnRoundStart; RoundEnd g_OnRoundEnd;
IGameEventManager2 *gameevents = NULL;
void ZombiePlague::SDK_OnLoad() { HookEvents(); }
void ZombiePlague::SDK_OnUnload() { HookEvents(true); }
void ZombiePlague::HookEvents(bool UnHook = false) { if(UnHook) { gameevents->RemoveListener(&g_OnRoundStart); gameevents->RemoveListener(&g_OnRoundEnd); return; } gameevents->AddListener(&g_OnRoundStart, "round_prestart", true); gameevents->AddListener(&g_OnRoundEnd, "round_end", true); }
events.hpp
Spoiler
PHP Code:
/** * vim: set ts=4 : * ============================================================================= * SourceMod Sample Extension * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 3.0, as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. * * As a special exception, AlliedModders LLC gives you permission to link the * code of this program (as well as its derivative works) to "Half-Life 2," the * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * by the Valve Corporation. You must obey the GNU General Public License in * all respects for all other code used. Additionally, AlliedModders LLC grants * this exception to all derivative works. AlliedModders LLC defines further * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * or <http://www.sourcemod.net/license.php>. * * Version: $Id$ */
#ifndef _INCLUDE_SOURCEMOD_EVENTS_H_ #define _INCLUDE_SOURCEMOD_EVENTS_H_
/** * @file extension.h * @brief Main extension code header. */
#include "extension.h"
/** * @brief Event callback (round_prestart). */ class RoundStart : public IGameEventListener2 { int GetEventDebugID(void) { return EVENT_DEBUG_ID_INIT; } void FireGameEvent(IGameEvent* pEvent) { // Reset server grobal bools g_IsNewRound = true; g_IsEndRound = false; g_IsOnRound = false; } };
/** * @brief Event callback (round_end). */ class RoundEnd : public IGameEventListener2 { int GetEventDebugID(void) { return EVENT_DEBUG_ID_INIT; } void FireGameEvent(IGameEvent* pEvent) { // Reset server grobal bools g_IsNewRound = false; g_IsEndRound = true; g_IsOnRound = false; } };
#endif
or just use that method
extension.cpp
Spoiler
PHP Code:
#define HOOK_EVENT2(name) \ if (!gameevents->AddListener(&g_cls_event_##name, #name, true)) { \ snprintf(error, maxlength, "Could not hook event \"%s\"", #name); \ return false; \ }
#define UNHOOK_EVENT2(name) gameevents->RemoveListener(&g_cls_event_##name);
#define DECLARE_EVENT(name) \ class cls_event_##name : public IGameEventListener2 \ { \ public: \ virtual void FireGameEvent(IGameEvent *event); \ virtual int GetEventDebugID( void ) { return EVENT_DEBUG_ID_INIT; } \ }; \ extern cls_event_##name g_cls_event_##name;
#define IMPLEMENT_EVENT(name) \ cls_event_##name g_cls_event_##name; \ void cls_event_##name::FireGameEvent(IGameEvent *event)
#include "events.hpp"
// Global server variables bool g_IsNewRound = false; bool g_IsEndRound = false; bool g_IsOnRound = false;
IGameEventManager2 *gameevents = NULL;
void ZombiePlague::SDK_OnLoad() { HookEvents(); }
void ZombiePlague::SDK_OnUnload() { HookEvents(true); }
void ZombiePlague::HookEvents(bool UnHook = false) { if(UnHook) { UNHOOK_EVENT2(round_prestart); UNHOOK_EVENT2(round_end); return; } HOOK_EVENT2(round_prestart); HOOK_EVENT2(round_end); }
events.hpp
Spoiler
PHP Code:
/** * vim: set ts=4 : * ============================================================================= * SourceMod Sample Extension * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 3.0, as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. * * As a special exception, AlliedModders LLC gives you permission to link the * code of this program (as well as its derivative works) to "Half-Life 2," the * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * by the Valve Corporation. You must obey the GNU General Public License in * all respects for all other code used. Additionally, AlliedModders LLC grants * this exception to all derivative works. AlliedModders LLC defines further * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * or <http://www.sourcemod.net/license.php>. * * Version: $Id$ */
#ifndef _INCLUDE_SOURCEMOD_EVENTS_H_ #define _INCLUDE_SOURCEMOD_EVENTS_H_
/** * @file extension.h * @brief Main extension code header. */
#include "extension.h"
DECLARE_EVENT(round_prestart); DECLARE_EVENT(round_end) /** * @brief Event callback (round_prestart). */ IMPLEMENT_EVENT(round_prestart) { // Reset server grobal bools g_IsNewRound = true; g_IsEndRound = false; g_IsOnRound = false; }
/** * @brief Event callback (round_end). */ IMPLEMENT_EVENT(round_end) { // Reset server grobal bools g_IsNewRound = false; g_IsEndRound = true; g_IsOnRound = false; }
#endif
Which of those will better for CS:GO?
__________________
Last edited by gubka; 12-01-2016 at 10:39.
|
|
|
|