1. Code:
    private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
            {
                if (ongoing) return; //Free for all
                if (entity is BasePlayer) return; // Player can be hurt.
                if (entity is BaseNPC) return;
                if (!(entity is BasePlayer)) {
                    string name = entity.name.ToString();
                    if (name.Contains("loot")) return; //We want loot barrels to be breakable during day
                    //if (name.Contains("animals")) return; // We want animals can be hurt.
                    //if (name.Contains("helicopter")) return; // We want helicopter can be hurt.                var block = entity as BuildingBlock;
                    if (block) {
                        if (!protectTwigs && block.grade.ToString() == "Twigs") return;
                        if (!protectWood && block.grade.ToString() == "Wood") return;
                        if (!protectStone && block.grade.ToString() == "Stone") return;
                        if (!protectMetal && block.grade.ToString() == "Metal") return;
                        if (!protectTopTier && block.grade.ToString() == "TopTier") return;
                    }
                }
                info.damageTypes = new DamageTypeList(); //Otherwise set all damages to 0
            }
    I want player can't attack buliding. But Heli Can.
    How to do it?
    Thanks :)
     
  2. Calytic

    Calytic Community Admin Community Mod

    Code:
    if (hitinfo.Initiator.name.Contains("helicopter")) return;
     
  3. Code:
    [Oxide] 17:57 [Error] Failed to call hook 'OnEntityTakeDamage' on plugin 'TimeToPVP v0.1.8' (NullReferenceException: Object reference not set to an instance of an object)
    [Oxide] 17:57 [Debug]   at Oxide.Plugins.TimeToPVP.OnEntityTakeDamage (.BaseCombatEntity entity, .HitInfo info) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.TimeToPVP.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
    Thank you :) It's work. But the server got a lot Error...
    [DOUBLEPOST=1480845578][/DOUBLEPOST]
    Code:
    private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
            {
                if (info.Initiator.name.Contains("helicopter")) return;
                if (ongoing) return; //Free for all
                if (entity is BasePlayer) return; // Player can be hurt.
                //if (entity is BaseNPC) return;
              
                if (!(entity is BasePlayer)) {
                    string name = entity.name.ToString();
                    if (name.Contains("loot")) return; //We want loot barrels to be breakable during day
                    if (name.Contains("box")) return;
                    if (name.Contains("animals")) return; // We want animals can be hurt.
                    if (name.Contains("helicopter")) return; // We want helicopter can be hurt.                var block = entity as BuildingBlock;
                    if (block) {
                        if (!protectTwigs && block.grade.ToString() == "Twigs") return;
                        if (!protectWood && block.grade.ToString() == "Wood") return;
                        if (!protectStone && block.grade.ToString() == "Stone") return;
                        if (!protectMetal && block.grade.ToString() == "Metal") return;
                        if (!protectTopTier && block.grade.ToString() == "TopTier") return;
                    }
                }
                info.damageTypes = new DamageTypeList(); //Otherwise set all damages to 0
            }
     
    Last edited by a moderator: Dec 4, 2016
  4. Wulf

    Wulf Community Admin

    You'll need to add some null checking in there to see what is null.
     
  5. Wulf... How to do it? add null checking. For example? Thank you :)
    [DOUBLEPOST=1480934974][/DOUBLEPOST]When the helicopter launch rocket, server report error. What can i do?~
     
  6. would help alot if you would post the full error - nobody arround, even @Wulf doesnt have witchcraft ball to see the future or your problem :)
     
  7. Code:
    [Oxide] 17:57 [Error] Failed to call hook 'OnEntityTakeDamage' on plugin 'TimeToPVP v0.1.8' (NullReferenceException: Object reference not set to an instance of an object)
    [Oxide] 17:57 [Debug]   at Oxide.Plugins.TimeToPVP.OnEntityTakeDamage (.BaseCombatEntity entity, .HitInfo info) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.TimeToPVP.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
    When the helicopter launch rocket :)
     
  8. Wulf

    Wulf Community Admin

    Add more null checks and print the output if necessary to test what is null when that happens.
     
  9. Code:
    if (info.WeaponPrefab != null)
                    {
                        if (info.WeaponPrefab.name.Contains("heli")) return;
                    }
    This will be okay, Thank you guys :)