Getting player IP address from BasePlayer?Solved
Struggling to find how to get the player ip from when someone issues a chat command
i have tried to do
string playerAddress = player.net.connection.ipaddress.Split(':')[0];​

which i saw on a old post on oxidemod.org thread but appears to cause a NullReferenceException

Did u try just ipaddress without split first?
oh, looks like that does work.
I thought the .Split was meant to remove the everything after and including the :
Pixel1001
oh, looks like that does work.
I thought the .Split was meant to remove the everything after and including the :

That is what it is for.

welp after some googling i just did
string playerAddress = player.net.connection.ipaddress;
string IPAddress = playerAddress.Substring(0, playerAddress.LastIndexOf(":"));​

and it seems to work just fine

Pixel1001
welp after some googling i just did
string playerAddress = player.net.connection.ipaddress;
string IPAddress = playerAddress.Substring(0, playerAddress.LastIndexOf(":"));​

and it seems to work just fine

That's another way of doing the same thing. Keep in mind that the BasePlayer has to be online with a valid connection, otherwise you will get that NRE; that's the only way you'd get an NRE otherwise. There's no real difference between the code in the first versus what you are using now.

i mean, if its a chat command then isn't the BasePlayer online?
because as i switch between the 2 ways then the one with the .Split() just breaks it
What is the exact error you were seeing before?
i was getting
 Failed to call hook 'admin' on plugin 'Aquatic v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Core.Configuration.DynamicConfigFile.Get (System.String[] path) [0x00011] in <b0a93b504f034a0db8b1c3d2503c0987>:0 
  at Oxide.Core.Configuration.DynamicConfigFile.get_Item (System.String keyLevel1, System.String keyLevel2, System.String keyLevel3) [0x00000] in <b0a93b504f034a0db8b1c3d2503c0987>:0 
  at Oxide.Plugins.Aquatic.admin (BasePlayer player, System.String command) [0x00056] in <3eb13466be2b4c759597b4c5528381e0>:0 
  at Oxide.Plugins.Aquatic.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000ef] in <3eb13466be2b4c759597b4c5528381e0>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <33f7c42a56934dae8ec04b11017dce31>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <b0a93b504f034a0db8b1c3d2503c0987>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <b0a93b504f034a0db8b1c3d2503c0987>:0​

but now i cant even reproduce it which is making me so confused considering i only changed that

Pixel1001
i was getting
 Failed to call hook 'admin' on plugin 'Aquatic v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Core.Configuration.DynamicConfigFile.Get (System.String[] path) [0x00011] in <b0a93b504f034a0db8b1c3d2503c0987>:0 
  at Oxide.Core.Configuration.DynamicConfigFile.get_Item (System.String keyLevel1, System.String keyLevel2, System.String keyLevel3) [0x00000] in <b0a93b504f034a0db8b1c3d2503c0987>:0 
  at Oxide.Plugins.Aquatic.admin (BasePlayer player, System.String command) [0x00056] in <3eb13466be2b4c759597b4c5528381e0>:0 
  at Oxide.Plugins.Aquatic.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000ef] in <3eb13466be2b4c759597b4c5528381e0>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <33f7c42a56934dae8ec04b11017dce31>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <b0a93b504f034a0db8b1c3d2503c0987>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <b0a93b504f034a0db8b1c3d2503c0987>:0​

but now i cant even reproduce it which is making me so confused considering i only changed that

Yeah, that looks like an error with your config file or handling of it; not from the above code.
Locked automatically