more natives

added ClearClientEvents
added SetEventsTimescale
This commit is contained in:
hermansimensen 2021-03-22 19:26:07 +01:00
parent 1b3b6447ff
commit 690b55446e
2 changed files with 60 additions and 8 deletions

View File

@ -39,12 +39,7 @@ Handle g_hFindEntityByName;
int g_iRefOffset;
bool g_bBhopTimer;
enum struct entity_t
{
int caller;
float waitTime;
}
float g_fTimescale[MAXPLAYERS + 1];
public Plugin myinfo =
{
@ -89,6 +84,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
{
CreateNative("GetClientEvents", Native_GetClientEvents);
CreateNative("SetClientEvents", Native_SetClientEvents);
CreateNative("ClearClientEvents", Native_ClearClientEvents);
CreateNative("SetEventsTimescale", Native_SetEventsTimescale);
g_bLateLoad = late;
RegPluginLibrary("eventqueuefix");
@ -112,6 +109,8 @@ public void OnMapStart()
public void OnClientPutInServer(int client)
{
g_fTimescale[client] = 1.0;
if(g_aPlayerEvents[client] == null)
{
g_aPlayerEvents[client] = new ArrayList(sizeof(event_t));
@ -299,6 +298,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
if(g_bBhopTimer)
timescale = Shavit_GetClientTimescale(client) != -1.0 ? Shavit_GetClientTimescale(client) : Shavit_GetStyleSettingFloat(Shavit_GetBhopStyle(client), "speed");
else timescale = g_fTimescale[client];
for(int i = 0; i < g_aOutputWait[client].Length; i++)
{
@ -365,5 +365,30 @@ public any Native_SetClientEvents(Handle plugin, int numParams)
g_aPlayerEvents[client] = ep.playerEvents.Clone();
g_aOutputWait[client] = ep.outputWaits.Clone();
return true;
}
public any Native_SetEventsTimescale(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if(client < 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client))
return false;
g_fTimescale[client] = GetNativeCell(2);
return true;
}
public any Native_ClearClientEvents(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if(client < 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client))
return false;
g_aOutputWait[client].Clear();
g_aPlayerEvents[client].Clear();
return true;
}

View File

@ -31,6 +31,12 @@ enum struct eventpack_t
ArrayList outputWaits;
}
enum struct entity_t
{
int caller;
float waitTime;
}
/*
* Gets the current pending events for a client.
*
@ -39,7 +45,7 @@ enum struct eventpack_t
*
* @return True if successful, false otherwise.
*/
native any GetClientEvents(int client, any[] eventpack);
native bool GetClientEvents(int client, any[] eventpack);
/*
* Sets the current pending events for a client.
@ -49,12 +55,33 @@ native any GetClientEvents(int client, any[] eventpack);
*
* @return True if successful, false otherwise.
*/
native any SetClientEvents(int client, any[] eventpack);
native bool SetClientEvents(int client, any[] eventpack);
/*
* Clears the current pending events for a client.
*
* @param client Client index.
*
* @return True if successful, false otherwise.
*/
native bool ClearClientEvents(int client);
/*
* Sets the current timescale for a client.
*
* @param client Client index.
* @param timescale Timescale.
*
* @return True if successful, false otherwise.
*/
native bool SetEventsTimescale(int client, float timescale);
#if !defined REQUIRE_PLUGIN
public void __pl_eventqueuefix_SetNTVOptional()
{
MarkNativeAsOptional("GetClientEvents");
MarkNativeAsOptional("SetClientEvents");
MarkNativeAsOptional("ClearClientEvents");
MarkNativeAsOptional("SetEventsTimescale");
}
#endif