I am trying to convert BasePlayer to ConsoleSystem.Arg.
I know I can do: BasePlayer player = (BasePlayer)arg.connection.player;
But I don't know how can I do the opposite.
Solved Converting BasePlayer to ConsoleSystem.Arg?
Discussion in 'Rust Development' started by Reynostrum, Jul 6, 2016.
-
Wulf Community Admin
It's a bit challenging to do the opposite I believe, and it might involve creating it all manually. Why do you need to convert it to Arg?
-
I am trying to call AlternadorTAB from OnLootEntity, but OnLootEntity is BasePlayer and AlternadorTAB, ConsoleSystem.ArgCode:
[ConsoleCommand("tabinfopanel")] void AlternadorTAB(ConsoleSystem.Arg arg) { if (arg != null && arg?.connection != null && arg?.connection?.player != null) { BasePlayer player = (BasePlayer)arg.connection.player; if (InventarioAbierto.Contains(player)) { InventarioAbierto.Remove(player); ChangePlayerSettings(player, "enable", "true"); RevealGUI(player); } else { InventarioAbierto.Add(player); ChangePlayerSettings(player, "enable", "false"); DestroyGUI(player); } } } void OnLootEntity(BasePlayer looter, BaseEntity target) { AlternadorTAB(looter); } -
Wulf Community Admin
Why not abstract the GUI stuff into another method and call it from the command and the loot hook instead? -
Sorry Wulf, I don't follow. Could you explain it again?
-
Wulf Community Admin
Put your code in something else that accepts BasePlayer, then call that from your command instead of putting it all in there. -
I did not think on that, I guess my brain needs to take a break

Thank you again Wulf.
