AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to activate func_button (https://forums.alliedmods.net/showthread.php?t=313708)

farawayf 01-19-2019 11:40

How to activate func_button
 
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");
    }



Ilusion9 01-19-2019 11:48

Re: How to activate func_button
 
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 


farawayf 01-19-2019 12:08

Re: How to activate func_button
 
Quote:

Originally Posted by Ilusion9 (Post 2635484)
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

Ilusion9 01-19-2019 12:35

Re: How to activate func_button
 
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



farawayf 01-19-2019 13:03

Re: How to activate func_button
 
Quote:

Originally Posted by Ilusion9 (Post 2635493)
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"

Mitchell 01-19-2019 15:15

Re: How to activate func_button
 
AcceptEntityInput(ent, "Use", client);
ent being the button, client being the one pressing the button

ThatOneGuy 01-19-2019 22:44

Re: How to activate func_button
 
Quote:

Originally Posted by Mitchell (Post 2635512)
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);


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

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