Junior Member
|
07-12-2023
, 13:04
VSH / FF2 Necrosmash
|
#1
|
I made a plugin not long ago, but it has a few errors.
1. If the saxton hale is afkol or there is a 1v1 and the hammer hits the saxton, it does not die.
2. If the saxton hale or the red team dies, the hammer will fall.
My code is:
Quote:
#pragma semicolon 1
#define PLUGIN_AUTHOR "Fate Fighter"
#define PLUGIN_VERSION "1.0"
#define KILL_ENT_IN(%1,%2) \
SetVariantString("OnUser1 !self:Kill::" ... #%2 ... ":1"); \
AcceptEntityInput(%1, "AddOutput"); \
AcceptEntityInput(%1, "FireUser1");
#define MATCHES 3
//#define DEBUG
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
float gF_Position[MAXPLAYERS+1][3];
float gF_Angles[MAXPLAYERS+1][3];
int gI_Buttons[MAXPLAYERS+1];
Handle gTimer = INVALID_HANDLE;
public Plugin myinfo =
{
name = "VSH Necrosmash",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = ""
};
public void OnPluginStart()
{
HookEvent("arena_round_start", Event_RoundStart);
HookEvent("teamplay_round_win", Event_RoundEnd);
HookEvent("teamplay_round_stalemate", Event_RoundEnd);
}
public void OnMapStart()
{
if(gTimer != INVALID_HANDLE)
{
KillTimer(gTimer);
gTimer = INVALID_HANDLE;
}
PrecacheModel("models/props_halloween/hammer_gears_mechanism.mdl");
PrecacheModel("models/props_halloween/hammer_mechanism.mdl");
PrecacheModel("models/props_halloween/bell_button.mdl");
PrecacheSound("misc/halloween/strongman_fast_impact_01.wav");
PrecacheSound("ambient/explosions/explode_1.wav");
PrecacheSound("misc/halloween/strongman_fast_whoosh_01.wav");
PrecacheSound("misc/halloween/strongman_fast_swing_01.wav");
PrecacheSound("doors/vent_open2.wav");
}
public void OnClientPutInServer(int client)
{
gF_Position[client] = view_as<float>({0.0, 0.0, 0.0});
gF_Angles[client] = view_as<float>({0.0, 0.0, 0.0});
gI_Buttons[client] = 0;
}
public void Event_RoundStart(Handle event, const char[] name, bool dB)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
GetClientAbsOrigin(i, gF_Position[i]);
GetClientEyeAngles(i, gF_Angles[i]);
gI_Buttons[i] = GetClientButtons(i);
}
}
#if defined DEBUG
PrintToChatAll("[SM] Initiating vsh afk timer.");
#endif
gTimer = CreateTimer(15.0, Timer_AFKCheck, _, TIMER_REPEAT);
}
public Action Event_RoundEnd(Handle event, char[] name, bool dontBroadcast)
{
if(gTimer != INVALID_HANDLE)
{
KillTimer(gTimer);
gTimer = INVALID_HANDLE;
#if defined DEBUG
PrintToChatAll("[SM] Killing existing vsh afk timer.");
#endif
}
}
public Action Timer_AFKCheck(Handle timer)
{
int count = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
if(GetClientTeam(i) == 2 && GetRedAlive() > 1)
continue;
else if (GetRedAlive() == 1)
{
Check(i);
continue;
}
float fPosition[3], fAngles[3];
GetClientAbsOrigin(i, fPosition);
GetClientEyeAngles(i, fAngles);
int iMatches = 0, iButtons = GetClientButtons(i);
if(bVectorsEqual(fPosition, gF_Position[i]))
{
iMatches++;
}
if(bVectorsEqual(fAngles, gF_Angles[i]))
{
iMatches++;
}
if(iButtons == gI_Buttons[i])
{
iMatches++;
}
if(iMatches >= MATCHES)
{
Check(i);
count++;
}
else
{
#if defined DEBUG
PrintToChatAll("[SM] %N is ok!", i);
#endif
}
gF_Position[i] = fPosition;
gF_Angles[i] = fAngles;
gI_Buttons[i] = iButtons;
}
}
if(count == 1)
{
PrintToChatAll("[SM] AFK Saxton has been necromissed!");
}
}
void Check(int client)
{
if(GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") > -1)
Smash(client);
else
CreateTimer(0.1, Timer_NecroMash_Retry, GetClientUserId(client), TIMER_REPEAT);
}
public Action Timer_NecroMash_Retry(Handle hTimer, int iUserId)
{
int client = GetClientOfUserId(iUserId);
if(!client)
return Plugin_Stop;
if(GetEntProp(client, Prop_Send, "m_hGroundEntity") < 0)
return Plugin_Continue;
Smash(client);
return Plugin_Stop;
}
void Smash(int client)
{
float flPos[3], flPpos[3], flAngles[3];
GetClientAbsOrigin(client, flPos);
GetClientAbsOrigin(client, flPpos);
GetClientEyeAngles(client, flAngles);
flAngles[0] = 0.0;
float vForward[3];
GetAngleVectors(flAngles, vForward, NULL_VECTOR, NULL_VECTOR);
flPos[0] -= (vForward[0] * 750);
flPos[1] -= (vForward[1] * 750);
flPos[2] -= (vForward[2] * 750);
flPos[2] += 350.0;
int gears = CreateEntityByName("prop_dynamic");
if(IsValidEntity(gears)){
DispatchKeyValueVector(gears, "origin", flPos);
DispatchKeyValueVector(gears, "angles", flAngles);
DispatchKeyValue(gears, "model", "models/props_halloween/hammer_gears_mechanism.mdl");
DispatchSpawn(gears);
}
int hammer = CreateEntityByName("prop_dynamic");
if(IsValidEntity(hammer)){
DispatchKeyValueVector(hammer, "origin", flPos);
DispatchKeyValueVector(hammer, "angles", flAngles);
DispatchKeyValue(hammer, "model", "models/props_halloween/hammer_mechanism.mdl");
DispatchSpawn(hammer);
}
int button = CreateEntityByName("prop_dynamic");
if(IsValidEntity(button)){
flPos[0] += (vForward[0] * 600);
flPos[1] += (vForward[1] * 600);
flPos[2] += (vForward[2] * 600);
flPos[2] -= 100.0;
flAngles[1] += 180.0;
DispatchKeyValueVector(button, "origin", flPos);
DispatchKeyValueVector(button, "angles", flAngles);
DispatchKeyValue(button, "model", "models/props_halloween/bell_button.mdl");
DispatchSpawn(button);
Handle pack;
CreateDataTimer(1.3, Timer_NecroMash_Hit, pack);
WritePackFloat(pack, flPpos[0]); //Position of effects
WritePackFloat(pack, flPpos[1]); //Position of effects
WritePackFloat(pack, flPpos[2]); //Position of effects
Handle pack2;
CreateDataTimer(1.0, Timer_NecroMash_Whoosh, pack2);
WritePackFloat(pack2, flPpos[0]); //Position of effects
WritePackFloat(pack2, flPpos[1]); //Position of effects
WritePackFloat(pack2, flPpos[2]); //Position of effects
EmitSoundToAll("misc/halloween/strongman_fast_swing_01.wav", _, _, _, _, _, _, _, flPpos);
}
SetVariantString("OnUser2 !self:SetAnimation:smash:0:1");
AcceptEntityInput(gears, "AddOutput");
AcceptEntityInput(gears, "FireUser2");
SetVariantString("OnUser2 !self:SetAnimation:smash:0:1");
AcceptEntityInput(hammer, "AddOutput");
AcceptEntityInput(hammer, "FireUser2");
SetVariantString("OnUser2 !self:SetAnimation:hit:1.3:1");
AcceptEntityInput(button, "AddOutput");
AcceptEntityInput(button, "FireUser2");
KILL_ENT_IN(gears, 5.0)
KILL_ENT_IN(hammer, 5.0)
KILL_ENT_IN(button, 5.0)
}
public Action Timer_NecroMash_Hit(Handle timer, any pack)
{
ResetPack(pack);
float pos[3];
pos[0] = ReadPackFloat(pack);
pos[1] = ReadPackFloat(pack);
pos[2] = ReadPackFloat(pack);
int shaker = CreateEntityByName("env_shake");
if(shaker != -1){
DispatchKeyValue(shaker, "amplitude", "10");
DispatchKeyValue(shaker, "radius", "1500");
DispatchKeyValue(shaker, "duration", "1");
DispatchKeyValue(shaker, "frequency", "2.5");
DispatchKeyValue(shaker, "spawnflags", "4");
DispatchKeyValueVector(shaker, "origin", pos);
DispatchSpawn(shaker);
AcceptEntityInput(shaker, "StartShake");
KILL_ENT_IN(shaker,1.0)
}
EmitSoundToAll("ambient/explosions/explode_1.wav", _, _, _, _, _, _, _, pos);
EmitSoundToAll("misc/halloween/strongman_fast_impact_01.wav", _, _, _, _, _, _, _, pos);
float pos2[3], Vec[3], AngBuff[3];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i)){
GetClientAbsOrigin(i, pos2);
if(GetVectorDistance(pos, pos2) <= 500.0){
MakeVectorFromPoints(pos, pos2, Vec);
GetVectorAngles(Vec, AngBuff);
AngBuff[0] -= 30.0;
GetAngleVectors(AngBuff, Vec, NULL_VECTOR, NULL_VECTOR);
NormalizeVector(Vec, Vec);
ScaleVector(Vec, 500.0);
Vec[2] += 250.0;
TeleportEntity(i, NULL_VECTOR, NULL_VECTOR, Vec);
}
if(GetVectorDistance(pos, pos2) <= 60.0)
SDKHooks_TakeDamage(i, i, i, 999999.0, DMG_CLUB|DMG_ALWAYSGIB|DMG_BLAST);
}
}
pos[2] += 10.0;
NecroMash_CreateParticle("hammer_impact_butto n", pos);
NecroMash_CreateParticle("hammer_bones_kickup ", pos);
}
public Action Timer_NecroMash_Whoosh(Handle timer, any pack){
ResetPack(pack);
float pos[3];
pos[0] = ReadPackFloat(pack);
pos[1] = ReadPackFloat(pack);
pos[2] = ReadPackFloat(pack);
EmitSoundToAll("misc/halloween/strongman_fast_whoosh_01.wav", _, _, _, _, _, _, _, pos);
}
stock void NecroMash_CreateParticle(char[] particle, float pos[3])
{
int tblidx = FindStringTable("ParticleEffectNames");
char tmp[256];
int count = GetStringTableNumStrings(tblidx);
int stridx = INVALID_STRING_INDEX;
for(int i = 0; i < count; i++)
{
ReadStringTable(tblidx, i, tmp, sizeof(tmp));
if(StrEqual(tmp, particle, false)){
stridx = i;
break;
}
}
for(int i = 1; i <= MaxClients; i++)
{
if(!IsValidEntity(i)) continue;
if(!IsClientInGame(i)) continue;
TE_Start("TFParticleEffect");
TE_WriteFloat("m_vecOrigin[0]", pos[0]);
TE_WriteFloat("m_vecOrigin[1]", pos[1]);
TE_WriteFloat("m_vecOrigin[2]", pos[2]);
TE_WriteNum("m_iParticleSystemIndex", stridx);
TE_WriteNum("entindex", -1);
TE_WriteNum("m_iAttachType", 2);
TE_SendToClient(i, 0.0);
}
}
bool bVectorsEqual(float[3] v1, float[3] v2)
{
return (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2]);
}
int GetRedAlive()
{
int count = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i))
count++;
}
return count;
}
|
|
|