Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_event_state and get_logevent_state natives #821

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions amxmodx/CEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ void EventsMngr::ClEvent::setForwardState(ForwardState state)
m_State = state;
}

ForwardState EventsMngr::ClEvent::getForwardState()
{
return m_State;
}

int EventsMngr::registerEvent(CPluginMngr::CPlugin* plugin, int func, int flags, int msgid)
{
Expand Down
1 change: 1 addition & 0 deletions amxmodx/CEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class EventsMngr
inline int getFunction();
void registerFilter(char* filter); // add a condition
void setForwardState(ForwardState value);
ForwardState getForwardState();
};

private:
Expand Down
5 changes: 5 additions & 0 deletions amxmodx/CLogEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ void LogEventsMngr::CLogEvent::setForwardState(ForwardState state)
m_State = state;
}

ForwardState LogEventsMngr::CLogEvent::getForwardState()
{
return m_State;
}

int LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos)
{
if (pos < 1 || pos > MAX_LOGARGS)
Expand Down
1 change: 1 addition & 0 deletions amxmodx/CLogEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class LogEventsMngr
inline CPluginMngr::CPlugin *getPlugin() { return plugin; }
void registerFilter(char* filter);
void setForwardState(ForwardState value);
ForwardState getForwardState();
inline int getFunction() { return func; }
};

Expand Down
26 changes: 26 additions & 0 deletions amxmodx/amxmodx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,19 @@ static cell AMX_NATIVE_CALL disable_event(AMX *amx, cell *params)
return 1;
}

static cell AMX_NATIVE_CALL get_event_state(AMX *amx, cell *params)
{
auto handle = EventHandles.lookup(params[1]);

if (!handle)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid event handle: %d", params[1]);
return 0;
}

return handle->m_event->getForwardState() == FSTATE_ACTIVE ? 1 : 0;
}

static cell AMX_NATIVE_CALL user_kill(AMX *amx, cell *params) /* 2 param */
{
int index = params[1];
Expand Down Expand Up @@ -3343,6 +3356,19 @@ static cell AMX_NATIVE_CALL disable_logevent(AMX *amx, cell *params)
return 1;
}

static cell AMX_NATIVE_CALL get_logevent_state(AMX *amx, cell *params)
{
auto handle = LogEventHandles.lookup(params[1]);

if (!handle)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid log event handle: %d", params[1]);
return 0;
}

return handle->m_logevent->getForwardState() == FSTATE_ACTIVE ? 1 : 0;
}

// native is_module_loaded(const name[]);
static cell AMX_NATIVE_CALL is_module_loaded(AMX *amx, cell *params)
{
Expand Down
10 changes: 10 additions & 0 deletions plugins/include/amxconst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public stock const Float:NULL_VECTOR[3];
#define MENU_KEY_8 (1<<7)
#define MENU_KEY_9 (1<<8)
#define MENU_KEY_0 (1<<9)
#define MENU_KEY_ALL MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0

/**
* Language constants
Expand Down Expand Up @@ -509,6 +510,15 @@ enum SetTaskFlags (<<= 1)
SetTask_BeforeMapChange // Time interval is treated as absolute time before map change
};

/**
* Event states constants for get_event_state and get_logevent_state
*/
enum ForwardState
{
FSTATE_STOP = 0,
FSTATE_ACTIVE = 1
};

/**
* RegisterEventFlags constants for register_event_ex()
*/
Expand Down
20 changes: 20 additions & 0 deletions plugins/include/amxmodx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,16 @@ native enable_event(handle);
*/
native disable_event(handle);

/**
* Get the state of a game event which has been previously registered with register_event_ex().
*
* @param handle Value returned from register_event() or register_event_ex()
*
* @return 1 if event is enabled, 0 otherwise
* @error If an invalid handle is provided, an error will be thrown.
*/
native get_event_state(handle);

/**
* Registers a function to be called on a given log event.
*
Expand Down Expand Up @@ -651,6 +661,16 @@ native enable_logevent(handle);
*/
native disable_logevent(handle);

/**
* Get the state of a game log event which has been previously registered with register_logevent().
*
* @param handle Value returned from register_logevent()
*
* @return 1 if log event is enabled, 0 otherwise
* @error If an invalid handle is provided, an error will be thrown.
*/
native get_logevent_state(handle);

/**
* Sets display parameters for hudmessages.
*
Expand Down
4 changes: 4 additions & 0 deletions plugins/include/time.inc
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ stock get_time_length(id, unitCnt, type, output[], outputLen)
case 4: formatex(output, outputLen, "%s, %s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], timeElement[3], id, "TIME_ELEMENT_AND", timeElement[4]);
}
}
else if (unitCnt == 0)
{
formatex(output, outputLen, "%L", id, "TIME_ELEMENT_PERMANENTLY");
}
}