Raised This Month: $ Target: $400
 0% 

How can i make a enable/disable toggle cvar?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-23-2019 , 21:56   Re: How can i make a enable/disable toggle cvar?
Reply With Quote #2

Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

Handle g_hEnablePlugin = INVALID_HANDLE;

public void OnPluginStart()
{
    RegConsoleCmd("sm_knife", Knife, "", 0);
    RegConsoleCmd("sm_knife", Knife);
    g_hEnablePlugin = CreateConVar("sm_knife_enable", "1", "Disabled/enabled [0/1]", 0, true, 0.0, true, 1.0);
}

public Action:Knife(client, args)
{
    if (!GetConVarBool(g_hEnablePlugin) || !IsTeamOneSide())
    {
        return Action:3;
    }
    if (!IsValidEntity(GetPlayerWeaponSlot(client, 2)))
    {
        if(GetConVarBool(g_hEnablePlugin))
        {
            GivePlayerItem(client, "weapon_knife", 0);
        }
    }
    return Action:3;
}

GetCountsPlayingInTeam(team)
{
    int iPlaysNum;
    int i = 1;
    while (i <= MaxClients)
    {
        if (IsClientConnected(i) && IsClientInGame(i))
        {
            if (team == GetClientTeam(i))
            {
                iPlaysNum++;
            }
        }
        i++;
    }
    return iPlaysNum;
}

bool IsTeamOneSide()
{
    if ((GetCountsPlayingInTeam(2) > 0 && GetCountsPlayingInTeam(3)) || (GetCountsPlayingInTeam(3) > 0 && GetCountsPlayingInTeam(2)))
    {
        return true;
    }
    return false;
}
__________________
8guawong is offline
 


Thread Tools
Display Modes

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 00:53.


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