Prevent plants for dying

Can someone make a simple plugin that prevents plants from dying and just stay in Ripe stage indefinitely? 

Prabobly only hook to do it.

object OnEntityFlagsNetworkUpdate(BaseEntity entity)

{
    Puts("OnEntityFlagsNetworkUpdate works!");
    return null;
}
9ltcuMb6EOrRZlz.jpg ArtiIOMI

Prabobly only hook to do it.

object OnEntityFlagsNetworkUpdate(BaseEntity entity)

{
    Puts("OnEntityFlagsNetworkUpdate works!");
    return null;
}

Not even close

LEVMACLIK09LeKf.png Orange

Not even close

Ok. Then it's not so easy to do. Is there some hook where growing call some hook?
0FUy2UiABxTsEZ9.jpg ArtiIOMI
Ok. Then it's not so easy to do. Is there some hook where growing call some hook?

You can open main entity class and check in decompiler 

ZUEVcrqOo1ZmtWz.png Orange

You can open main entity class and check in decompiler 

Thanks a lot, you're my time safer.



Merged post

I wrote something, but doesn't tested it yet.
Link to GitHub with plugin. In future i try to add this to uMod plugins base.

Full plugin code.

namespace Oxide.Plugins
{
    [Info("Plants Never Die", "ArtiIOMI", "0.0.1")]
    [Description("Plants never die")]
    internal class PlantsNeverDie : RustPlugin
    {
    #region Oxide Hooks
        void OnGrowableStateChange(GrowableEntity entity, PlantProperties.State state){
            if(state != PlantProperties.State.Dying)
                return;
            state = PlantProperties.State.Ripe;
            entity.stageAge = 0.0f;
        }
    #endregion
    }
}

 

Thanks very much

Wow you rock thank you :)

OnGrowableStateChange should return object..

object OnGrowableStateChange(GrowableEntity entity, PlantProperties.State state)

Would it be possible to apply to a specific player with a permission or it has to be server wide only?

gfhlyJOjWkop6np.jpg Lorenzo

OnGrowableStateChange should return object..

object OnGrowableStateChange(GrowableEntity entity, PlantProperties.State state)

It CAN return object, it can be void too

M7jLQNQf6JYQogP.png Orange

It CAN return object, it can be void too

I agree, but returning true (or non null) would stop the processing of the GrowableEntity.ChangeState

Unless i am mistaken, modifying the parameter 

state = PlantProperties.State.Ripe;​
will not affect the caller function and will not work for this. the plant will still continue to the Dying phase
8x0K2yqAZsHPLMq.jpg Lorenzo

I agree, but returning true (or non null) would stop the processing of the GrowableEntity.ChangeState

Unless i am mistaken, modifying the parameter 

state = PlantProperties.State.Ripe;​
will not affect the caller function and will not work for this. the plant will still continue to the Dying phase

Better plan i think is to cancel invoke for growing and setting normal state :wink:

x86joJlwu1RHXUE.jpg Lorenzo

I agree, but returning true (or non null) would stop the processing of the GrowableEntity.ChangeState

Unless i am mistaken, modifying the parameter 

state = PlantProperties.State.Ripe;​
will not affect the caller function and will not work for this. the plant will still continue to the Dying phase

When I was writing my first plugin in here, Wolf send me massage to change some vars instead using returns.

Here you have function where is callhook.

public void ChangeState(PlantProperties.State state, bool resetAge, bool loading = false)
  {
    if (Interface.CallHook("OnGrowableStateChange", (object) this, (object) state) != null || this.isServer && this.State == state)
      return;
    this.State = state;
    if (!this.isServer)
      return;
    if (!loading)
    {
      if ((double) this.currentStage.resources > 0.0)
        this.yieldPool = this.currentStage.yield;
      if (state == PlantProperties.State.Crossbreed)
      {
        if (this.Properties.CrossBreedEffect.isValid)
          Effect.server.Run(this.Properties.CrossBreedEffect.resourcePath, this.transform.position, Vector3.up);
        GrowableGenetics.CrossBreed(this);
      }
      this.SendNetworkUpdate();
    }
    if (!resetAge)
      return;
    this.stageAge = 0.0f;
  }

Like you see if callhook is true/false then function ChangeState will be stoped. Other way it will be go thru to rest of code.