So I've been working on this plugin for quite some time. The plugin is supposed to give people Ranks based on the hours they have on a server. Required dependencies would PlayTime and BetterChat. Inside the plugin, when people reach a playtime over 50 hours, they get the rank [Casual] and it sends them the permissions, 100 hours would be [Regular] and 20 hours would be [Noob]. Through betterchat, they would have to create 3 groups, called Noob, Casual, and Regular. Then edit the configs to make the permissions color_noob, etc. However it seems like it's not receiving the data value and hoursPlayed isn't working.
Code:PLUGIN.Name = "PlayerTitles" PLUGIN.Title = "PlayerTitles" PLUGIN.Version = V(1, 0, 0) PLUGIN.Description = "Titles that players receive based on the number of hours they have" PLUGIN.Author = "Ankawi" PLUGIN.ResourceID = 715function PLUGIN:Init() plugin = plugins.Find("PlayTime"):Call("hoursPlayed", player) plugin = plugins.Find("BetterChat") self:LoadDataFiles() permissions = {"noob", "casual", "regular"} for _, current in pairs(permissions) do if not permission.PermissionExists("color_" .. current) then permission.RegisterPermission("color_" .. current, self.Object) end end timer.Repeat(60, 0, function() self:UpdateTitles() end) endfunction PLUGIN:LoadDefaultConfig() self.Config.Messages = {} self.Config.Messages.RegularRank = self.Config.Messages.RegularRank or "You have been ranked up to [Regular]" self.Config.Messages.CasualRank = self.Config.Messages.CasualRank or "You have been ranked up to [Casual]" self.Config.Messages.NoobRank = self.Config.Messages.NoobRank or "You have been ranked up to [Noob]" self:SaveConfig() endfunction FindPlayer(searchedName, player) local players = global.BasePlayer.activePlayerList:GetEnumerator() local matchingPlayers = {} while players:MoveNext() do if string.match(string.lower(players.Current), string.lower(searchedName)) then table.insert(matchingPlayers, players.Current) end end if matchingPlayers.Length == 1 then return matchingPlayers[0] elseif matchingPlayers.Length > 1 then rust.SendChatMessage(player, "Multiple matching players have been found:") for _, name in pairs(matchingPlayers) do rust.SendChatMessage(player, name) end return nil elseif matchingPlayers == 0 then rust.SendChatMessage(player, "No matching player has been found") return nil end endfunction PLUGIN:UpdateTitles() if hoursPlayed > 20 then rust.SendChatMessage(player,rust.SendChatMessage.NoobRank) permission.GrantUserPermission(userid, "color_noob") elseif hoursPlayed > 50 then rust.SendChatMessage(player,rust.SendChatMessage.CasualRank) permission.GrantUserPermission(userid, "color_casual") elseif hoursPlayed > 100 then rust.SendChatMessage(player,rust.SendChatMessage.RegularRank) permission.GrantUserPermission(userid, "color_regular") end endfunction PLUGIN:LoadDataFiles() dataTable = datafile.GetDataTable("PlayTime") or {} endfunction PLUGIN:SaveDataFiles() datafile.SaveDataTable("PlayTime") end
In need of help with my plugin
Discussion in 'Rust Development' started by Ankawi, Nov 1, 2015.
-
Wulf Community Admin
Firstly, don't set variables without global, else use "self." prefixing. If you don't do one of these, the variables will likely bleed over into other plugins if they try to use the same thing, and ultimately could break critical variables.
Secondly, do not use PLUGIN.Name, it's redundant and is set automatically by Oxide based on your PLUGIN.Title.
Thirdly, you are trying to set multiple plugin references to the same variable (plugins, global bad). This basically makes the first time you set it pointless, and will likely give you errors if you try to use it later with a call that doesn't exist.
Lastly, if you take a look in your oxide/logs or console, you'll probably see some error spam from trying to call variables that don't exist.
Some reading material:
-
[DOUBLEPOST=1446421091][/DOUBLEPOST]Now what I need to do is implement a way so that my plugin can read the data of the plugin PlayTime and to apply the permission.Code:
PLUGIN.Title = "PlayerTitles" PLUGIN.Version = V(1, 0, 0) PLUGIN.Description = "Titles that players receive based on the number of hours they have" PLUGIN.Author = "Ankawi"function PLUGIN:Init() self.PlayTime = plugins.Find("PlayTime") self.BetterChat = plugins.Find("BetterChat") self:LoadDataFiles() self:UpdateTitles() self.updateTimer = timer.Repeat(60, 0, function() self:UpdateTitles() end) endfunction PLUGIN:Unloaded() self.updateTimer.Destroy() endfunction PLUGIN:LoadDefaultConfig() self.Config = self.Config or {} self.Config.Noob = self.Config.Noob or {} self.Config.Noob.Permission = self.Config.Noob.Permission or "color_noob" self.Config.Noob.Playtime = self.Config.Noob.Playtime or 20 self.Config.Casual = self.Config.Casual or {} self.Config.Casual.Permission = self.Config.Casual.Permission or "color_casual" self.Config.Casual.Playtime = self.Config.Casual.Playtime or 40 self.Config.Advanced = self.Config.Advanced or {} self.Config.Advanced.Permission = self.Config.Advanced.Permission or "color_advanced" self.Config.Advanced.Playtime = self.Config.Advanced.Playtime or 60 self:SaveConfig() endfunction FindPlayer(searchedName, player) local players = global.BasePlayer.activePlayerList:GetEnumerator() local matchingPlayers = {} while players:MoveNext() do if string.match(string.lower(players.Current), string.lower(searchedName)) then table.insert(matchingPlayers, players.Current) end end if matchingPlayers.Length == 1 then return matchingPlayers[0] elseif matchingPlayers.Length > 1 then rust.SendChatMessage(player, "Multiple matching players have been found:") for _, name in pairs(matchingPlayers) do rust.SendChatMessage(player, name) end return nil elseif matchingPlayers == 0 then rust.SendChatMessage(player, "No matching player has been found") return nil end endfunction PLUGIN:UpdateTitles() for test, group in pairs(self.Config) do rust.BroadcastChat(tostring(test) .. " | " .. group.Permission .. " : " .. group.Playtime) end endfunction PLUGIN:LoadDataFiles() self.dataTable = datafile.GetDataTable("PlayTime") or {} endfunction PLUGIN:SaveDataFiles() datafile.SaveDataTable("PlayTime") end
[DOUBLEPOST=1446428081,1446420539][/DOUBLEPOST]@Wulf what type of code would I need to use in order to grab the data from Playtime and implement into my plugin so when players have a playtime of over 20m they get [Noob] or well the permission color_noob.
[DOUBLEPOST=1446533845][/DOUBLEPOST]I've been trying to try and get the data from the plugin PlayTime in order to implement it into my plugin, but I'm not sure what the code is for lua. I've tried declaring the variable, but it keeps saying Playtime as a nil value.
Code:PLUGIN.Title = "PlayerTitles" PLUGIN.Version = V(1, 0, 0) PLUGIN.Description = "Titles that players receive based on the number of hours they have" PLUGIN.Author = "Ankawi"function PLUGIN:Init() self.PlayTime = plugins.Find("PlayTime") self.BetterChat = plugins.Find("BetterChat") self:LoadDataFiles() self:UpdateTitles() self.updateTimer = timer.Repeat(60, 0, function() self:UpdateTitles() end) endfunction PLUGIN:Unloaded() self.updateTimer.Destroy() endfunction PLUGIN:LoadDefaultConfig() self.Config = self.Config or {} self.Config.Noob = self.Config.Noob or {} self.Config.Noob.Permission = self.Config.Noob.Permission or "color_noob" self.Config.Noob.Playtime = self.Config.Noob.Playtime or 20 self.Config.Casual = self.Config.Casual or {} self.Config.Casual.Permission = self.Config.Casual.Permission or "color_casual" self.Config.Casual.Playtime = self.Config.Casual.Playtime or 40 self.Config.Regular = self.Config.Regular or {} self.Config.Regular.Permission = self.Config.Regular.Permission or "color_regular" self.Config.Regular.Playtime = self.Config.Regular.Playtime or 60 self.Config.Pro = self.Config.Pro or {} self.Config.Pro.Permission = self.Config.Pro.Permission or "color_pro" self.Config.Pro.Playtime = self.Config.Pro.Playtime or 100 self.Config.Messages = self.Config.Messages or {} self.Config.Messages.NoobRankUp = self.Config.Messages.NoobRankUp or "You ranked up to [Noob]" self.Config.Messages.CasualRankUp = self.Config.Messages.CasualRankUp or "You ranked up to [Casual]" self.Config.Messages.RegularRankUp = self.Config.Messages.RegularRankUp or "You ranked up to [Regular]" self.Config.Messages.ProRankUp = self.Config.Messages.ProRankUp or "You have been ranked up to [Pro]" self:SaveConfig() endfunction FindPlayer(searchedName, player) local players = global.BasePlayer.activePlayerList:GetEnumerator() local matchingPlayers = {} while players:MoveNext() do if string.match(string.lower(players.Current), string.lower(searchedName)) then table.insert(matchingPlayers, players.Current) end end if matchingPlayers.Length == 1 then return matchingPlayers[0] elseif matchingPlayers.Length > 1 then rust.SendChatMessage(player, "Multiple matching players have been found:") for _, name in pairs(matchingPlayers) do rust.SendChatMessage(player, name) end return nil elseif matchingPlayers == 0 then rust.SendChatMessage(player, "No matching player has been found") return nil end endfunction PLUGIN:UpdateTitles() for test, group in pairs(self.Config) do rust.BroadcastChat(tostring(test) .. " | " .. group.Permission .. " : " .. group.Playtime) end if hoursPlayed >= 20 then GrantUserPermission(userid, "color_noob") elseif hoursPlayed >= 40 then GrantUserPermission(userid, "color_casual") elseif hoursPlayed >= 60 then GrantUserPermission(userid, "color_regular") elseif hoursPlayed >= 100 then GrantUserPermission(userid, "color_pro") return end endfunction PLUGIN:LoadDataFiles() self.dataTable = datafile.GetDataTable("PlayerTitles") endfunction PLUGIN:SaveDataFiles() datafile.SaveDataTable("PlayerTitles") end -
Wulf Community Admin
As I mentioned to you on Steam, you can't really call a random variable, only hooks. Since the PlayTime plugin doesn't actually return anything in any of its hooks for you to use, there's no way to get what you want from it directly. The only way you can get the data would be to read the .json file for it directly (not recommended), or request some "API" methods be added to return the data you'd like.
