I have a custom statistic, which I can use to trigger applying a buff etc so seems to be working.
I have also made an interaction which works fine when triggered manually. I would like to make the sim use the interaction when the custom statistic has a certain value (like how a sim eats when hungry etc).
I am not sure how this works, I have tried using the below but it does not work, anyone have any ideas?
What you've posted will test to see if the Sim is allowed to do the interaction autonomously, but it won't push that interaction onto the Sim. What you want is to set a commodity_distress or failure on the statistic itself, and that can then push an interaction (see motive_hunger for example).
Now, as I understand it, you're wanting the interaction to occur when the statistic goes high, correct? If there's no easy way for you to change that to the other direction (trigger interaction when it goes low) then you will not want to use a commodity_distress as it can't have a comparison direction tuned for the threshold, it will only trigger when a statistic goes lower than the threshold.
Commodity failure, on the other hand, can have a comparison tuned for the threshold, and by default is set to check if the statistic is greater or equal to the threshold (default of -100). This is why in the commodity_failure of motive_hunger, the value isn't set (so defaults to -100) but the comparison is set to LESS_OR_EQUAL so Sims die when hunger motive goes low. By leaving the comparison to default (or explicitly setting to GREATER_OR_EQUAL) then the interaction will trigger whenever the statistic goes over the value you set for the threshold.
It does make sense, but still not working. I have the below in my statistic but the interaction never happens. If I apply a buff instead that appears just fine. The interaction is on an object (not the actor) does that make a difference?
Looking at the sims bladder distress, it triggers a non-autonomous animation-only action onto the Sim, sim_BladderDistress, which then uses a post_run_autonomy_commodities tuning to indicate that the Sim should choose an autonomous action to solve the motive_Bladder commodity. This then would seek out an autonomous action (which could be on an object then, e.g. toilet-use-sitting) to solve for the commodity. Of course, this is just to force the action to occur - if you don't want it to be forced then it shouldn't need to be pushed.
Most importantly -- are you sure the autonomy code for the action is setup properly that it will ever occur autonomously? It should have at least something to suggest to the Sim that the interaction will solve that commodity, either an autonomous desire or an advertised statistics change (could be a false advertisement, of course).
I definitely think having the statistic want to be high, and trigger when it goes low, would be a good design change. For instance, a statistic_change advertisement has the SIm wanting a postiive change to the commodity, a negative change to a statistic does not make that autonomous action desireable to a Sim. Motive commoditys decay to a low value and SIm's want to bring them back to high which is encouraged by the statistic advertisements.