SourceMod 1.10 and new OnEntitySpawned forward

This commit is contained in:
BotoX
2019-09-10 16:34:12 +02:00
parent e32e702108
commit 73f450eaae
26 changed files with 802 additions and 975 deletions
+77 -10
View File
@@ -7,6 +7,9 @@
#include <sdktools>
#include <dhooks>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo =
{
name = "ZItemKnockback",
@@ -17,10 +20,20 @@ public Plugin myinfo =
};
Handle hFireBulletDetour;
bool g_bLateLoad = false;
int g_LastAttacker = 0;
int g_LastVictim = 0;
// maps from edict index to object index
char g_EntityIdxToItemIdx[2048];
enum struct SItem
{
bool m_Test;
}
SItem g_Items[255];
public void OnPluginStart()
{
Handle hGameData = LoadGameConfigFile("ZItemKnockback.games");
@@ -34,7 +47,57 @@ public void OnPluginStart()
if(!DHookEnableDetour(hFireBulletDetour, false, Detour_OnFireBullet))
SetFailState("Failed to detour CCSPlayer__FireBullet.");
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_bLateLoad = late;
return APLRes_Success;
}
public void OnMapStart()
{
bool bLate = g_bLateLoad;
g_bLateLoad = false;
char sMapName[PLATFORM_MAX_PATH];
GetCurrentMap(sMapName, sizeof(sMapName));
char sConfigFile[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/ZItemKnockback/%s.cfg", sMapName);
if(!FileExists(sConfigFile))
{
LogMessage("Could not find mapconfig: \"%s\"", sConfigFile);
return;
}
LogMessage("Found mapconfig: \"%s\"", sConfigFile);
KeyValues KvConfig = new KeyValues("items");
if(!KvConfig.ImportFromFile(sConfigFile))
{
delete KvConfig;
LogError("ImportFromFile() failed!");
return;
}
KvConfig.Rewind();
if(!KvConfig.GotoFirstSubKey())
{
delete KvConfig;
LogError("GotoFirstSubKey() failed!");
return;
}
do
{
char sSection[64];
KvConfig.GetSectionName(sSection, sizeof(sSection));
} while(KvConfig.GotoNextKey(false));
delete KvConfig;
/* Late Load */
for(int client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
@@ -42,6 +105,7 @@ public void OnPluginStart()
}
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_WeaponEquipPost, OnWeaponEquip);
@@ -97,9 +161,16 @@ void CheckChildren(int client, int parent)
}
}
public MRESReturn Detour_OnFireBullet(int pThis, Handle hParams)
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
PrintToServer("OnFireBullet called on entity %d!", pThis);
// because knifes don't call FireBullet we reset it here too
g_LastAttacker = 0;
g_LastVictim = 0;
}
public MRESReturn Detour_OnFireBullet(int pThis, Handle hReturn, Handle hParams)
{
// need to reset it per fired bullet else only one of the shotgun pellets would be able to hit the same player
g_LastAttacker = 0;
g_LastVictim = 0;
return MRES_Handled;
@@ -107,7 +178,6 @@ public MRESReturn Detour_OnFireBullet(int pThis, Handle hParams)
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3])
{
PrintToChatAll("OnTakeDamage(%d, %d, %d, %f, %d, %d)", victim, attacker, inflictor, damage, damagetype, weapon);
if(attacker <= 0 || attacker > MAXPLAYERS)
return Plugin_Continue;
@@ -118,21 +188,18 @@ public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &dam
break;
}
PrintToChatAll("\tclient = %d", client);
if(client <= 0)
return Plugin_Handled;
// TODO: Fix for knife
// fix multiple penetration
if(g_LastAttacker == attacker && g_LastVictim == client)
return Plugin_Handled;
g_LastAttacker = attacker;
g_LastVictim = client;
victim = client;
PrintToChatAll("\tvictim = %d", victim);
SDKHooks_TakeDamage(victim, inflictor, attacker, damage, damagetype, weapon, damageForce, damagePosition);
g_LastAttacker = attacker;
g_LastVictim = victim;
SDKHooks_TakeDamage(victim, inflictor, attacker, damage, damagetype, weapon, damageForce, damagePosition);
return Plugin_Handled;
}