Raised This Month: $32 Target: $400
 8% 

How to activate func_button


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
farawayf
Senior Member
Join Date: Jan 2019
Old 01-19-2019 , 11:40   How to activate func_button
Reply With Quote #1

Hello.

How i can activate func_button "target name" with command ? I find that code but it crash server when i type command
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
      
RegAdminCmd"sm_activatebutton"CmdbuttonADMFLAG_ROOT);
}

public 
Action:Cmdbuttonclientargs )
{
    
decl String:TargetName[128];
    new 
CurEnt FindEntityByClassname(-1"func_button");
    while (
CurEnt >= 0
    {
        
GetEntPropString(CurEntProp_Data"m_iName"TargetName128);
        if (
StrEqual(TargetName"button_name")) 
        {
            
LogMessage("%d : %s"CurEntTargetName);
            
ActivateEntity(CurEnt);
        }
        
CurEnt FindEntityByClassname(CurEnt"func_button");
    }


Last edited by farawayf; 01-19-2019 at 11:41.
farawayf is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-19-2019 , 11:48   Re: How to activate func_button
Reply With Quote #2

PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

public void OnPluginStart()
{
      
RegAdminCmd("sm_activatebutton"CmdbuttonADMFLAG_ROOT);
}

public 
Action Cmdbutton(int clientint args)
{
    
char targetName[128];
    
GetCmdArg(1targetNamesizeof(targetName));

    
int ent = -1;

    while ((
ent FindEntityByClassname(ent"func_button")) != -1
    {
        
char buttonName[128];
        
GetEntPropString(entProp_Data"m_iName"buttonNamesizeof(buttonName));
       
        if (
StrEqual(targetNamebuttonName
        {
            
AcceptEntityInput(ent"Press");
            return 
Plugin_Handled;
        }
    }

    return 
Plugin_Handled;

Your server crash because because of this code:
PHP Code:

    
new CurEnt FindEntityByClassname(-1"func_button"); // CurEnt = entity if exists
    
while (CurEnt >= 0) {} // if an entity "func_button" exists, then this is an infinite loop 
__________________

Last edited by Ilusion9; 01-19-2019 at 11:48.
Ilusion9 is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-19-2019 , 12:08   Re: How to activate func_button
Reply With Quote #3

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

public void OnPluginStart()
{
      
RegAdminCmd("sm_activatebutton"CmdbuttonADMFLAG_ROOT);
}

public 
Action Cmdbutton(int clientint args)
{
    
char targetName[128];
    
GetCmdArg(1targetNamesizeof(targetName));

    
int ent = -1;

    while ((
ent FindEntityByClassname(ent"func_button")) != -1
    {
        
char buttonName[128];
        
GetEntPropString(entProp_Data"m_iName"buttonNamesizeof(buttonName));
       
        if (
StrEqual(targetNamebuttonName
        {
            
AcceptEntityInput(ent"Press");
            return 
Plugin_Handled;
        }
    }

    return 
Plugin_Handled;

Your server crash because because of this code:
PHP Code:

    
new CurEnt FindEntityByClassname(-1"func_button"); // CurEnt = entity if exists
    
while (CurEnt >= 0) {} // if an entity "func_button" exists, then this is an infinite loop 
Thanks for noticing.
Still crashing the server.

Perhaps a stupid question: where do i set the name of the button here? Maybe I'm doing it wrong
farawayf is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-19-2019 , 12:35   Re: How to activate func_button
Reply With Quote #4

You haven't used my code because it doesn't even compile.
It's easy to talk that your server crashes because you are still using your code.

Use this:

PHP Code:

#pragma semicolon 1 

#include <sourcemod> 
#include <sdktools> 

public void OnPluginStart() 

    
RegAdminCmd("sm_activatebutton"Command_ActivateButtonADMFLAG_ROOT"sm_activatebutton <name>"); 


public 
Action Command_ActivateButton(int clientint args
{
    if (
args 1)
    {
        
ReplyToCommand(client"[SM] Usage: sm_activatebutton <name>");
        return 
Plugin_Handled
    }
    
    
char arg[65]; 
    
GetCmdArg(1argsizeof(arg)); 

    
int entity = -1
    while ((
entity FindEntityByClassname(entity"func_button")) != -1)
    {
        
char name[65]; 
        
GetEntPropString(entityProp_Data"m_iName"namesizeof(name)); 
        
        if (
StrEqual(argname))
        { 
            
AcceptEntityInput(entity"Press"); 
            return 
Plugin_Handled
        } 
    } 

    return 
Plugin_Handled

__________________
Ilusion9 is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-19-2019 , 13:03   Re: How to activate func_button
Reply With Quote #5

Quote:
Originally Posted by Ilusion9 View Post
You haven't used my code because it doesn't even compile.
It's easy to talk that your server crashes because you are still using your code.

Use this:

PHP Code:

#pragma semicolon 1 

#include <sourcemod> 
#include <sdktools> 

public void OnPluginStart() 

    
RegAdminCmd("sm_activatebutton"Command_ActivateButtonADMFLAG_ROOT"sm_activatebutton <name>"); 


public 
Action Command_ActivateButton(int clientint args
{
    if (
args 1)
    {
        
ReplyToCommand(client"[SM] Usage: sm_activatebutton <name>");
        return 
Plugin_Handled
    }
    
    
char arg[65]; 
    
GetCmdArg(1argsizeof(arg)); 

    
int entity = -1
    while ((
entity FindEntityByClassname(entity"func_button")) != -1)
    {
        
char name[65]; 
        
GetEntPropString(entityProp_Data"m_iName"namesizeof(name)); 
        
        if (
StrEqual(argname))
        { 
            
AcceptEntityInput(entity"Press"); 
            return 
Plugin_Handled
        } 
    } 

    return 
Plugin_Handled

Thanks you. Everything works fine.

Sorry to appeal to you again, but it’s not working the way I would like. I would like to do this: the administrator writes the command “sm_activatebutton 1 (or 2, 3, etc.)” And, for example, 1 - button_open, 2 - button_close, 3 - button_slay etc.
Not to write every time the name of the buttons like "sm_activatebutton button_open"

Last edited by farawayf; 01-19-2019 at 13:07.
farawayf is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-19-2019 , 15:15   Re: How to activate func_button
Reply With Quote #6

AcceptEntityInput(ent, "Use", client);
ent being the button, client being the one pressing the button
Mitchell is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 01-19-2019 , 22:44   Re: How to activate func_button
Reply With Quote #7

Quote:
Originally Posted by Mitchell View Post
AcceptEntityInput(ent, "Use", client);
ent being the button, client being the one pressing the button
Similarly, I've used the following to trigger buttons:
Code:
AcceptEntityInput(iEntID, "Press", client, iEntID);
__________________
ThatOneGuy 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 09:18.


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