Raised This Month: $ Target: $400
 0% 

Command to change ConVar (true:false)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
maciasbarlinek
Senior Member
Join Date: May 2015
Old 06-24-2015 , 17:20   Command to change ConVar (true:false)
Reply With Quote #1

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
__________________
cam0 & lingzhidiyu - The best users
maciasbarlinek is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 06-24-2015 , 21:16   Re: Command to change ConVar (true:false)
Reply With Quote #2

https://sm.alliedmods.net/api/index....d=show&id=481&
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-24-2015 , 22:28   Re: Command to change ConVar (true:false)
Reply With Quote #3

Quote:
Originally Posted by friagram View Post
Don't forget https://sm.alliedmods.net/api/index....d=show&id=480& and https://sm.alliedmods.net/api/index....d=show&id=476&
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
maciasbarlinek
Senior Member
Join Date: May 2015
Old 06-25-2015 , 06:17   Re: Command to change ConVar (true:false)
Reply With Quote #4

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
__________________
cam0 & lingzhidiyu - The best users
maciasbarlinek is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 06-25-2015 , 11:44   Re: Command to change ConVar (true:false)
Reply With Quote #5

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);
    }

__________________
SourcePawn Coding Level: Novice
DJ Data is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-25-2015 , 14:50   Re: Command to change ConVar (true:false)
Reply With Quote #6

Quote:
Originally Posted by DJ Data View Post
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;

__________________

Last edited by ddhoward; 06-25-2015 at 14:53.
ddhoward is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 06-25-2015 , 14:55   Re: Command to change ConVar (true:false)
Reply With Quote #7

Quote:
Originally Posted by ddhoward View Post
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 ;_;
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
maciasbarlinek
Senior Member
Join Date: May 2015
Old 06-25-2015 , 15:42   Re: Command to change ConVar (true:false)
Reply With Quote #8

Quote:
Originally Posted by DJ Data View Post
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
__________________
cam0 & lingzhidiyu - The best users

Last edited by maciasbarlinek; 06-25-2015 at 15:43.
maciasbarlinek is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-25-2015 , 15:53   Re: Command to change ConVar (true:false)
Reply With Quote #9

Quote:
Originally Posted by maciasbarlinek View Post
Nice, THANK YOU VERY MUCH
Do not use that code. It contains a memory leak. Use mine instead.
Attached Files
File Type: sp Get Plugin or Get Source (toggleASNB.sp - 357 views - 291 Bytes)
__________________

Last edited by ddhoward; 06-25-2015 at 15:54.
ddhoward is offline
maciasbarlinek
Senior Member
Join Date: May 2015
Old 06-25-2015 , 16:27   Re: Command to change ConVar (true:false)
Reply With Quote #10

Quote:
Originally Posted by ddhoward View Post
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)
__________________
cam0 & lingzhidiyu - The best users

Last edited by maciasbarlinek; 06-25-2015 at 16:31.
maciasbarlinek is offline
Reply


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 05:16.


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