I have started a very basic plugin that handle kits.
It needs a lot of improvement but I have to start somewhere.
This code is very simple.
when a player type in /kits I display the kits and add an item to the player inventory
I have commented the code. Im looking to retreive the player name and anounce it in chat when he connect.
I would also like to know how to set default player inventory (on spawn)
This is my plugin so far.
Can anyone help?Code:using Oxide.Core; using Oxide.Core.Plugins;namespace Oxide.Plugins { [Info("kits", "Madeindreams", 1.0)] [Description("Kits plugin")] class kits : RustPlugin { void Init() { Puts("Init works!"); } void Loaded() { Puts("Loaded works!"); }void OnPluginLoaded(Plugin name) { Puts($"Plugin '{name}' has been loaded"); }void OnPlayerConnected(Network.Message packet,BasePlayer player) { PrintWarning("user connecting"); // hOW CAN I ANNOUCE PLAYERS? // How do i set deafult inventory ? }[ChatCommand("kits")] private void kitsCmd(BasePlayer player, string command, string[] args) { //Magic goes here Puts("command works!"); string message = "<color=#0000ffff>Available Kits</color>\n Assault,..."; SendReply(player, message); // giving something to the player Item item = ItemManager.CreateByName("rifle.ak", 1); item.position = 1; // needs to be empty item.contents.itemList.Add(ItemManager.CreateByName("weapon.mod.silencer", 1)); // add mod to weapon player.inventory.GiveItem(item); } } }
Getting player info on connection?
Discussion in 'Rust Development' started by Madeindreams, Feb 3, 2018.
-
// hOW CAN I ANNOUCE PLAYERS?
Code:player.Chatmessage($"Hello {player.displayName}, here you are!");
if you mean clear it =>
Code:player.inventory.Strip()
player.inventory.GiveItem(ItemManager.CreateByItemID(108061910));
player.inventory.GiveItem(ItemManager.CreateByItemID(108061910));
player.inventory.GiveItem(ItemManager.CreateByItemID(108061910));Last edited by a moderator: Feb 3, 2018 -
the player.Chatmessage will be sent to the player alone I presume. How do I say it in general chat for every one to see.
And this chat command isnt working for me.
player.ChatMessage($"Hello '{player.displayName}', here you are!");
will trow an error
Code:Failed to call hook 'OnPlayerConnected' on plugin 'kits v1.0.0' (NullReferenceException: Object reference not set to an instance of an object) at Oxide.Plugins.kits.OnPlayerConnected (Network.Message packet, .BasePlayer player, System.String[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.kits.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.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
Now the other thing about clearing the inventory. This is not the behavior im expecting. A player could log in with stuff on him. I dont want to clear the enventory when a player connects but when he spawn. How can I do this on spawn^
Thak you very much for your repliy.Last edited by a moderator: Feb 3, 2018 -
I got the player connection message working by using onPlayerSleepEnded. For some reason it is not working OnPlayerConnected. Is there anything in between? can I annouce the player connection before he end sleep and after he connected?
-
For sending a message to everyone in game you can either use BroadcastChat or PrintToChat. more info on messages >here< -
Thank you very much guys. Its all working now im starting to get it.
So I have found the inbetween I was looking for.
Code:void OnPlayerInit(BasePlayer player) { //PrintToChat ($"{player.displayName} connected (PTC)"); rust.BroadcastChat(null, $"{player.displayName} connected (BC)"); Puts($"{player.displayName} connected (Puts)"); }
So there are 2 ways to print out in general chat.
Is there any advantage using BroadcastChat rather then PrintToChat?
Is Puts considered a console output? I can see these outputs in Rcon. My code is actualy live in Rcon and the server. Thats totaly awesome. No need to restart anything. -
Wulf Community Admin
-
Wulf how do I refer to the packet.playeName? in here lets say :
Code:void OnPlayerConnected(Network.Message packet) { Puts("OnPlayerConnected works!"); Puts("packet player name?"); }
-
Wulf Community Admin
-
Intellisence for CS is already installed. I not sure how to import or link librarys to my plugin.
Last edited by a moderator: Feb 3, 2018