Raised This Month: $ Target: $400
 0% 

Disable In_Attack for x seconds on player_spawn?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xXNewGuyXx
Member
Join Date: Jun 2016
Old 03-04-2017 , 09:40   Disable In_Attack for x seconds on player_spawn?
Reply With Quote #1

- Hey all,

I got some funky stuff goin' on as a product of some new plugins I've been testing (firing a weapon the very frame they spawn), and am wondering if I could address that with this method ...but I don't know how to go about flipping IN_ATTACK and appending it to a short timer.

Thanks in advance!

Last edited by headline; 03-05-2017 at 11:50. Reason: Do not blank out posts.
xXNewGuyXx is offline
sdz
Senior Member
Join Date: Feb 2012
Old 03-04-2017 , 12:39   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #2

PHP Code:
bool g_enableAttack[MAXPLAYERS 1] = false;

public 
Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weaponint &subtypeint &cmdnumint &tickcountint &seedint mouse[2])
{
    if(
client && client <= MaxClients)
    {
        if(!
g_enableAttack && buttons IN_ATTACK)
        {
            
buttons &= ~IN_ATTACK;
            return 
Plugin_Handled;
        }
    }
    return 
Plugin_Continue;
}

public 
Action timer_enableAttack(Handle timer)
{
    for(
int client 1client <= MaxClientsclient++)
    {
        
g_enableAttack[client] = true;
    }

you'll want to hook the spawn event and call that timer

Last edited by sdz; 03-04-2017 at 12:48.
sdz is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 03-04-2017 , 16:48   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #3

Thank you for the reply EasSidezz,

This is what I have:
Code:
new Handle:hEnableAutoRespawn;
new Handle:hAutoRespawnTime;
new Handle:hDisableManualRespawn;
bool:g_enableAttack[MAXPLAYERS+1] = false;
 
public OnPluginStart()
{
	HookEvent("player_death", Event_PlayerDeath);
	HookEvent("player_spawn", Event_PlayerSpawn);
}
 
public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(!GetConVarInt(hEnableAutoRespawn)){ return; }
 
	new client_id = GetClientOfUserId(GetEventInt(event, "userid"));
	CreateTimer(GetConVarFloat(hAutoRespawnTime), RespawnPlayer, client_id);
}
 
public Action:RespawnPlayer(Handle:timer, any:client)
{
	if(!IsPlayerAlive(client)) { DispatchSpawn(client); }
}

public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])
{ 
	if(GetConVarInt(hDisableManualRespawn) == 1)
	{
		if(client > 0 && client <= MaxClients)
		{
			if(!g_enableAttack && buttons & IN_ATTACK)
			{
				buttons &= ~IN_ATTACK;
				return Plugin_Handled;
			}
		}
	
		//Fix spectate "free camera" functionality
		if(!IsPlayerAlive(client) && GetClientTeam(client) != 1)
		{
			return Plugin_Handled;
		}
	}
	return Plugin_Continue;
}

public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(!GetConVarInt(hEnableAutoRespawn)){ return; }
 
	new client_id = GetClientOfUserId(GetEventInt(event, "userid"));
	CreateTimer(5.0, timer_enableAttack, client_id);
}

public Action:timer_enableAttack(Handle:timer, any:client)
{
	for(client = 1; client <= MaxClients; client++)
	{
		if(IsClientInGame(client) && IsPlayerAlive(client))
		{
			g_enableAttack[client] = true;
			PrintToChat(client, "Attack timer: FIRED");
		}
	}
}
The timer is firing after 5 seconds, but it appears that it's still failing to negate IN_ATTACK.

From further testing, it appears that this glitch only happens when the player is holding attack1 while dead- and the player spawns while still holding attack1, which causes the dead client's input to become a live client's input- causing a random weapon to fire on the first frame of spawn? (I say first frame because the projectile hole is sometimes elevated and in a different direction then the direction the player spawns facing.)

Game is HL2DM if that helps
xXNewGuyXx is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 03-04-2017 , 17:13   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #4

I'm not sure exactly what the problem you're describing is, but why the hell are you looping client indexes when you are already being handed them???? This is probably why you're getting mixed client input...


Try this.
PHP Code:
#include <sdktools>

new Handle:hEnableAutoRespawn;
new 
Handle:hAutoRespawnTime;
new 
Handle:hDisableManualRespawn;
bool:g_enableAttack[MAXPLAYERS+1] = false;
 
public 
OnPluginStart()
{
    
HookEvent("player_death"Event_PlayerDeath);
    
HookEvent("player_spawn"Event_PlayerSpawn);
}
 
public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
GetConVarInt(hEnableAutoRespawn)){ return; }
 
    new 
client_id GetClientOfUserId(GetEventInt(event"userid"));
    
CreateTimer(GetConVarFloat(hAutoRespawnTime), RespawnPlayerclient_id);
}
 
public 
Action:RespawnPlayer(Handle:timerany:client)
{
    if(!
IsPlayerAlive(client)) { DispatchSpawn(client); }
}

public 
Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seedmouse[2])

    if(
GetConVarInt(hDisableManualRespawn) == 1)
    {
        if(!
g_enableAttack[client] && (buttons IN_ATTACK) == IN_ATTACK)
        {
            
buttons = (buttons & ~IN_ATTACK);
            return 
Plugin_Changed;
        }
    
        
//Fix spectate "free camera" functionality
        
if(!IsPlayerAlive(client) && GetClientTeam(client) != 1)
        {
            return 
Plugin_Handled;
        }
    }
    return 
Plugin_Continue;
}

public 
Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
GetConVarInt(hEnableAutoRespawn)){ return; }
 
    
CreateTimer(5.0timer_enableAttackGetEventInt(event"userid"));
}

public 
Action:timer_enableAttack(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);
    if(
IsClientInGame(client) && IsPlayerAlive(client))
    {
        
g_enableAttack[client] = true;
    }


Last edited by headline; 03-04-2017 at 17:21.
headline is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 03-04-2017 , 18:44   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #5

No Headline,

Unfortunately, this issue was present before EasSidezz recommended the client index loop.

Also, with your recommendation, the issue persists. Once a player is killed, if they hold attack1, they will instantly fire a weapon once they spawn, before they even really know where they are.

Thanks for your reply.
xXNewGuyXx is offline
sdz
Senior Member
Join Date: Feb 2012
Old 03-04-2017 , 19:15   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #6

It'll do it on the clientside due to prediction, if you were to do this on a LAN Server it wouldn't fire.. or it shouldn't
sdz is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 03-04-2017 , 21:22   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #7

@EasSidezz

Would sv_lan 1 still be viable for this? Using Headline's example, I've tested on my server with sv_lan 1, and it's still not negating IN_ATTACK.
xXNewGuyXx is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 03-05-2017 , 09:22   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #8

I have fixed this bug by stripping player weapons in the player_death event as well.

Thanks for the help.
xXNewGuyXx is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 03-05-2017 , 10:31   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #9

Please, do not blank out the question...
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 03-05-2017 , 11:50   Re: Disable In_Attack for x seconds on player_spawn?
Reply With Quote #10

Quote:
Originally Posted by KissLick View Post
Please, do not blank out the question...
Restored.
headline 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 02:34.


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