Hi,
In one case i would need to kill a player by script, and i thought this was an easy task. Here is what i have:
disconnecting: Exception: NullReferenceException: Object reference not set to an instance of an objectCode:[ConsoleCommand("RB.Kill")] void RBKill(ConsoleSystem.Arg arg) { if (arg.connection == null) { var args = arg.HasArgs() ? arg.Args : null; if (args != null && args.Length == 1) { ulong _userId; ulong.TryParse(args[0], out _userId); if (Players.ContainsKey(_userId)) { var player = BasePlayer.activePlayerList.FirstOrDefault(x => x.userID == _userId); if (player != null) { player.Kill(BaseNetworkable.DestroyMode) } } } } }
The player isnt null and the only variable to pass a long the Kill method is a BaseNetworkable.DestroyMode, and it doesnt seem to make a difference what one of the two enumerator options i use.
What am i missing out?
[DOUBLEPOST=1459931178][/DOUBLEPOST]Oh, and why i have arg.connection == null is because this never will be used in console ingame.
[DOUBLEPOST=1459931575][/DOUBLEPOST]player.ChangeHealth(-101); solved it.
Solved BasePlayer.Kill() throws NullReferenceException
Discussion in 'Rust Development' started by Murky, Apr 6, 2016.
-
Calytic Community Admin Community Mod
You don't kill players like you would with entities.
player.Die(); -
I guess it was time for my coffey break. I knew this already from Unity.. Cheers
-
@Murky is your plugin now works as it should be? And is it possible to kill player by his steam-id with console command? If answer is yes, then please share it with me.
Thank you! -
Its merely a little fracture of a server utility that works only over RCON, but if you want to have a look at it here is the extracted part needed to kill a player based on id:
Code:using MurkysRustBoot; using Newtonsoft.Json; using System.Collections.Generic; using System.Linq;namespace Oxide.Plugins { [Info("Murkys Core", "Murky", 0.1)] [Description("Core plugin used in combination of RustBoot")] class MurkysCore : RustPlugin { Dictionary<ulong, BasePlayer> Players; void Init() { Players = new Dictionary<ulong, BasePlayer>(); foreach (var player in BasePlayer.activePlayerList) { Players.Add(player.userID, player); } RustBootConsoleMsg("RustBootPluginInit"); } [ConsoleCommand("server.kill")] void RustBootAdminKill(ConsoleSystem.Arg steamID) { // Only for RCON connections if (steamID.connection == null) { var args = steamID.HasArgs() ? steamID.Args : null; if (args != null && args.Length == 1) { ulong _userId; ulong.TryParse(args[0], out _userId); if (Players.ContainsKey(_userId)) { var player = Players.FirstOrDefault(x => x.Value.userID == _userId); if (player.Value != null) { player.Value.Die(); } } } } } void OnPlayerInit(BasePlayer player) { if (!Players.ContainsKey(player.userID)) { Players.Add(player.userID, player); } } void OnPlayerDisconnected(BasePlayer player, string reason) { if (Players.ContainsKey(player.userID)) { Players.Remove(player.userID); } } } }
Last edited by a moderator: Apr 7, 2016 -
-
The RCON connection is solely used by a application. I have tried to get input/output of RustDedicated.exe to read and send input directly but as of now i have not found a way to do this. I have read Unity documentation and googled for hours, so i gave in and chose a combination of parsing logs in realtime and using RCON for input. The plugin parses the input from the application.
I am referring to the ProcessStartInfo.RedirectStandardInput and RedirectStandardOutput and RedirectStandardError Properties in the .NET framework, which none of them seems to work with RustDedicated.exe.
If you know a way to redirect the output/input i would LOVE you, since the "unsolvable" task have given me some hard time and costed me alot of hours.Last edited by a moderator: Apr 8, 2016 -
ah that makes sense.