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

How do I get a value from an entity output?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SauerkrautKebap
New Member
Join Date: May 2021
Old 06-13-2021 , 08:41   How do I get a value from an entity output?
Reply With Quote #1

I'm trying to hook OnSidesPicked from the mapvetopick_controller using
PHP Code:
HookEntityOutput("mapvetopick_controller""OnSidesPicked"Entity_VetoController_OnSidesPicked); 
but how do I get the int that tells me if the teams switched or stayed?
SauerkrautKebap is offline
SauerkrautKebap
New Member
Join Date: May 2021
Old 06-14-2021 , 13:59   Re: How do I get a value from an entity output?
Reply With Quote #2

Thanks to AdRiAnIlloOs help, I managed to get this code to work:

PHP Code:
public void OnPluginStart()
{
    
HookEntityOutput("mapvetopick_controller""OnSidesPicked"Entity_VetoController_OnSidesPicked);
}

public 
void Entity_VetoController_OnSidesPicked(const char[] outputint callerint activatorfloat delay)
{
    
int switchSides GetEntProp(callerProp_Data"m_OnSidesPicked");

This does not work for every entity output, tho! The maximum size of GetEntProp() is 1 cell (4 bytes), but most members of COutputVariant are 24 bytes long. If you try to use math_counter::m_OutValue for example, SourceMod is going to throw an exception. The solution is to use GetEntData() like in this example AdRiAnIlloO provided me with:
PHP Code:
#include <sdktools_entoutput>

public void OnMapStart()
{
    
HookEntityOutput("math_counter""OutValue"OnMathCounterOutValue);
}

void OnMathCounterOutValue(const char[] outputint callerint activatorfloat delay)
{
    
float value GetEntDataFloat(callerFindDataMapInfo(caller"m_OutValue"));
    
PrintToServer("OnMathCounterOutValue called. New value = %f."value);

GetEntData() performs no strict checking like GetEntProp() so it's less save to use but gets the job done.

Apparently there has been an attempt by the devs to also make it work with GetEntProp():
https://forums.alliedmods.net/showpo...5&postcount=16
But this has never made it to the stable branches.
SauerkrautKebap is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-14-2021 , 14:21   Re: How do I get a value from an entity output?
Reply With Quote #3

Quote:
Originally Posted by SauerkrautKebap View Post
Apparently there has been an attempt by the devs to also make it work with GetEntProp():
https://forums.alliedmods.net/showpo...5&postcount=16
But this has never made it to the stable branches.
That PR was merged back when SM 1.9 was the development branch, so both 1.9 (the previous stable branch) and 1.10 (the current stable branch) have support for reading variant props.
__________________

Last edited by asherkin; 06-14-2021 at 14:22.
asherkin is offline
AdRiAnIlloO
Member
Join Date: Jul 2015
Location: Spain
Old 06-14-2021 , 15:18   Re: How do I get a value from an entity output?
Reply With Quote #4

Quote:
Originally Posted by asherkin View Post
That PR was merged back when SM 1.9 was the development branch, so both 1.9 (the previous stable branch) and 1.10 (the current stable branch) have support for reading variant props.
Alright, so I have to hop in. First, I'd like so say that my mention to
Code:
COutputVariant
was a mistake, I meant
Code:
CBaseEntityOutput
instead.

Then, it gave me the impression that such support wasn't applied on the stable branch (I'm using 1.10) because using the following code:

Code:
#include <sdktools_entoutput>

public void OnMapStart()
{
    HookEntityOutput("math_counter", "OutValue", OnMathCounterOutValue);
}

void OnMathCounterOutValue(const char[] output, int caller, int activator, float delay)
{
    float value = GetEntPropFloat(caller, Prop_Data, "m_OutValue");
    PrintToServer("OnMathCounterOutValue called. New value = %f.", value);
}
I get the error:

Code:
L 06/14/2021 - 19:14:00: [SM] Exception reported: Data field m_OutValue is not a float (11 != [1,16])
L 06/14/2021 - 19:14:00: [SM] Blaming: outputtest.smx
L 06/14/2021 - 19:14:00: [SM] Call stack trace:
L 06/14/2021 - 19:14:00: [SM]   [0] GetEntPropFloat
L 06/14/2021 - 19:14:00: [SM]   [1] Line 10, d:\Source\sourcemod-plugins\scripting\outputtest.sp:
How I would fix it using
Code:
GetEntProp
variants, then? Thanks
AdRiAnIlloO is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-14-2021 , 16:49   Re: How do I get a value from an entity output?
Reply With Quote #5

It looks like support was missed from the float functions, I've filed a bug for you.
__________________
asherkin is offline
AdRiAnIlloO
Member
Join Date: Jul 2015
Location: Spain
Old 06-14-2021 , 18:43   Re: How do I get a value from an entity output?
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
It looks like support was missed from the float functions, I've filed a bug for you.
Alright, good that I casually found a bug unintentionally while helping another guy lol. Well, thanks!
AdRiAnIlloO 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 08:02.


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