Implemented CanChangeToGrade hook (Rust)

Discussion in 'Feature Suggestions' started by Fujikura, May 12, 2017.

  1. Fujikura

    Fujikura Plugin Developer

    Due to latest changes to the build/upgrade rights system, i would like to see a new hook "CanChangeToGrade" in the following function (called by BuildingBlock.DoUpgradeToGrade):
    Code (C#):
    // BuildingBlock
    private bool CanChangeToGrade(BuildingGrade.Enum iGrade, BasePlayer player)
    {
        //BEGIN
        object obj = Oxide.Core.Interface.CallHook("CanChangeToGrade", new object[]
        {
            this,
            iGrade,
            player
        });
        if (obj is bool)
        {
            return (bool)obj;
        }
        //END
        return this.HasUpgradePrivilege(iGrade, player) && !this.IsUpgradeBlocked();
    }
    It would allow to change the results of this...
    Code (C#):
    // BuildingBlock
    private bool HasUpgradePrivilege(global::BuildingGrade.Enum iGrade, global::BasePlayer player)
    {
     return iGrade != this.grade && iGrade < (global::BuildingGrade.Enum)this.blockDefinition.grades.Length && iGrade >= global::BuildingGrade.Enum.Twigs && iGrade >= this.grade && !player.IsBuildingBlocked(base.transform.position, base.transform.rotation, this.bounds);
    }
     
    ...and my main objective to be intercepted by the hook:
    Code (C#):
    // BuildingPrivlidge
    public static bool IsBlocked(global::BasePlayer player, Vector3 position, Quaternion rotation, Bounds bounds)
    {
        global::BuildingPrivlidge buildingPrivlidge = global::BuildingPrivlidge.Get(position, rotation, bounds);
        return buildingPrivlidge != null && !buildingPrivlidge.IsAuthed(player);
    }
     
  2. Fujikura

    Fujikura Plugin Developer

    @Wulf or @Mughisi
    Could you guys have a look into this? (If you guys not already have done so)
    Thx, Fuji
     
  3. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Yeah, we'll have to do another batch of hooks soon.
     
    Trippy and Fujikura like this.
  4. Fujikura

    Fujikura Plugin Developer

    Sounds good., Many thanks.
     
  5. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Added locally, will push once I get a few others added.

    I think the order of the args will be BasePlayer player, BuildingBlock block, BuildingGrade/Enum grade) though.
     
    jemes. and Fujikura like this.
  6. Fujikura

    Fujikura Plugin Developer

    Muchas gracias