So i'm just having a small problem where this bit of code wont compile correctly.
AntiChatFlood.cs - Pastebin.com
Any help would be awesome, thanks.
[DOUBLEPOST=1456188598][/DOUBLEPOST]Error Code: "[Error] AntiChatFlood.cs(73,4): error CS1002 ; expected
Need help with an error in my plugin
Discussion in 'Rust Development' started by DylanSMR, Feb 23, 2016.
-
Wulf Community Admin
You're missing brackets in one if statement that has two lines. Visual Studio should tell you this if you use it.
-
Right so I fixed all of that, got my plugin working. But with the "OnPlayerChat hook" I am getting a little error when I type in-game.
ScreenshotCode:void OnPlayerChat(ConsoleSystem.Arg arg, BasePlayer player) { var info = new PlayerInfo(player); if (storedData.Players.Contains(info)) { SendReply(player, "You must wait to send another message."); return; } if(!storedData.Players.Contains(info)) { storedData.Players.Add(info); Interface.Oxide.DataFileSystem.WriteObject("MyDataFile", storedData); timer.Repeat(TimeBetweenMessage, 0, () => { storedData.Players.Remove(info); }); } } -
Wulf Community Admin
You're using an invalid argument for the hook, the only valid one is the first one.
-
Wait so how would it be able to call for player if player isn't a variable? AS "BasePlayer player" is what I use to define player.
-
Wulf Community Admin
You'd need to get the player from arg.connection.player I believe, and cast it as BasePlayer. -
Right thanks, I got it.
Code:BasePlayer player = (BasePlayer) arg.connection.player;
-
Right so ive done a bit of editing, no errors, and mostly good. But when it does add the player to the data(Which it does), when it tries to read if it is in the file, it say it is.
Just a bit new to data files(DO I do, storedData.Players.Remove(info)Code:void OnPlayerChat(ConsoleSystem.Arg arg) { BasePlayer player = (BasePlayer) arg.connection.player; var info = new PlayerInfo(player); if (storedData.Players.Contains(info)) { PrintToChat(player, "You are chatting to fast, try again soon"); return; } else { storedData.Players.Add(info); Interface.Oxide.DataFileSystem.WriteObject("AntiChatFlood", storedData); timer.Once(WaitTillMsg, () => { storedData.Players.Remove(info); }); } }
, or what would I do -
Wulf Community Admin
You can't store the full player, you'd need to store the name, steamid, etc. or whatever else you may want. -
Odd, I just used the one from the docs.oxidemod.org, then edited it to my needs.
And is the script(storedData.Players.Remove)? -
Wulf Community Admin
Mmm, pretty sure you can't store the entire player in a datafile, only variables/strings from it. You can store the player in a hashset or dictionary though. -
Heres the entire plugin of what I am working with.
Code:using System.Collections.Generic; using Oxide.Core;namespace Oxide.Plugins { [Info("AntiChatFlood", "DylanSMR", "1.0.0")] [Description("Data test stuff.")] class AntiChatFlood : RustPlugin { int WaitTillMsg = 5; class StoredData { public HashSet<PlayerInfo> Players = new HashSet<PlayerInfo>(); public StoredData() { } } class PlayerInfo { public string UserId; public string Name; public PlayerInfo() { } public PlayerInfo(BasePlayer player) { UserId = player.userID.ToString(); Name = player.displayName; } } StoredData storedData; void Loaded() { storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("AntiChatFlood"); } void OnPlayerChat(ConsoleSystem.Arg arg) { BasePlayer player = (BasePlayer) arg.connection.player; var info = new PlayerInfo(player); if (storedData.Players.Contains(info)) { PrintToChat(player, "You are chatting to fast, try again soon"); return; } else { storedData.Players.Add(info); Interface.Oxide.DataFileSystem.WriteObject("AntiChatFlood", storedData); timer.Once(WaitTillMsg, () => { storedData.Players.Remove(info); }); } } } } -
You don't really need to store any data unless you are planning on having the information carry over through restarts, you could just as easily use a list
Code:using System.Collections.Generic; using Oxide.Core;namespace Oxide.Plugins { [Info("AntiChatFlood", "DylanSMR", "1.0.0")] [Description("Data test stuff.")] class AntiChatFlood : RustPlugin { int WaitTillMsg = 5; List<ulong> playerWait = new List<ulong>(); // We are going to store the users ID, there isnt much point in taking more data than we need for this plugin void OnPlayerChat(ConsoleSystem.Arg arg) { BasePlayer player = (BasePlayer)arg.connection.player; if (playerWait.Contains(player.userID)) { PrintToChat(player, "You are chatting to fast, try again soon"); return; } else { playerWait.Add(player.userID); timer.Once(WaitTillMsg, () => { playerWait.Remove(player.userID); }); } } } } -
I plan on adding a warning point sytem, so I decided it would be easier to add both to a data file instead.
-
Ok, either way you would still be better off saving the above to memory instead of data, otherwise the plugin will have to read and write a physical file every 5 seconds. You could then use a datafile to save data purely related to the warning system
-
How would I go about saving it to memory(Sorry, just a bit to new to rust data/memory and such)
-
The way I showed you, as long as the plugin is loaded the list is in memory. If you want some help understanding data and how to better manage it to suit what you are doing you can add me on steam. Ill be home later tonight
-
Right, I used a list and got it working, Thanks
. When you get home though I will need to ask about how to store numbers in data files. Then request
that number a bit later on.
