AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How do I get a value from an entity output? (https://forums.alliedmods.net/showthread.php?t=332998)

SauerkrautKebap 06-13-2021 08:41

How do I get a value from an entity output?
 
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 06-14-2021 13:59

Re: How do I get a value from an entity output?
 
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.

asherkin 06-14-2021 14:21

Re: How do I get a value from an entity output?
 
Quote:

Originally Posted by SauerkrautKebap (Post 2749733)
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.

AdRiAnIlloO 06-14-2021 15:18

Re: How do I get a value from an entity output?
 
Quote:

Originally Posted by asherkin (Post 2749739)
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

asherkin 06-14-2021 16:49

Re: How do I get a value from an entity output?
 
It looks like support was missed from the float functions, I've filed a bug for you.

AdRiAnIlloO 06-14-2021 18:43

Re: How do I get a value from an entity output?
 
Quote:

Originally Posted by asherkin (Post 2749746)
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!


All times are GMT -4. The time now is 23:01.

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