AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How can i make a enable/disable toggle cvar? (https://forums.alliedmods.net/showthread.php?t=317058)

faketuna 06-23-2019 20:49

How can i make a enable/disable toggle cvar?
 
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;
}


8guawong 06-23-2019 21:56

Re: How can i make a enable/disable toggle cvar?
 
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;
}



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

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