Raised This Month: $ Target: $400
 0% 

Difficulty with plugin-strange glitches?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SNCurti
Member
Join Date: Feb 2016
Old 01-22-2017 , 22:12   Difficulty with plugin-strange glitches?
Reply With Quote #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?
SNCurti is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-23-2017 , 14:00   Re: Difficulty with plugin-strange glitches?
Reply With Quote #2

Have you checked your error logs?
__________________
asherkin is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-23-2017 , 14:11   Re: Difficulty with plugin-strange glitches?
Reply With Quote #3

Why are you returning plugin handled all the time?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
SNCurti
Member
Join Date: Feb 2016
Old 01-23-2017 , 14:53   Re: Difficulty with plugin-strange glitches?
Reply With Quote #4

Code:
#include <sourcemod>
#include <sdkhooks>
#include <tf2_stocks>
#include <tf2items>

#pragma semicolon 1

int PlayerHit[MAXPLAYERS+1] = 0; int weapon[MAXPLAYERS+1];

int laserrifle = 30665;

bool LaserActivated = false;

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 OnClientConnected(int client)
{
	SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
	if (LaserActivated == true)
	{
		damage = 0.0;
		return Plugin_Changed;
	}
	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 (player != 0 && IsClientInGame(player))
		{
			if (IsPlayerAlive(player))
			{
				if (TF2_GetPlayerClass(player) != TFClass_Sniper)
				{
					TF2_SetPlayerClass(player, TFClass_Sniper);
					TF2_RespawnPlayer(player);
				}
				if (GetPlayerWeaponSlot(player, 0) != weapon[player])
				{
					PrintToChatAll("Inventory changed, player does not have rifle");
					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);
					weapon[player] = TF2Items_GiveNamedItem(player, sniperlaser);		
					EquipPlayerWeapon(player, weapon[player]);
					SetEntProp(weapon[player], Prop_Data, "m_iClip1", 2);
						
					CloseHandle(sniperlaser);
				}
				SetEntProp(player, Prop_Send, "m_bGlowEnabled", 1);
			}
		}
	}
	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 (player != 0 && IsClientInGame(player))
		{
			PrintToChatAll("Player is not invalid.");
			if (IsPlayerAlive(player))
			{
				if (TF2_GetPlayerClass(player) != TFClass_Sniper)
				{
					TF2_SetPlayerClass(player, TFClass_Sniper);
					TF2_RespawnPlayer(player);
				}
				if (GetPlayerWeaponSlot(player, 0) != weapon[player])
				{
					PrintToChatAll("Inventory changed, player does not have rifle");
					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);
					weapon[player] = TF2Items_GiveNamedItem(player, sniperlaser);		
					EquipPlayerWeapon(player, weapon[player]);
					SetEntProp(weapon[player], Prop_Data, "m_iClip1", 2);
						
					CloseHandle(sniperlaser);
				}
				SetEntProp(player, Prop_Send, "m_bGlowEnabled", 1);
			}
		}
		else
		{
			PrintToChatAll("%N, %i, invalid", player, player);
		}
	}
	return Plugin_Handled;
}

public Action CMD_Test(int client, int args)
{
	LaserActivated = true;
	for (int i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i))
		{
			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;
}
This is the updated code, and the error logs on my server are as follows:

[SM] Exception reported: Entity 1 is invalid (This comes after I join)
[SM] Blaming: newtestlaser.smx (This is the plugin)
[SM] Call stack trace:
[SM] [0] SDKHook
[SM] [1] Line 25, newtestlaser.sp::OnClientConnected

For some reason things that have worked in previous codes are not working now. These are the errors I receive. The error logs show me where a problem may lie, but there seems to be no reconciling the code that has worked for me for a while. I removed regeneration and such as to solve one problem at a time, and I cannot pick up ammo for the weapon. Ideally I would like the weapon to have infinite ammo, but one thing at a time.

EDIT: Issue found. Apparently calling OnClientConnected is too early. PostAdminCheck works, however. As for the weapon dropping, I was told that this is simply a feature we will have to live with as valve dislikes any true ownership of a weapon.

Last edited by SNCurti; 01-23-2017 at 15:53.
SNCurti is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-23-2017 , 17:21   Re: Difficulty with plugin-strange glitches?
Reply With Quote #5

Quote:
Originally Posted by friagram View Post
Why are you returning plugin handled all the time?
That's normally what you do when you modify events....or have commands....you need to return something if it's an Action, especially a command because without a return I've had commands just outright refuse to work. Probably some beginner fuckup, but most things I do with events/commands always ends in return Plugin_Handled/Continue/Changed where appropriate.

You only use Plugin_Changed in an event if you've changed a value related to an event integer/string/bool/float/what-have-you.

Unless I'm completely missing something here....
404UserNotFound is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-23-2017 , 17:39   Re: Difficulty with plugin-strange glitches?
Reply With Quote #6

OnClientPutInServer is the forward you want to use.
__________________
asherkin is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-24-2017 , 05:08   Re: Difficulty with plugin-strange glitches?
Reply With Quote #7

Quote:
Originally Posted by abrandnewday View Post
That's normally what you do when you modify events....or have commands....you need to return something if it's an Action, especially a command because without a return I've had commands just outright refuse to work. Probably some beginner fuckup, but most things I do with events/commands always ends in return Plugin_Handled/Continue/Changed where appropriate.

You only use Plugin_Changed in an event if you've changed a value related to an event integer/string/bool/float/what-have-you.

Unless I'm completely missing something here....
Most events you would never return handled or stop on an event listener.
Iirc you can not cancel the event.
You can modify it with changed, or return continue (mabye?)...
Most of the time you do not even need a return, and do not need the action tag either...
This is because the values are passed by refernce and the callback ignores the return type.

For stuff like looping timers continue/stop make sense..
sdkhooks it makes sense to use changed/continue/handled for many callbacks.

I mean, having a return just to have a return doesnt make sense if the return is ignored.. You never see return at the end of every function if the expected return value is to be ignored. Nor do you see like, return 0 and return 1 just for shits and giggles if the return values will be ignored by the function caller. Why does adding a tag suddenly change this practice?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 01-24-2017 at 05:09.
friagram is offline
SNCurti
Member
Join Date: Feb 2016
Old 01-24-2017 , 10:14   Re: Difficulty with plugin-strange glitches?
Reply With Quote #8

Quote:
Originally Posted by asherkin View Post
OnClientPutInServer is the forward you want to use.
Is that the latest forward, because I was told that ideally for hooking things like this the later it is the better.
SNCurti is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-24-2017 , 10:57   Re: Difficulty with plugin-strange glitches?
Reply With Quote #9

Quote:
Originally Posted by SNCurti View Post
Is that the latest forward, because I was told that ideally for hooking things like this the later it is the better.
That is backwards, you want to be hooking as early as possible so you don't miss calls. OnClientPutInServer is fired when the client entity is created, so is the earliest you can do stuff with the client as an entity (such as SDKHooks hooks).

OnClientPostAdminCheck is fired after both OnClientPutInServer and OnClientAuthorized have fired (if not delayed further by an asynchronous admin plugin). It is possible for a player to be in-game and playing for several minutes before it is fired.
__________________
asherkin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:20.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode