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; int g_iRefOffset;
bool g_bBhopTimer; bool g_bBhopTimer;
float g_fTimescale[MAXPLAYERS + 1];
enum struct entity_t
{
int caller;
float waitTime;
}
public Plugin myinfo = public Plugin myinfo =
{ {
@ -89,6 +84,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
{ {
CreateNative("GetClientEvents", Native_GetClientEvents); CreateNative("GetClientEvents", Native_GetClientEvents);
CreateNative("SetClientEvents", Native_SetClientEvents); CreateNative("SetClientEvents", Native_SetClientEvents);
CreateNative("ClearClientEvents", Native_ClearClientEvents);
CreateNative("SetEventsTimescale", Native_SetEventsTimescale);
g_bLateLoad = late; g_bLateLoad = late;
RegPluginLibrary("eventqueuefix"); RegPluginLibrary("eventqueuefix");
@ -112,6 +109,8 @@ public void OnMapStart()
public void OnClientPutInServer(int client) public void OnClientPutInServer(int client)
{ {
g_fTimescale[client] = 1.0;
if(g_aPlayerEvents[client] == null) if(g_aPlayerEvents[client] == null)
{ {
g_aPlayerEvents[client] = new ArrayList(sizeof(event_t)); 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) if(g_bBhopTimer)
timescale = Shavit_GetClientTimescale(client) != -1.0 ? Shavit_GetClientTimescale(client) : Shavit_GetStyleSettingFloat(Shavit_GetBhopStyle(client), "speed"); 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++) for(int i = 0; i < g_aOutputWait[client].Length; i++)
{ {
@ -367,3 +367,28 @@ public any Native_SetClientEvents(Handle plugin, int numParams)
return true; 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; ArrayList outputWaits;
} }
enum struct entity_t
{
int caller;
float waitTime;
}
/* /*
* Gets the current pending events for a client. * Gets the current pending events for a client.
* *
@ -39,7 +45,7 @@ enum struct eventpack_t
* *
* @return True if successful, false otherwise. * @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. * 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. * @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 #if !defined REQUIRE_PLUGIN
public void __pl_eventqueuefix_SetNTVOptional() public void __pl_eventqueuefix_SetNTVOptional()
{ {
MarkNativeAsOptional("GetClientEvents"); MarkNativeAsOptional("GetClientEvents");
MarkNativeAsOptional("SetClientEvents"); MarkNativeAsOptional("SetClientEvents");
MarkNativeAsOptional("ClearClientEvents");
MarkNativeAsOptional("SetEventsTimescale");
} }
#endif #endif