I'm trying to put different ranks of players to broadcast at the first line of them connecting. However i also tried putting the website: example.com text below it and it will only work if put on another plugin. The reason I cant put it all in one function is i have to return/exit the function so im either forced to put the website text in at top or in another plugin if i want it below the connection text or leave it at top of the onplayerinit. Is there a way to have multiple playerinit or a way so it will only return to a certain point rather than exit the entire function?
Multiple player inits(lua)
Discussion in 'Rust Development' started by JohnRU, Aug 22, 2015.
-
Wulf Community Admin
Please paste the code for what you are trying to do. It should be perfectly fine in a single plugin and function.
-
Basically i want the bottom aspect of giving the website out or the member text but won't work due to the return and only will work if used in another plugin. I hope i make sense.Code:
function PLUGIN:OnPlayerInit(player, cmd, args) played = played + "1" local steamId = rust.UserIDFromPlayer(player) if permission.UserHasPermission(steamId, "owner") then local owner = "<color=" .. self.Config.OwnerColor .. ">" .. "[Owner]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.OwnerColor .. ">" .. " has connected." .. "</color>" rust.BroadcastChat(owner, nil, rust.UserIDFromPlayer(player)) print(player.displayName .. " has connected.") return end if permission.UserHasPermission(steamId, "admin") then local owner = "<color=" .. self.Config.adminColor .. ">" .. "[Admin]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.adminColor .. ">" .. " has connected." .. "</color>" rust.BroadcastChat(owner, nil, rust.UserIDFromPlayer(player)) print(player.displayName .. " has connected.") return end if permission.UserHasPermission(steamId, "mod") then local owner = "<color=" .. self.Config.modColor .. ">" .. "[Mod]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.modColor .. ">" .. " has connected." .. "</color>" rust.BroadcastChat(owner, nil, rust.UserIDFromPlayer(player)) print(player.displayName .. " has connected.") return end if permission.UserHasPermission(steamId, "trialmod") then local owner = "<color=" .. self.Config.trialColor .. ">" .. "[Trial Mod]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.trialColor .. ">" .. " has connected." .. "</color>" rust.BroadcastChat(owner, nil, rust.UserIDFromPlayer(player)) print(player.displayName .. " has connected.") return end if permission.UserHasPermission(steamId, "membertag") then local owner = "<color=" .. self.Config.memberColor .. ">" .. "[Member]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.memberColor .. ">" .. " has connected." .. "</color>" rust.BroadcastChat(owner, nil, rust.UserIDFromPlayer(player)) print(player.displayName .. " has connected.") return end if permission.UserHasPermission(steamId, "user") then local owner = "<color=" .. self.Config.userColor .. ">" .. "[User]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.userColor .. ">" .. " has connected." .. "</color>" rust.BroadcastChat(owner, nil, rust.UserIDFromPlayer(player)) print(player.displayName .. " has connected.") return end if self.Config.SeekMembers == "false" then return end if permission.UserHasPermission(steamId, "member") then rust.SendChatMessage(player, "<color=#1DCC8F>Website:</color> " .. self.Config.Site, nil, self.Config.Icon) else rust.SendChatMessage(player, "<color=#1DCC8F>Become a Member @</color> " .. self.Config.Site, nil, self.Config.Icon) end end -
Wulf Community Admin
Here's a version that does what you want. The returns are not needed. Also, I'm not sure what your whole "played" thing is, but if you want to use that to store who has joined or played before, you'd need to store it by steamId. You could also do away with more of the code duplication by making the message dynamic based on the permissions.
Code:function PLUGIN:OnPlayerInit(player, cmd, args) local steamId = rust.UserIDFromPlayer(player) local message if permission.UserHasPermission(steamId, "owner") then message = "<color=" .. self.Config.OwnerColor .. ">" .. "[Owner]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.OwnerColor .. ">" .. " has connected." .. "</color>" elseif permission.UserHasPermission(steamId, "admin") then message = "<color=" .. self.Config.AdminColor .. ">" .. "[Admin]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.AdminColor .. ">" .. " has connected." .. "</color>" elseif permission.UserHasPermission(steamId, "mod") then message = "<color=" .. self.Config.ModColor .. ">" .. "[Mod]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.ModColor .. ">" .. " has connected." .. "</color>" elseif permission.UserHasPermission(steamId, "trialmod") then message = "<color=" .. self.Config.TrialColor .. ">" .. "[Trial Mod]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.TrialColor .. ">" .. " has connected." .. "</color>" elseif permission.UserHasPermission(steamId, "membertag") then message = "<color=" .. self.Config.MemberColor .. ">" .. "[Member]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.MemberColor .. ">" .. " has connected." .. "</color>" elseif permission.UserHasPermission(steamId, "user") then message = "<color=" .. self.Config.UserColor .. ">" .. "[User]" .. "</color> " .. "<color=" .. self.Config.DNameColor .. ">" .. player.displayName .. "</color>" .. "<color=" .. self.Config.UserColor .. ">" .. " has connected." .. "</color>" end if message then rust.BroadcastChat(message, nil, steamId) print(player.displayName .. " has connected.") end if self.Config.SeekMembers == "true" then if permission.UserHasPermission(steamId, "member") then rust.SendChatMessage(player, "<color=#1DCC8F>Website:</color> " .. self.Config.Site, nil, self.Config.Icon) else rust.SendChatMessage(player, "<color=#1DCC8F>Become a Member @</color> " .. self.Config.Site, nil, self.Config.Icon) end end end
