1. Hello. I'm tryin to edit the plugin RotateOnUpgrade for remove wall after Hammer hit, but nothing is happen.
    I know, many in this plugin is wrong, but I hope U can help me.
    Code:
    using System;
    using System.Collections.Generic;
    using UnityEngine;
    using Rust;namespace Oxide.Plugins
    {
        [Info("RotateOnUpgrade", "KeyboardCavemen", "1.3.0")]
        class RotateOnUpgrade : RustPlugin
        {
            //Oxide Hook
            void OnServerInitialized()
            {        }        //Oxide Hook
            protected override void LoadDefaultConfig()
            {        }        //Oxide Hook
            void OnPlayerInput(BasePlayer player, InputState input)
            {
                if (player.IsAdmin() && player.GetActiveItem() != null && player.GetActiveItem().info.shortname.Equals("hammer"))
                {
                    if (input.WasJustPressed(BUTTON.FIRE_PRIMARY))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(player.eyes.position, (player.eyes.rotation * Vector3.forward), out hit, 2f, Layers.Server.Buildings))
                        {
                            BaseEntity baseEntity = hit.collider.gameObject.ToBaseEntity();
                            if (baseEntity != null)
                            {
                                BuildingBlock block = baseEntity.GetComponent<BuildingBlock>();                            if (block != null && block.blockDefinition.canRotate && !block.HasFlag(BaseEntity.Flags.Reserved1))
                                {
                                    block.SetFlag(BaseEntity.Flags.Reserved1, true);                                SendReply(player, "Called");
                                }
                            }
                        }
                    }
                }
            }    }
    }
     
  2. Have you placed Puts("debug inner cycle"); debug console outputs to see where the methods does exit before?
     
  3. Something wrong with:

    Code:
    BaseEntity baseEntity = hit.collider.gameObject.ToBaseEntity();
    if (baseEntity != null)
    {
        puts("Not null");
    }
    I don't get Not null message.
    [DOUBLEPOST=1453642767,1453555447][/DOUBLEPOST]HACHI MODE: On
     
  4. but SendReply(player, "Called"); never gets called?
     
  5. OnPlayerInput is a horrible way to do this. A hook was actually added in the past to allow you to capture hits of the hammer (Oxide Documentation) as Sanlerus also mentioned above.
    Code:
    void OnHammerHit(BasePlayer player, HitInfo info)
    {
        // Your code here...
    }
    To obtain the object the user hits you just need to grab the target out of the HitInfo object and check if it is a building block, no need to do any raycast either.
     
  6. Thanks a lot! :)

    Next question — it required to set Reserved1/Reserved2 to false after rotate/remove the wall? Maybe for RAM saving or etc.
     
    Last edited by a moderator: Jan 25, 2016
  7. Code:
            private void OnHammerHit(BasePlayer player, HitInfo info)
            {
                if (player.IsAdmin() && info?.HitEntity != null) {
                    var block = info.HitEntity.GetComponent<BuildingBlock>();                if (block != null && block.blockDefinition.canRotate && !block.HasFlag(BaseEntity.Flags.Reserved1)) {
                        block.SetFlag(BaseEntity.Flags.Reserved1, true);
                        timer.In(30f, () =>  block?.SetFlag(BaseEntity.Flags.Reserved1, false)); // reset after 30 seconds
                        SendReply(player, "You can rotate this block for 30 seconds");
                    }
                }
            }
          
    
    untested