AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Command to change ConVar (true:false) (https://forums.alliedmods.net/showthread.php?t=265105)

maciasbarlinek 06-24-2015 17:20

Command to change ConVar (true:false)
 
Hello,

Purpose: Make command to change ConVar (sm_antistucknoblock)
Description: Command sm_nb should change ConVar sm_antistucknoblock true:false (if 1 --> 0, if 0 --> 1)

How should look the code?
maciasbarlinek

friagram 06-24-2015 21:16

Re: Command to change ConVar (true:false)
 
https://sm.alliedmods.net/api/index....d=show&id=481&

Powerlord 06-24-2015 22:28

Re: Command to change ConVar (true:false)
 
Quote:

Originally Posted by friagram (Post 2311707)

Don't forget https://sm.alliedmods.net/api/index....d=show&id=480& and https://sm.alliedmods.net/api/index....d=show&id=476&

maciasbarlinek 06-25-2015 06:17

Re: Command to change ConVar (true:false)
 
antistuck_noblock.sp

Code:

#include <sourcemod>
#include <sdktools>
#define VERSION "1.1"

public Plugin:myinfo =
{
    name = "SM Anti-Stuck NoBlock",
    author = "Franc1sco steam: franug",
    description = "give to all players a simple Anti-Stuck NoBlock",
    version = VERSION,
    url = "http://servers-cfg.foroactivo.com/"
};

new Handle:sm_noblock;
new bool:enable;
#define COLLISION_GROUP_PUSHAWAY 17
#define COLLISION_GROUP_PLAYER 5

public OnPluginStart()
{
    HookEvent("player_spawn", OnSpawn);
    sm_noblock = CreateConVar("sm_antistucknoblock", "1");
    CreateConVar("sm_antistucknoblock_version", VERSION, _, FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    HookConVarChange(sm_noblock, OnCVarChange);
}

public OnCVarChange(Handle:convar_hndl, const String:oldValue[], const String:newValue[])
{
    GetCVars();
}

public OnConfigsExecuted()
{
    GetCVars();
}

public OnSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!enable)
        return;
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    SetEntProp(client, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PUSHAWAY);
}

public GetCVars()
{
    enable = GetConVarBool(sm_noblock);
    if(enable)
        EnableBlock();
    else
        DisableBlock();
}

EnableBlock()
{
    for(new i=1; i <= MaxClients; i++)
        if (IsClientInGame(i) && IsPlayerAlive(i))
            SetEntProp(i, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PUSHAWAY);
}

DisableBlock()
{
    for(new i=1; i <= MaxClients; i++)
        if (IsClientInGame(i) && IsPlayerAlive(i))
            SetEntProp(i, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PLAYER);
}

Can you edit this code and make command with fuctions??
Thank you

DJ Data 06-25-2015 11:44

Re: Command to change ConVar (true:false)
 
PHP Code:

#pragma semicolon 1
#include <sourcemod>
#define PLUGIN_VERSION "1.0"

public Plugin:myinfo =
{
    
name "AntiStuck ConVar Changer",
    
author "Danian",
    
description "Changes ConVar: sm_antistucknoblock",
    
version PLUGIN_VERSION,
    
url "http://danian.website"
};

public 
OnPluginStart()
{
    
RegAdminCmd("sm_nb"Command_NBADMFLAG_ROOT);
}

public 
Action:Command_NB(clientargs)
{
    new 
Handle:convar FindConVar("sm_antistucknoblock");
    
    if(
GetConVarInt(convar) == 1)
    {
        
SetConVarInt(convar0);
    }
    else if(
GetConVarInt(convar) == 0)
    {
        
SetConVarInt(convar1);
    }



ddhoward 06-25-2015 14:50

Re: Command to change ConVar (true:false)
 
Quote:

Originally Posted by DJ Data (Post 2311986)
Spoiler

Nice handle leak.

Here's basically the same code sans handle-leak, and with the new syntax.

PHP Code:

public OnPluginStart() {
    
RegAdminCmd("sm_nb"Command_NBADMFLAG_ROOT);
}

public 
Action Command_NB(int clientint args) {
    static 
ConVar cvar;
    if (
cvar == nullcvar FindConVar("sm_antistucknoblock");
    if (
cvar != nullcvar.BoolValue = !cvar.BoolValue;



DJ Data 06-25-2015 14:55

Re: Command to change ConVar (true:false)
 
Quote:

Originally Posted by ddhoward (Post 2312021)
Nice handle leak.

Here's basically the same code sans handle-leak, and with the new syntax.

PHP Code:

public OnPluginStart() {
    
RegAdminCmd("sm_nb"Command_NBADMFLAG_ROOT);
}

public 
Action Command_NB(int clientint args) {
    static 
ConVar cvar;
    if (
cvar == nullcvar FindConVar("sm_antistucknoblock");
    if (
cvar != nullcvar.BoolValue = !cvar.BoolValue;



I dont even know what a handle leak is ;_;

maciasbarlinek 06-25-2015 15:42

Re: Command to change ConVar (true:false)
 
Quote:

Originally Posted by DJ Data (Post 2311986)
PHP Code:

#pragma semicolon 1
#include <sourcemod>
#define PLUGIN_VERSION "1.0"

public Plugin:myinfo =
{
    
name "AntiStuck ConVar Changer",
    
author "Danian",
    
description "Changes ConVar: sm_antistucknoblock",
    
version PLUGIN_VERSION,
    
url "http://danian.website"
};

public 
OnPluginStart()
{
    
RegAdminCmd("sm_nb"Command_NBADMFLAG_ROOT);
}

public 
Action:Command_NB(clientargs)
{
    new 
Handle:convar FindConVar("sm_antistucknoblock");
    
    if(
GetConVarInt(convar) == 1)
    {
        
SetConVarInt(convar0);
    }
    else if(
GetConVarInt(convar) == 0)
    {
        
SetConVarInt(convar1);
    }



Nice, THANK YOU VERY MUCH

ddhoward 06-25-2015 15:53

Re: Command to change ConVar (true:false)
 
1 Attachment(s)
Quote:

Originally Posted by maciasbarlinek (Post 2312038)
Nice, THANK YOU VERY MUCH

Do not use that code. It contains a memory leak. Use mine instead.

maciasbarlinek 06-25-2015 16:27

Re: Command to change ConVar (true:false)
 
Quote:

Originally Posted by ddhoward (Post 2312043)
Do not use that code. It contains a memory leak. Use mine instead.

Can you add notice PrintCenterTextAll that convar was turned on/off? (if 0 --> Turned off, if 1 --> Turned on)


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

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