I'm trying to call the BuildingBlock.UpgradeToGrade function with C#, but this method is private.
Private Methods & Fields | Oxide
I found this but it doesn't really help me. I have never working with these kind of things.
Is it even possible?
- Ino
Solved Access private method with C#
Discussion in 'Rust Development' started by Inofix, Sep 17, 2015.
-
UpgradeToGrade? this doesn't exist.
you have DoUpgradeToGrade(RPCMessage msg)
but you can't use this
if you want to set a grade just use:
BuildingBlock.SetGrade( BuildingGrade.Enum iGradeID ) -
My bad, had client assembly csharp opened.
But still how's it possible to call a privat method?
EDIT: I'm looking for a function to upgrade the wall and take the items away from the player without using the hammer. -
Code:
[MaxDistance(4f), RPC_Server] private void DoUpgradeToGrade(BaseEntity.RPCMessage msg) { BuildingGrade.Enum iGrade = (BuildingGrade.Enum) msg.read.Int32(); ConstructionGrade g = this.GetGrade(iGrade); object[] args = new object[] { this, msg, iGrade }; if (((((Interface.CallHook("IOnStructureUpgrade", args) == null) && (g != null)) && this.CanChangeToGrade(iGrade, msg.player)) && this.CanAffordUpgrade(iGrade, msg.player)) && (base.TimeSinceAttacked() >= 8f)) { this.PayForUpgrade(g, msg.player); this.SetGrade(iGrade); this.SetHealthToMax(); this.StartBeingRotatable(); base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); Effect.server.Run("assets/bundled/prefabs/fx/build/promote_" + iGrade.ToString().ToLower() + ".prefab", this, 0, Vector3.zero, Vector3.zero, null, false); } }
As for using private methods.
read this plugin: Oxide2Plugins/Build.cs at master · strykes/Oxide2Plugins · GitHub
private MethodInfo CreateEntity;
private MethodInfo FindPrefab; -
Thanks!
-
ok wrong example, forgot that i don't use t in this plugin
private MethodInfo inventoryClear = typeof(ItemContainer).GetMethod("Clear", BindingFlags.NonPublic | BindingFlags.Instance);
inventoryClear.Invoke(box.inventory, null);
so try something like
Code:MethodInfo DoUpgradeToGrade = typeof(BasePlayer).GetMethod("CanChangeToGrade", BindingFlags.NonPublic | BindingFlags.Instance); DoUpgradeToGrade.Invoke(Block, new object[] { BuildingGrade.Enum.TopTier, Player} );
[DOUBLEPOST=1442531795][/DOUBLEPOST]if you want a return just add var thereturn = DoUpgradeToGrade.Invoke(Block, new object[] { BuildingGrade.Enum.TopTier, Player} ); -
typeof(BasePlayer) was my mistake, didn't see i have defined BasePlayer right there, it needed to be BuildingBlock.
My question is solved, ty. -
lol sorry foro that ^^