AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Disable In_Attack for x seconds on player_spawn? (https://forums.alliedmods.net/showthread.php?t=294643)

xXNewGuyXx 03-04-2017 09:40

Disable In_Attack for x seconds on player_spawn?
 
- 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!

sdz 03-04-2017 12:39

Re: Disable In_Attack for x seconds on player_spawn?
 
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

xXNewGuyXx 03-04-2017 16:48

Re: Disable In_Attack for x seconds on player_spawn?
 
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 :(

headline 03-04-2017 17:13

Re: Disable In_Attack for x seconds on player_spawn?
 
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;
    }



xXNewGuyXx 03-04-2017 18:44

Re: Disable In_Attack for x seconds on player_spawn?
 
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.

sdz 03-04-2017 19:15

Re: Disable In_Attack for x seconds on player_spawn?
 
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

xXNewGuyXx 03-04-2017 21:22

Re: Disable In_Attack for x seconds on player_spawn?
 
@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 03-05-2017 09:22

Re: Disable In_Attack for x seconds on player_spawn?
 
I have fixed this bug by stripping player weapons in the player_death event as well.

Thanks for the help.

KissLick 03-05-2017 10:31

Re: Disable In_Attack for x seconds on player_spawn?
 
Please, do not blank out the question...

headline 03-05-2017 11:50

Re: Disable In_Attack for x seconds on player_spawn?
 
Quote:

Originally Posted by KissLick (Post 2501011)
Please, do not blank out the question...

Restored.


All times are GMT -4. The time now is 15:32.

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