New plugin: RandomTriggerTouch
randomizes OnTrigger !activator by randomizing calls to trigger_multiple Touch
This commit is contained in:
parent
3818fea767
commit
2733e53800
@ -14,7 +14,7 @@ public Plugin myinfo =
|
||||
name = "AntiFlood",
|
||||
author = "BotoX",
|
||||
description = "",
|
||||
version = "0.1",
|
||||
version = "1.0",
|
||||
url = ""
|
||||
};
|
||||
|
||||
|
136
RandomTriggerTouch/scripting/RandomTriggerTouch.sp
Normal file
136
RandomTriggerTouch/scripting/RandomTriggerTouch.sp
Normal file
@ -0,0 +1,136 @@
|
||||
#include <sourcemod>
|
||||
#include <sdkhooks>
|
||||
#include <sdktools>
|
||||
#include <CSSFixes>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
Handle g_hCBaseEntity_Touch;
|
||||
bool g_bIgnoreHook = false;
|
||||
|
||||
#define TOUCHED_MAX (MAXPLAYERS + 1)
|
||||
int g_aTouched[TOUCHED_MAX];
|
||||
int g_aaTouchedList[TOUCHED_MAX][MAXPLAYERS + 1];
|
||||
int g_aTouchedListSize[TOUCHED_MAX];
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Randomize Trigger Touch",
|
||||
author = "BotoX",
|
||||
description = "Randomize Touches on trigger_multiple",
|
||||
version = "1.0"
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
Handle hGameConf = LoadGameConfigFile("sdkhooks.games");
|
||||
if(hGameConf == INVALID_HANDLE)
|
||||
{
|
||||
SetFailState("Couldn't load sdkhooks.games game config!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(GameConfGetOffset(hGameConf, "Touch") == -1)
|
||||
{
|
||||
CloseHandle(hGameConf);
|
||||
SetFailState("Couldn't get Touch offset from game config!");
|
||||
return;
|
||||
}
|
||||
|
||||
// void CBaseEntity::Touch( CBaseEntity *pOther )
|
||||
StartPrepSDKCall(SDKCall_Entity);
|
||||
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "Touch"))
|
||||
{
|
||||
CloseHandle(hGameConf);
|
||||
SetFailState("PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, \"Touch\" failed!");
|
||||
return;
|
||||
}
|
||||
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
|
||||
g_hCBaseEntity_Touch = EndPrepSDKCall();
|
||||
|
||||
// Late load
|
||||
int entity = INVALID_ENT_REFERENCE;
|
||||
while((entity = FindEntityByClassname(entity, "trigger_multiple")) != INVALID_ENT_REFERENCE)
|
||||
{
|
||||
SDKHook(entity, SDKHook_Touch, OnTouch);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRunThinkFunctionsPost(bool simulating)
|
||||
{
|
||||
g_bIgnoreHook = true;
|
||||
for(int i = 0; i < sizeof(g_aTouched); i++)
|
||||
{
|
||||
if(!g_aTouched[i])
|
||||
break;
|
||||
|
||||
if(!IsValidEntity(g_aTouched[i]))
|
||||
continue;
|
||||
|
||||
// Fisher-Yates Shuffle
|
||||
for(int j = g_aTouchedListSize[i] - 1; j >= 1; j--)
|
||||
{
|
||||
int k = GetRandomInt(0, j);
|
||||
int t = g_aaTouchedList[i][j];
|
||||
g_aaTouchedList[i][j] = g_aaTouchedList[i][k];
|
||||
g_aaTouchedList[i][k] = t;
|
||||
}
|
||||
|
||||
for(int j = 0; j < g_aTouchedListSize[i]; j++)
|
||||
{
|
||||
if(IsValidEntity(g_aaTouchedList[i][j]))
|
||||
SDKCall(g_hCBaseEntity_Touch, g_aTouched[i], g_aaTouchedList[i][j]);
|
||||
}
|
||||
|
||||
g_aTouched[i] = 0;
|
||||
g_aTouchedListSize[i] = 0;
|
||||
}
|
||||
g_bIgnoreHook = false;
|
||||
}
|
||||
|
||||
public void OnEntityCreated(int entity, const char[] classname)
|
||||
{
|
||||
if(StrEqual(classname, "trigger_multiple"))
|
||||
{
|
||||
SDKHook(entity, SDKHook_Touch, OnTouch);
|
||||
}
|
||||
}
|
||||
|
||||
public Action OnTouch(int touched, int toucher)
|
||||
{
|
||||
if(toucher > MAXPLAYERS || g_bIgnoreHook)
|
||||
return Plugin_Continue;
|
||||
|
||||
int i;
|
||||
for(i = 0; i < sizeof(g_aTouched); i++)
|
||||
{
|
||||
if(!g_aTouched[i] || g_aTouched[i] == touched)
|
||||
break;
|
||||
}
|
||||
|
||||
if(i == sizeof(g_aTouched))
|
||||
return Plugin_Continue;
|
||||
|
||||
g_aTouched[i] = touched;
|
||||
|
||||
for(int j = 0; j < g_aTouchedListSize[i]; j++)
|
||||
{
|
||||
if(g_aaTouchedList[i][j] == toucher)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
g_aaTouchedList[i][g_aTouchedListSize[i]++] = toucher;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
stock int GetHighestClientIndex()
|
||||
{
|
||||
for(int i = MaxClients; i >= 1; i--)
|
||||
{
|
||||
if(IsValidEntity(i))
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
1
RandomTriggerTouch/scripting/include/CSSFixes.inc
Symbolic link
1
RandomTriggerTouch/scripting/include/CSSFixes.inc
Symbolic link
@ -0,0 +1 @@
|
||||
../../../includes/CSSFixes.inc
|
@ -22,7 +22,7 @@ public Plugin myinfo =
|
||||
name = "Reserved Slot",
|
||||
author = "BotoX",
|
||||
description = "Kicks someone to make space for a connecting donator.",
|
||||
version = "0.1",
|
||||
version = "1.0",
|
||||
url = ""
|
||||
};
|
||||
|
||||
|
29
includes/CSSFixes.inc
Normal file
29
includes/CSSFixes.inc
Normal file
@ -0,0 +1,29 @@
|
||||
#if defined _cssfixes_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _cssfixes_included
|
||||
|
||||
forward void OnRunThinkFunctions(bool simulating);
|
||||
forward void OnRunThinkFunctionsPost(bool simulating);
|
||||
|
||||
public Extension:__ext_CSSFixes =
|
||||
{
|
||||
name = "CSSFixes",
|
||||
file = "CSSFixes.ext",
|
||||
#if defined AUTOLOAD_EXTENSIONS
|
||||
autoload = 1,
|
||||
#else
|
||||
autoload = 0,
|
||||
#endif
|
||||
#if defined REQUIRE_EXTENSIONS
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined REQUIRE_EXTENSIONS
|
||||
public __ext_CSSFixes_SetNTVOptional()
|
||||
{
|
||||
}
|
||||
#endif
|
@ -61,7 +61,7 @@ public Extension:__ext_PointDetour =
|
||||
};
|
||||
|
||||
#if !defined REQUIRE_EXTENSIONS
|
||||
public __ext_dhooks_SetNTVOptional()
|
||||
public __ext_PointDetour_SetNTVOptional()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user