1. Getting a InvalidCastException when any CanBuild hook in any plugin is called. For instance:

    Code:
    Failed to call hook 'CanBuild' on plugin 'BuildingBlocker v1.0.0' (InvalidCastException: Value is not a convertible object: UnityEngine.Vector3 to Construction+Target)
    at System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) [0x00000] in <filename unknown>:0
    at System.Convert.ChangeType (System.Object value, System.Type conversionType) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.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 hook, System.Object[] args) [0x00000] in <filename unknown>:0
    
    [DOUBLEPOST=1513897010][/DOUBLEPOST]Just a note to any other plugin authors, you can just omit the final argument and the hook works fine.
     
  2. Wulf

    Wulf Community Admin

    Which signature are you implementing in your plugin?
     
  3. object CanBuild(Planner planner, Construction prefab, Vector3 position) as per the documentation
    [DOUBLEPOST=1513897316][/DOUBLEPOST]Ahh, I see the hook changes in the opj. I should've checked that as well.
     
  4. Is anyone else still getting this issue? I still get the exception with CanBuild(Planner, Construction, Construction.Target) or object CanBuild(Planner, Construction, Vector3), but not CanBuild(Planner, Construction)
     
  5. Wulf

    Wulf Community Admin

    It's likely a bug with the hook overloading for these particular types.
     
  6. You need currently a workaround:

    Code:
    object CanBuild(Planner plan, Construction prefab, object obj)
    {
        if (obj is Construction.Target)
        {
            var target = (Construction.Target)obj;
            // ....
           
        }
        else
        {
            var position = (Vector3)obj;
            // ...
        }
        return null; // or anything else needed
    }
     
  7. This works great, thanks. I was just ignoring the third argument and using the Planner to get the position.