Im having issues using the DataTables.
1. The values somehow get saved, but they don't show up in the file.
2. I cant clear those.
Propably just totally failing.
I would post my code in PM. But i don't want to do that here right now.
Solved Data tables problem (LUA)
Discussion in 'Rust Development' started by LaserHydra, May 26, 2015.
-
Wulf Community Admin
self:SaveDataFile()
-
Code:
datafile.SaveDataTable("pluginname")
-
Wulf Community Admin
-
is exactly whats is in "self:SaveDataFile()"
Also as I said I could write you the code -
Wulf Community Admin
-
-
Wulf Community Admin
-
Yes Im doing that too... -
Wulf Community Admin
The more review done now, the less issues you run into later. -
Well yeah, just gonna post it here.
Here it goes:
Code:PLUGIN.Title = "Admin Reports" PLUGIN.Description = "Gives players the opportunity to send reports to admins" PLUGIN.Author = "LaserHydra" PLUGIN.Version = V(1,0,0) PLUGIN.ResourceId = "?"function PLUGIN:Init() command.AddChatCommand("report", self.Object, "cmdReport") endfunction PLUGIN:LoadDataFiles() reports = datafile.GetDataTable("adminreports") or {} endfunction PLUGIN:cmdReport(player, cmd, args) reports = datafile.GetDataTable("adminreports") or {} local allArgs = "" local arg = args:GetEnumerator() local userId = rust.UserIDFromPlayer(player) while arg:MoveNext() do allArgs = allArgs .. " " .. arg.Current end if args.Length == 0 then rust.SendChatMessage(player, "<color=aqua>Admin Reports:</color>") rust.SendChatMessage(player, "/report message") if player.net.connection.authLevel >= 1 then rust.SendChatMessage(player, "/report list") end elseif args.Length > 0 then if args.Length == 1 and player.net.connection.authLevel >= 1 and args[0] == "list" then if #reports == 0 then rust.SendChatMessage(player, "<color=cyan>Reports</color><color=white>", "</color>There currently are no reports!") return false end if #reports >= 1 then rust.SendChatMessage(player, "<color=cyan>Reports</color><color=white>", "</color>Following reports has been made:") for report, data in pairs(reports) do rust.SendChatMessage(player, "<color=cyan>-----------------------------------</color>") rust.SendChatMessage(player, "<color=cyan>Player</color><color=white>", "</color>" .. data.player) rust.SendChatMessage(player, "<color=cyan>SteamID</color><color=white>", "</color>" .. data.steamId) rust.SendChatMessage(player, "<color=cyan>Message</color><color=white>", "</color>" .. data.message) rust.SendChatMessage(player, "<color=cyan>-----------------------------------</color>") end end return false end if args.Length == 1 and player.net.connection.authLevel >= 1 and args[0] == "clear" then reports = {} datafile.SaveDataTable("adminreports") rust.SendChatMessage(player, "<color=cyan>Reports</color><color=white>", "</color>List of Reports successfully cleared.") return false end local report = {} report.player = player.displayName report.steamId = rust.UserIDFromPlayer(player) report.message = allArgs table.insert(reports, report) datafile.SaveDataTable("adminreports") rust.SendChatMessage(player, "<color=cyan>Reports</color><color=white>", "</color>You have sent following report:") rust.SendChatMessage(player, "<color=cyan>-----------------------------------</color>") rust.SendChatMessage(player, "<color=cyan>Player</color><color=white>", "</color>" .. report.player) rust.SendChatMessage(player, "<color=cyan>SteamID</color><color=white>", "</color>" .. report.steamId) rust.SendChatMessage(player, "<color=cyan>Message</color><color=white>", "</color>" .. report.message) rust.SendChatMessage(player, "<color=cyan>-----------------------------------</color>") end end
-
Remove the GetDataTable in cmdReport
-
[DOUBLEPOST=1432665086][/DOUBLEPOST]Wow now it works... um thanks
[DOUBLEPOST=1432665158][/DOUBLEPOST]Now still the file seems to be empty though...
[DOUBLEPOST=1432668522][/DOUBLEPOST]@Hatemail @Wulf thanks
http://oxidemod.org/plugins/admin-reports-reporting-system.1065/Last edited by a moderator: May 26, 2015