Raised This Month: $ Target: $400
 0% 

Detect buttons that is pressed by player in maps.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thenumb3rguy
Senior Member
Join Date: Oct 2012
Location: Hong Kong
Old 11-12-2012 , 05:10   Detect buttons that is pressed by player in maps.
Reply With Quote #1

I want to make a plugin for my zombie escape server that announces something like this: "[SM] {PLAYERNAME} Pressed a button." when a player pressed a button. How do I do that?
thenumb3rguy is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 11-12-2012 , 18:43   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #2

When they trigger a func_button map entity or they press +attack?

The +attack one is simple enough. There's a functional example here though I'd recommend replacing the ongameframe with onplayerruncmd as it's more straightforward and does a lot of the work for you.
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod

Last edited by paegus; 11-12-2012 at 18:45.
paegus is offline
thenumb3rguy
Senior Member
Join Date: Oct 2012
Location: Hong Kong
Old 11-13-2012 , 05:08   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #3

i mean func_button.
thenumb3rguy is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 11-13-2012 , 05:14   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #4

easy to use SDKHooks_UsePost
Despirator is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 11-13-2012 , 05:48   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #5

uhm, why not just hook the OnPressed entity output of the button ?

@paegus your method is not reliable, as you don't have to directly aim at something in order to use it.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 11-13-2012 at 05:50.
berni is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 11-13-2012 , 13:38   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #6

For his ultimate purpose, you're quite correct.

But I didn't mean it to be used it in that context. I just wanted to know what kind of 'button' he meant. A map entity or a client function like +attack or +duck, as I had a relative quick and dirty example of client button detection.
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod
paegus is offline
thenumb3rguy
Senior Member
Join Date: Oct 2012
Location: Hong Kong
Old 11-17-2012 , 04:46   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #7

so far my code:
Code:
#include <sourcemod>
#include <sdktools>
#include <colors>
public Plugin:myinfo = 
{
  name = "button announce",
  author = "Hours Played, Inc.",
  description = "Button Announcements",
  version = "0.9"
};
public OnPluginStart()
{
    HookEntityOutput( "func_button", "OnPressed", pressed)
}
public pressed(const String:output[], caller, attacker, Float:Any)
{
  decl String:user[MAX_NAME_LENGTH];
  decl String:entity[1024];
  GetEntPropString(caller, Prop_Data, "m_iName", entity, sizeof(entity));
  GetClientName(attacker,user, sizeof(user));
  CPrintToChatAll("[{green}SM{default}] {green}%s{default} pressed a button.", user);
  return Plugin_Handled;
}
The problem is, this cant filter flags of func_buttons. I want func_buttons that has flag 1024 : Use Activates to be able to trigger an announcement.
thenumb3rguy is offline
thenumb3rguy
Senior Member
Join Date: Oct 2012
Location: Hong Kong
Old 11-19-2012 , 00:20   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #8

Also how do I filter stuff that don't have func_button flag 1024 (Toggle).
thenumb3rguy is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 11-19-2012 , 03:34   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #9

could try somethign along the lines of...

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <colors>
#define SFL_BLAH 1<<10 // 1024

public Plugin:myinfo 
{
  
name "button announce",
  
author "Hours Played, Inc.",
  
description "Button Announcements",
  
version "0.9"
};
public 
OnPluginStart()
{
    
HookEntityOutput"func_button""OnPressed"pressed)
}
public 
pressed(const String:output[], callerattackerFloat:Any)
{
  
decl String:user[MAX_NAME_LENGTH];
  
decl String:entity[1024];
  
GetEntPropString(callerProp_Data"m_iName"entitysizeof(entity));
  
GetClientName(attacker,usersizeof(user));
  new 
flags GetEntProp(entityProp_Data"m_spawnflags");
  if (
flags SFL_BLAH)
  {
    
CPrintToChatAll("[{green}SM{default}] {green}%s{default} pressed a button that has spawn flag BLAH."user);
  }
  else if (!(
flags SFL_BLAH))
  {
    
CPrintToChatAll("[{green}SM{default}] {green}%s{default} pressed a button that does not have spawn flag BLAH."user);
  }
  return 
Plugin_Continue;

??
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod

Last edited by paegus; 11-19-2012 at 03:35.
paegus is offline
thenumb3rguy
Senior Member
Join Date: Oct 2012
Location: Hong Kong
Old 11-20-2012 , 20:52   Re: Detect buttons that is pressed by player in maps.
Reply With Quote #10

Thanks, I will try this.
thenumb3rguy is offline
Reply



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