Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Created June 3, 2018 03:22
Show Gist options
  • Save DustinAlandzes/3d1ea4a742e58bbb1682bb47823bab65 to your computer and use it in GitHub Desktop.
Save DustinAlandzes/3d1ea4a742e58bbb1682bb47823bab65 to your computer and use it in GitHub Desktop.
An OxideMod python plugin that writes text to the GUI, c+p from flamingmojo's blog: https://flamingmojo.wordpress.com/2016/07/17/making-a-gui-plugin-the-basics/
try:
import Rust, BasePlayer
import Oxide.Game.Rust.Cui as Cui
from System import Action
import UnityEngine.TextAnchor as TextAnchor
except ImportError, e:
print 'IMPORT ERROR',e
class AnnounceGUI:
def __init__(self):
self.Title = "Announce GUI"
self.Author = "FlamingMojo"
self.Version = V(1, 0, 1)
self.HasConfig = True
self.TINTCOLOURS = {
'grey_tint' : "0.1 0.1 0.1 0.7",
'red_tint' : "0.5 0.1 0.1 0.7",
'green_tint' : "0.1 0.4 0.1 0.5",
'yellow_tint': "0.7 0.7 0.1 0.5",
'orange_tint': "0.8 0.5 0.1 0.5",
'blue_tint' : "0.1 0.1 0.4 0.5",
'black_tint' : "0.01 0.01 0.01 0.9"}
self.TEXTCOLOURS = {
'red_text' : "0.8 0.1 0.1",
'yellow_text' : "0.7 0.7 0.1",
'green_text' : "0.1 0.8 0.1",
'blue_text' : "0.1 0.1 0.8",
'white_text' : "1 1 1",
'orange_text' : "0.8 0.5 0.1"}
self.fadeInTime = 0.5
self.fadeOutTime = 0.5
self.Default = {
'Version' : '1.0.0',
'TextSize' : 15,
'AnnounceTime' : 10,
'GUIColour' : 'yellow_tint',
'TextColour' : 'red_text'}
self.timers = []
def OnServerInitialized(self):
command.AddConsoleCommand("notice.create", self.Plugin, "createNotice")
def LoadDefaultConfig(self):
self.Config.clear()
self.Config = self.Default
self.SaveConfig()
def createNotice(self,player,cmd,args):
if player.IsAdmin():
msg = ''
for arg in args:
msg += arg
msg += ' '
tint = self.TINTCOLOURS[selfConfig['GUIColour']]
txtColor = self.TEXTCOLOURS[selfConfig['TextColour']]
elements = Cui.CuiElementContainer()
imgcomp = Cui.CuiImageComponent(Color = tint, FadeIn = self.fadeInTime)
txtcomp = Cui.CuiTextComponent(Text = msg,
Color = txtColor,
FadeIn = self.fadeInTime,
Align = TextAnchor.MiddleCenter,
FontSize = self.Config['TextSize'])
rectcomp = Cui.CuiRectTransformComponent(AnchorMin = "0.2 0.8", AnchorMax = "0.8 0.95")
guielem = Cui.CuiElement(Name = "announcementGUI", FadeOut = self.fadeOutTime)
guielem.Components.Add(imgcomp)
guielem.Components.Add(rectcomp)
txtelem = Cui.CuiElement(Name = "announcementText",FadeOut = self.fadeOutTime)
txtelem.Components.Add(txtcomp)
txtelem.Components.Add(rectcomp)
elements.Add(guielem)
elements.Add(txtelem)
for player in BasePlayer.activePlayerList:
Cui.CuiHelper.AddUi(player, elements)
newtimer = timer.Once(self.Config['AnnounceTime'],Action(self.destroyGlobalUI), self.Plugin)
self.timers.append(newtimer)
def Unload(self):
for t in self.timers:
t.Destroy()
self.destroyGlobalUI()
def destroyGlobalUI(self):
for player in BasePlayer.activePlayerList:
Cui.CuiHelper.DestroyUi(player, "announcementGUI")
Cui.CuiHelper.DestroyUi(player, "announcementText")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment