Hey, everybody has to start somewhere and I'm making a simple plugin.
Can someone show me how to make a config file, where the player can change the respawn message?Code:namespace Oxide.Plugins { [Info("RespawnMessages", "Kappasaurus", 0.1)] [Description("Make customized notes players view on respawn!")] class RespawnMessages : RustPlugin { void OnPlayerRespawned(BasePlayer player) { SendPlayer("Hey! Try not to die this time!"); } } }
[DOUBLEPOST=1467693581][/DOUBLEPOST]Error: SendPlayer, does not exist in the current context.
Solved Making a config with changeable message?
Discussion in 'Rust Development' started by Kappasaurus, Jul 5, 2016.
-
Ok, so I guess I need to get the player, because put shows in console.
[DOUBLEPOST=1467694842][/DOUBLEPOST]Update:
So how do I change the puts to SendPlayer without getting errors?Code:namespace Oxide.Plugins { [Info("RespawnMessages", "Kappasaurus", 0.1)] [Description("Make customized notes players view on respawn!")] class RespawnMessages : RustPlugin { void OnPlayerRespawn(BasePlayer player) { Puts("Test!"); } } }
Sorry for being such a noob
-
Instead of SendPlayer use SendReply. Examples:
So for that it would be:Code:SendReply(player, string message);
[DOUBLEPOST=1467695693][/DOUBLEPOST]Now if you wanted it so they could change it whenever they wanted(per player) you would have to use some sort of data system.Code:SendReply(player, "Hey! Try not to die this time!");
-
Thanks man
, but how would I create a config file the
owner/admin can edit, that is created in oxide config folder? -
If you wanted a config file:
Now if you wanted to add more to that just do another Config[""] and then delete the current config and reload the plugin.Code:void LoadDefaultConfig() { Config.Clear(); Config["DeathMessage"] = "This is a test!"; Config.Save(); }
Config["This is where the name of the config goes"] = "This is what that config equals"
If you wanted to pull that data try something like:
[DOUBLEPOST=1467696293][/DOUBLEPOST]Now if its a integer or a float(vector, etc) you can try various methods to retrieve it:Code:[ConsoleCommand("test")] void test() { Puts(Config["DefGroupName"].ToString()); } { Config.Clear(); Config["DefGroupName"] = _defGroupName; Config.Save(); }
Code:Convert.ToInt32(Config[""]); which would convert a something to a int. Convert.ToInt64(Config[""]); which would convert something to a float.
Last edited by a moderator: Jul 5, 2016 -
Ok so say I changed the DeathMessage name to RespawnMessage, I would doIs that correct? So when it is changed the message would rely on it?Code:
SendReply(player, "RespawnMessage")
-
SendReply(player, Config["RespawnMessage"].ToString());
-
Code:
namespace Oxide.Plugins { [Info("RespawnMessages", "Kappasaurus", 0.1)] [Description("Make customized notes players view on respawn!")] class RespawnMessages : RustPlugin { void LoadDefaultConfig() { Config.Clear(); Config["RespawnMessage"] = "Hey, try not to die this time!"; Config.Save(); } void OnPlayerRespawn(BasePlayer player) { SendReply(player, Config["RespawnMessage"].ToString()); } } } -
Yes. That should work!
-
Thanks man
I'm going to try to upload this, my first
plugin... I will site you, maybe I will be able to make something really cool in the future -
Cool. Make sure everything works in game of course! Also don't forget to check out other plugins as they contain a lot of information such as hooks and methods you might need.
-
Yep, works perfectly, even the config, I will put you as an author.
[DOUBLEPOST=1467697187][/DOUBLEPOST]Getting errors, unexpected symbols, 19, 32
[DOUBLEPOST=1467697702][/DOUBLEPOST]Code:[Command("rmessage")] void TestCommand(IPlayer player, string command, string[] args) { SendReply(player, "<size=20>Respawn Messages v0.1</size><size=16>by <size=18>Kappasaurus</size><size=16> & </size> <size=18>"); }Last edited by a moderator: Jul 5, 2016 -
When I try to reload it I get it saying I need a semi-colon at the end of the else, however even when I add it I still get the same error, does anyone know what is wrong with my if/else prefix statement.Code:
using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("RespawnMessages", "Kappasaurus", 0.2)] [Description("Make customized notes players view on respawn!")] class RespawnMessages : RustPlugin { [PluginReference] Plugin PopupNotifications; void LoadDefaultConfig() { Config.Clear(); Config["RespawnMessagePopup"] = "<size=20>Hey, <color=#cd422b>try not to die</color> this time!</size>"; Config["RespawnMessageChat"] = "Hey, <color=#cd422b>try not to die</color> this time!"; Config["Prefix"] = "<color=#cd422b>[</color> Server <color=#cd422b>]</color>"; Config["PopupEnabled"] = false; Config["ChatEnabled"] = true; Config["PrefixEnabled"] = true; Config.Save(); } void OnPlayerRespawn(BasePlayer player) { if ((bool)Config["PrefixEnabled"] == true) { SendReply(player, "The prefic works (I haven't expanded fully on this system, I just need to make sure it works in the first place... I will include popup API and chat messages for the prefix option.)") } else; if ((bool)Config["PopupEnabled"] == true) { PopupNotifications?.Call("CreatePopupNotification", Config["RespawnMessagePopup"].ToString()); } if ((bool)Config["ChatEnabled"] == true) { SendReply(player, Config["RespawnMessageChat"].ToString()); } } [ChatCommand("rm")] void TestCommand(BasePlayer player, string command, string[] args) { SendReply(player, "<size=22><color=#cd422b>Respawn Messages v0.1</color></size>"); SendReply(player, "<size=12>Created by </size><size=14>Kappasaurus</size><size=12> with the help of </size><size=14>DylanSMR</size>"); } } } -
Wulf Community Admin
I'd store i
Just the missing ; is all I see so far on the line above that. The else should not have an ;. -
Seems to do the trick.
[DOUBLEPOST=1467753628][/DOUBLEPOST]Just an OCD thing, why is my config genning like this
when my code isCode:{ "ChatEnabled": true, "PopupEnabled": false, "Prefix": "<color=#cd422b>[</color> Server <color=#cd422b>]</color>", "PrefixEnabled": true, "RespawnMessageChat": "Hey, <color=#cd422b>try not to die</color> this time!", "RespawnMessagePopup": "<size=20>Hey, <color=#cd422b>try not to die</color> this time!</size>" }
Code:{ Config.Clear(); Config["RespawnMessagePopup"] = "<size=20>Hey, <color=#cd422b>try not to die</color> this time!</size>"; Config["RespawnMessageChat"] = "Hey, <color=#cd422b>try not to die</color> this time!"; Config["Prefix"] = "<color=#cd422b>[</color> Server <color=#cd422b>]</color>"; Config["PopupEnabled"] = false; Config["ChatEnabled"] = true; Config["PrefixEnabled"] = true; Config.Save(); } -
Wulf Community Admin
It's A-Z. -
Nevermind, had to put the else action in brackets.
-
Would there be anothrr way to organize it? A-Z is good but I would like to make sections.
-
Wulf Community Admin
You can make sections as much as you'd like.
