Raised This Month: $51 Target: $400
 12% 

How can i make a enable/disable toggle cvar?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
faketuna
New Member
Join Date: Jun 2019
Location: Japan
Old 06-23-2019 , 20:49   How can i make a enable/disable toggle cvar?
Reply With Quote #1

Sorry for my poor English.

hello. im stuck in a adding enable/disable cvar on plugin.
source code here. this plugin is use sm_knife to get a knifes,this plugin for csgo mg server.

I added g_hEnablePlugin but not work.
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 (!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;
}

Last edited by faketuna; 06-23-2019 at 20:55. Reason: added game name
faketuna is offline
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
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 11:05.


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