Raised This Month: $51 Target: $400
 12% 

Assigning a client index to a button


Post New Thread Reply   
 
Thread Tools Display Modes
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 04-13-2016 , 06:45   Re: Assigning a client index to a button
Reply With Quote #11

Just to be clear, you only need to check one button?
Phil25 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-13-2016 , 07:26   Re: Assigning a client index to a button
Reply With Quote #12

...what if try something simple first.
Go touch that button and look your in game console.
Use command sm_button to look all func_buttons on map.
PHP Code:
#include <sdktools>


public void OnPluginStart()
{
    
RegConsoleCmd("sm_button"sm_button);
    
HookEntityOutput("func_button""OnPressed"OnPressed);
}

public 
Action sm_button(int clientint args)
{
    
int ent MaxClients +1;

    while( (
ent FindEntityByClassname(ent"func_button")) != -)
    {
        
char m_iName[MAX_NAME_LENGTH];
        
GetEntPropString(entProp_Data"m_iName"m_iNamesizeof(m_iName));
        
PrintToConsole(client"Button index %i name '%s'"entm_iName);
    }
    return 
Plugin_Handled;
}

public 
void OnPressed(const char[] outputint callerint activatorfloat delay)
{
    if(
activator <= MaxClients && IsClientInGame(activator))
    {
        
char m_iName[MAX_NAME_LENGTH];
        
GetEntPropString(callerProp_Data"m_iName"m_iNamesizeof(m_iName));
        
PrintToConsole(activator"Button index %i name '%s'"callerm_iName);
    }

__________________
Do not Private Message @me
Bacardi is offline
adma
Senior Member
Join Date: Oct 2015
Old 04-14-2016 , 02:46   Re: Assigning a client index to a button
Reply With Quote #13

Hi guys, after a bit of testing this seems to work. Thanks for all your help.
Code:
#include <sourcemod>
#include <sdktools>
#include <morecolors>
#include <tf2jail>

#define MAXENTITIES 2048

new bool:isListening[MAXPLAYERS + 1] = false;
new button[MAXENTITIES + 1];

public Plugin:myinfo = 
{
  name = "Button Announce",
  author = "adma",
  description = "Announces button press in chat.",
  version = "3.0"
};

public OnPluginStart()
{
	RegConsoleCmd("sm_button", OnButtonListen, "Enables button stuff.");
	HookEntityOutput("func_button", "OnPressed", OnButtonPressed)
}

public Action:OnButtonListen(int client, int args)
{
	if (isListening[client])
	{
		isListening[client] = false;
		CReplyToCommand(client, "[SM] {uncommon}No longer listening for button presses.")
		return Plugin_Handled;
	}
	else
	{
		isListening[client] = true;
		CReplyToCommand(client, "[SM] {uncommon}Now listening for button presses");
		return Plugin_Handled;
	}
}

public OnButtonPressed(const String:output[], buttonEnt, attacker, Float:delay)
{
	decl String:entity[1024];
	
	GetEntPropString(buttonEnt, Prop_Data, "m_iName", entity, sizeof(entity));
	
	if (IsClientInGame(attacker) && IsPlayerAlive(attacker) && !isListening[attacker])
	{
		button[buttonEnt] = attacker;
	}
	
	if (IsClientInGame(attacker) && IsPlayerAlive(attacker) && isListening[attacker])
	{
		CPrintToChat(attacker, "%N {uncommon}was the last to press button {lime}%s", button[buttonEnt], entity);
	}
}

Last edited by adma; 04-14-2016 at 02:46.
adma is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-14-2016 , 04:54   Re: Assigning a client index to a button
Reply With Quote #14

Code:
new button[MAXENTITIES + 1];
This is a waste of memory. But makes your code simple.
__________________
Neuro Toxin is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-14-2016 , 16:26   Re: Assigning a client index to a button
Reply With Quote #15

Quote:
Originally Posted by Neuro Toxin View Post
Code:
new button[MAXENTITIES + 1];
This is a waste of memory. But makes your code simple.
This is a good example of when tries should be used. Simple and efficient.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers

Last edited by mottzi; 04-14-2016 at 16:26.
mottzi is offline
Send a message via MSN to mottzi
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-14-2016 , 18:44   Re: Assigning a client index to a button
Reply With Quote #16

A trie wouldn't really be suitable either because they indexed by string.

The storage here is int to int (entity->client).
__________________
Neuro Toxin is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 04-14-2016 , 19:43   Re: Assigning a client index to a button
Reply With Quote #17

Regular ArrayList, with a blocksize of 2 would be best, methinks.
__________________

Last edited by ddhoward; 04-14-2016 at 19:43.
ddhoward 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 00:05.


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