AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [L4D2] How to stop plugin when HookEvent is triggered (https://forums.alliedmods.net/showthread.php?t=338480)

alasfourom 07-07-2022 20:27

[L4D2] How to stop plugin when HookEvent is triggered
 
Hi guys,

I'm trying to disable a plugin when these hookevents started

PHP Code:

    HookEvent ("charger_charge_start"Event_InfectedAbilityStart);
    
HookEvent ("charger_pummel_start"Event_InfectedAbilityStart);
    
HookEvent ("choke_start",     Event_InfectedAbilityStart);
    
HookEvent ("lunge_pounce"Event_InfectedAbilityStart);
    
HookEvent ("jockey_ride"Event_InfectedAbilityStart); 

I'm not sure how to do it, if someone can enlighten me I would be appreciated

Here is the script

PHP Code:

#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.0"
#define SOUND "ui/menu_countdown.wav"
#include <sdktools>
#include <sourcemod>

Handle SpeedAllowed INVALID_HANDLE;
Handle MaximumSpeed INVALID_HANDLE;
bool Speeding [MAXPLAYERS+1];

public 
Plugin myinfo 
{
    
name "L4D2 Speed Booster",
    
author "alasfourom",
    
description "Allowing Speical Infected To Speed Boost When SHIFT Is Pressed",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/"
}

public 
void OnPluginStart()
{
    
CreateConVar ("l4d2_speed_booster_version"PLUGIN_VERSION"Players Speed Booster"FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
SpeedAllowed CreateConVar    ("l4d2_speed_allowed""1""Enable Speed Booster Plugin [ 0 = Disable - 1 = Enable ]"FCVAR_NOTIFYtrue0.0true1.0);
    
MaximumSpeed CreateConVar    ("l4d2_maximum_speed""1.25""Set your maximum speed [ Default = 1.0 - Maximum = 2.0]"FCVAR_NOTIFYtrue0.0true2.0);
    
AutoExecConfig (true"L4D2_Speed_Booster");
}

public 
void OnMapStart()
{
    
PrecacheSound (SOUNDtrue);
}

public 
Action OnPlayerRunCmd (int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weapon)
{
    if (
buttons IN_SPEED && GetEntityFlags(client) & FL_ONGROUND && GetConVarBool(SpeedAllowed))
    {
        if (
client && IsClientInGame(client) && !IsFakeClient(client) && IsInfected(client))
        {
            
buttons &= ~IN_SPEED;            
            if (
Speeding [client])
            {
                
SetClientSpeed(clientGetConVarFloat(MaximumSpeed));
                return 
Plugin_Continue;
            }
            else
            {
                
Speeding [client] = true;
                
SetClientSpeed(clientGetConVarFloat(MaximumSpeed));
                
EmitSoundToClient(clientSOUNDclientSNDCHAN_WEAPONSNDLEVEL_SCREAMING);
                return 
Plugin_Continue;
            }
        }
        else
        {
            if (
Speeding [client])
            {
                
Speeding [client] = false;
                
SetEntPropFloat (clientProp_Data"m_flLaggedMovementValue"1.0);
                return 
Plugin_Continue;
            }
        }
    }
    else
    {
        if (
Speeding [client])
        {
            
Speeding [client] = false;
            
SetEntPropFloat (clientProp_Data"m_flLaggedMovementValue"1.0);
            return 
Plugin_Continue;
        }
    }
    return 
Plugin_Continue;
}

stock bool IsInfected(int client)
{
    return (
GetClientTeam(client) == 3);
}

stock int SetClientSpeed (int clientfloat ammount)
{
    
SetEntPropFloat (clientProp_Data"m_flLaggedMovementValue"ammount);
    return 
true;


I thought this may work but it didnt

PHP Code:

public void Event_InfectedAbilityStart (Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId (event.GetInt("userid"));
    if (
client && IsClientInGame(client) && !IsFakeClient(client) && IsInfected(client))
    {
        
Speeding [client] = false;
        
SetEntPropFloat (clientProp_Data"m_flLaggedMovementValue"1.0);
    }
    return;


Thanks

Marttt 07-07-2022 20:42

Re: [L4D2] How to stop plugin when HookEvent is triggered
 
Probably what happens is that you set "Speeding[client] = false" but in the next frame it backs to "true" again, cause OnPlayerRunCmd run dozen times per seconds.

Basically you need to track the event between the ability starts, and when it ends, block it in another variable and while "true", return Plugin_Continue


All times are GMT -4. The time now is 00:58.

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