I'm getting this error with my stats plugin:
It appears to be related to:Code:(21:35:13) | at Oxide.Plugins.MStats.OnEntityBuilt (.Planner planner, UnityEngine.GameObject component) [0x00000] in <filename unknown>:0 at Oxide.Plugins.MStats.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 hook, System.Object[] args) [0x00000] in <filename unknown>:0
Can anyone guide me towards what the issue might be? Was the object's name changed or something?Code:void OnEntityBuilt(Planner planner, GameObject component) { Vector3 pos = planner.GetOwnerPlayer().GetEstimatedWorldPosition(); string name = component.ToBaseEntity().ShortPrefabName; if(component.ToBaseEntity() is BuildingBlock) { name = ((BuildingBlock)component.ToBaseEntity()).blockDefinition.info.name.english; } executeQuery("INSERT INTO player_place_building (player, building, pos_x, pos_y, pos_z, date) VALUES (@0,@1,@2,@3,@4,@5)", planner.GetOwnerPlayer().userID, name, pos.x, pos.y, pos.z, getDateTime()); }
Thanks in advance.
MStats error: (.Planner planner, UnityEngine.GameObject component)
Discussion in 'Rust Development' started by Tunnleram, Aug 5, 2017.
-
Wulf Community Admin
You are assuming that a BasePlayer (GetOwnerPlayer()) will always exist for one, which may not always be the case, so adding some null checking would be wise. ToBaseEntity() may also potentially be null as well, but you can test and see with some debugging and null checking.
-
The mod author abandoned this MStats mod so I just tweak it. Oh, and I don't know C, but I try
Would it be something like this for handling the first part? I'm not sure if I have the syntax right, but I get the general idea.
Code:void OnEntityBuilt(Planner planner, GameObject component) { if (!BasePlayer(GetOwnerPlayer()) == null) { Vector3 pos = planner.GetOwnerPlayer().GetEstimatedWorldPosition(); string name = component.ToBaseEntity().ShortPrefabName; } if(component.ToBaseEntity() is BuildingBlock) { name = ((BuildingBlock)component.ToBaseEntity()).blockDefinition.info.name.english; executeQuery("INSERT INTO player_place_building (player, building, pos_x, pos_y, pos_z, date) VALUES (@0,@1,@2,@3,@4,@5)", planner.GetOwnerPlayer().userID, name, pos.x, pos.y, pos.z, getDateTime()); } }
-
Wulf Community Admin
Code:void OnEntityBuilt(Planner planner, GameObject component) { var player = planner.GetOwnerPlayer(); var buildingBlock = component.ToBaseEntity() as BuildingBlock; if (player != null && buildingBlock != null) { var pos = player.GetEstimatedWorldPosition(); var name = buildingBlock.blockDefinition.info.name.english; executeQuery("INSERT INTO player_place_building (player, building, pos_x, pos_y, pos_z, date) VALUES (@0,@1,@2,@3,@4,@5)", player.userID, name, pos.x, pos.y, pos.z, getDateTime()); } }
-
Thank you very much. I will digest this.