Member
|
01-22-2017
, 22:12
Difficulty with plugin-strange glitches?
|
#1
|
Code:
#include <sourcemod>
#include <sdkhooks>
#include <tf2_stocks>
#include <tf2items>
#pragma semicolon 1
int PlayerHit[MAXPLAYERS+1] = 0;
const int laserrifle = 30665;
bool LaserActivated;
public OnPluginStart()
{
RegConsoleCmd("sm_test", CMD_Test);
RegConsoleCmd("sm_testoff", CMD_TestOff);
HookEvent("player_death", Ev_PlayerDeath);
HookEvent("post_inventory_application", Ev_InventoryChanged);
HookEvent("player_spawn", Ev_PlayerSpawn);
}
public void OnClientConnected(int client)
{
SDKHook(client, SDKHook_TraceAttack, TraceAttackHook);
SDKHook(client, SDKHook_FireBulletsPost, FireBulletsPostHook);
SDKHook(client, SDKHook_OnTakeDamage, TakeDamageHook);
}
public OnClientDisconnect(int client)
{
SDKUnhook(client, SDKHook_TraceAttack, TraceAttackHook);
SDKUnhook(client, SDKHook_FireBulletsPost, FireBulletsPostHook);
SDKUnhook(client, SDKHook_OnTakeDamage, TakeDamageHook);
}
public Action TakeDamageHook(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if (LaserActivated == true)
{
damage = 0.0;
TF2_RegeneratePlayer(victim);
TF2_RegeneratePlayer(attacker);
return Plugin_Changed;
}
return Plugin_Continue;
}
public void FireBulletsPostHook(int client, int shots, const char[] weaponname)
{
if (LaserActivated == true)
{
TF2_RegeneratePlayer(client);
}
}
public Action TraceAttackHook(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
{
if (LaserActivated == true)
{
damage = 0.0;
TF2_RegeneratePlayer(victim);
TF2_RegeneratePlayer(attacker);
int Replacement = PlayerHit[victim]+1;
PlayerHit[victim] = Replacement;
if (PlayerHit[victim] >= 3)
{
SDKHooks_TakeDamage(victim, attacker, attacker, float(GetClientHealth(victim)), DMG_ENERGYBEAM, _, _, _);
}
return Plugin_Changed;
}
else
{
return Plugin_Continue;
}
}
public Action Ev_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
if (LaserActivated == true)
{
int player = GetClientOfUserId(GetEventInt(event, "userid", 0));
if (TF2_GetPlayerClass(player) != TFClass_Sniper)
{
ForcePlayerSuicide(player);
TF2_SetPlayerClass(player, TFClass_Sniper);
TF2_RespawnPlayer(player);
}
if (GetPlayerWeaponSlot(player, 0) != laserrifle)
{
TF2_RemoveAllWeapons(player);
Handle sniperlaser = TF2Items_CreateItem(OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
TF2Items_SetClassname(sniperlaser, "tf_weapon_sniperrifle");
TF2Items_SetItemIndex(sniperlaser, laserrifle);
TF2Items_SetLevel(sniperlaser, 1);
TF2Items_SetQuality(sniperlaser, 1);
TF2Items_SetNumAttributes(sniperlaser, 0);
SetEntProp(player, Prop_Send, "m_bGlowEnabled", 1);
int weapon = TF2Items_GiveNamedItem(player, sniperlaser);
EquipPlayerWeapon(player, weapon);
SetEntProp(weapon, Prop_Data, "m_iClip1", 1);
CloseHandle(sniperlaser);
}
}
return Plugin_Handled;
}
public Action Ev_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int victim = GetClientOfUserId(GetEventInt(event, "victim", 0));
PlayerHit[victim] = 0;
return Plugin_Handled;
}
public Action Ev_InventoryChanged(Event event, const char[] name, bool dontBroadcast)
{
if (LaserActivated == true)
{
int player = GetClientOfUserId(GetEventInt(event, "userid", 0));
if (TF2_GetPlayerClass(player) != TFClass_Sniper)
{
ForcePlayerSuicide(player);
TF2_SetPlayerClass(player, TFClass_Sniper);
TF2_RespawnPlayer(player);
}
if (GetPlayerWeaponSlot(player, 0) != laserrifle)
{
TF2_RemoveAllWeapons(player);
Handle sniperlaser = TF2Items_CreateItem(OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
TF2Items_SetClassname(sniperlaser, "tf_weapon_sniperrifle");
TF2Items_SetItemIndex(sniperlaser, laserrifle);
TF2Items_SetLevel(sniperlaser, 1);
TF2Items_SetQuality(sniperlaser, 1);
TF2Items_SetNumAttributes(sniperlaser, 0);
SetEntProp(player, Prop_Send, "m_bGlowEnabled", 1);
int weapon = TF2Items_GiveNamedItem(player, sniperlaser);
EquipPlayerWeapon(player, weapon);
SetEntProp(weapon, Prop_Data, "m_iClip1", 1);
CloseHandle(sniperlaser);
}
}
return Plugin_Handled;
}
public Action CMD_Test(int client, int args)
{
LaserActivated = true;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
if (IsPlayerAlive(i))
{
ForcePlayerSuicide(i);
if (TF2_GetPlayerClass(i) != TFClass_Sniper)
{
TF2_SetPlayerClass(i, TFClass_Sniper);
}
TF2_RespawnPlayer(i);
}
else
{
if (TF2_GetPlayerClass(i) != TFClass_Sniper)
{
TF2_SetPlayerClass(i, TFClass_Sniper);
TF2_RespawnPlayer(i);
}
}
}
}
SetConVarInt(FindConVar("sv_gravity"), 600);
PrintToChatAll("Laser Activated");
return Plugin_Handled;
}
public Action CMD_TestOff(int client, int args)
{
LaserActivated = false;
return Plugin_Handled;
}
I made a code using TF2Items to give a shooting star to all players spawning during a specific mode, enabled by a test command. This works, but the shooting star acts strange. It will not be reloaded, the SDKHooks do not seem to be firing or being used, and much of the plugin seems defunct as if it were never activated even though compilation is completed without a warning.
This locks players in sniper, and should block damage incoming until 3 shots from the shooting star.
Some issues noticed-The shooting star is spawned, but when going to the refill it drops the current one, creating another... any reason for this?
Also, when I shoot someone (yes, the laser activated thing is activated unless I somehow broke that) it doesn't register as removing the damage and does the damage anyway. The plugin code clearly shows those values being reduced to 0.0. The TF2_RegeneratePlayer code should regenerate ammo and health, but does nothing of the sort, so clearly this code isn't being reached but for what reason I couldn't guess nor test to find out. It's puzzling to me... so any help or any spotted flaws in the code would be helpful. I want the gun to be at 1 ammo in clip every time you shoot it, but apparently regenerate isn't doing that. I don't want, when going to a refill station, for it to drop another rifle on the ground (I thought I had blocked the creation of another one)... any help?
|
|