Skip to content

Instantly share code, notes, and snippets.

@jonstvns
Last active August 29, 2015 13:55
Show Gist options
  • Save jonstvns/8779234 to your computer and use it in GitHub Desktop.
Save jonstvns/8779234 to your computer and use it in GitHub Desktop.
PLUGIN.Title = "Raffle"
PLUGIN.Description = "Raffle off your items and money"
PLUGIN.Author = "Limyc"
PLUGIN.Version = 1.10
local function split(str, delimiter)
result = {}
if delimiter == nil then
delimiter = "%s"
end
for match in (str..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result
end
-- #### ## ## #### ######## #### ### ## #### ######## ########
-- ## ### ## ## ## ## ## ## ## ## ## ##
-- ## #### ## ## ## ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ## ## ## ## ## ## ######
-- ## ## #### ## ## ## ######### ## ## ## ##
-- ## ## ### ## ## ## ## ## ## ## ## ##
-- #### ## ## #### ## #### ## ## ######## #### ######## ########
function PLUGIN:Init()
-- Load the config file
local b, cfg = config.Read("raffleConfig")
self.Config = cfg or {}
if (not b) then
self:LoadDefaultConfig()
if (cfg) then
config.Save("raffleConfig")
end
end
local econName = string.lower(self.Config.econPlugin)
self:ReloadEconPlugin(econName)
if not (EconPlugin) then
print("NOTICE: No suppported economy plugin found!")
end
oxminPlugin = plugins.Find("oxmin")
if not (oxminPlugin) or not (oxmin) then
print("ERROR: Oxmin not found!")
else
self.FLAG_CANRAFFLE = oxmin.AddFlag("canRaffle")
self.FLAG_CANRAFFLEADMIN = oxmin.AddFlag("canRaffleAdmin")
print("Oxmin flag 'canRaffle' was added successfully")
print("Oxmin flag 'canRaffleAdmin' was added successfully")
end
self:AddChatCommand("raffle", self.CmdRaffle)
self:AddChatCommand("joinraffle", self.CmdJoinRaffle)
self:AddChatCommand("endraffle", self.CmdEndRaffle)
self:AddChatCommand("cancelraffle", self.CmdCancelRaffle)
self:AddChatCommand("helpraffle", self.CmdRaffleHelp)
self:AddChatCommand("configraffle", self.CmdRaffleConfig)
-- Duplicates for consistency
self:AddChatCommand("rafflejoin", self.CmdJoinRaffle)
self:AddChatCommand("raffleend", self.CmdEndRaffle)
self:AddChatCommand("rafflecancel", self.CmdCancelRaffle)
self:AddChatCommand("rafflehelp", self.CmdRaffleHelp)
self:AddChatCommand("raffleconfig", self.CmdRaffleConfig)
RaffleData = {}
WeaponList = {"9mm Pistol", "Bolt Action Rifle", "HandCannon", "M4", "MP5A4", "P250", "Pipe Shotgun", "Research Kit 1", "Revolver", "Shotgun", "Torch"}
local users = rust.GetAllNetUsers()
if users then
for i,v in ipairs(users) do
self:SetupUser(v)
end
end
end
-- ###### ####### ## ## ######## #### ######
-- ## ## ## ## ### ## ## ## ## ##
-- ## ## ## #### ## ## ## ##
-- ## ## ## ## ## ## ###### ## ## ####
-- ## ## ## ## #### ## ## ## ##
-- ## ## ## ## ## ### ## ## ## ##
-- ###### ####### ## ## ## #### ######
-- /raffleconfig [configKeyName] [newValue]
-- Gets or sets the given config variable
function PLUGIN:CmdRaffleConfig(netuser, cmd, args)
if (true or netuser:CanAdmin()) then
local configKey = args[1]
local newValue = args[2]
-- if there is no command name, print all command values
if not configKey then
for k,v in pairs(self.Config) do
self:SendMessage(netuser, k .. " = " .. v)
end
else
local configValue = self.Config[configKey]
if configValue then
-- if the value is not nil, set the new value.
if newValue then
-- validate types
if (type(configValue) == "string") then
if configKey == "econPlugin" then
if (newValue == "market" or newValue == "econ" or newValue == "econfork") then
configValue = newValue
self:ReloadEconPlugin(newValue)
end
else
configValue = newValue
end
elseif (type(configValue) == "number" and tonumber(newValue)) then
configValue = tonumber(newValue)
elseif (type(configValue) == "boolean") then
if newValue == "true" then
configValue = true
elseif newValue == "false" then
configValue = false
else
self:SendMessage(netuser, newValue .. " is not a valid value for " .. configKey)
end
else
self:SendMessage(netuser, newValue .. " is not a valid value for " .. configKey)
end
self.Config[configKey] = configValue
config.Save("raffleConfig")
end
self:SendMessage(netuser, configKey .. " = " .. self.Config[configKey])
else
self:SendMessage(netuser, "No command named '" .. configKey .. "' was found.")
end
end
else
self:SendMessage(netuser, "You must be an admin to change config settings")
end
end
-- Resets all Config variables to their default values
function PLUGIN:LoadDefaultConfig()
self.Config.allowWeapons = false
self.Config.chatName = "Raffle"
self.Config.defaultDuration = 20
self.Config.defaultMaxEntries = 0
self.Config.econPlugin = "market"
end
-- Finds the given plugin and assigns it to EconPlugin
function PLUGIN:ReloadEconPlugin(econName)
if econName == "market" then
EconPlugin = plugins.Find("market")
elseif (econName == "econ" or econName == "econfork") then
EconPlugin = plugins.Find("econ")
end
end
-- Ensures that any new user is initialized for raffles
function PLUGIN:OnUserConnect(netuser)
self:SetupUser(netuser)
end
-- If no index is found in RaffleData, creates a new setup of data for the given userID
function PLUGIN:SetupUser(netuser)
local userID = rust.GetUserID(netuser)
local raffleData = RaffleData[tostring(userID)]
if not raffleData then
raffleData = {}
raffleData.ownerName = netuser.displayName
raffleData.ownerID = userID
raffleData.netowner = netuser
self:ResetRaffleData(raffleData)
RaffleData[tostring(userID)] = raffleData
end
self:PrintRaffleData(tostring(userID))
return raffleData
end
-- Resets the given raffleData to its default values
function PLUGIN:ResetRaffleData(raffleData)
raffleData.duration = self.Config.defaultDuration
raffleData.entries = {}
raffleData.inventory = nil
raffleData.isRunning = false
raffleData.joinPass = ""
raffleData.maxEntries = self.Config.defaultMaxEntries
raffleData.prizeData = {}
raffleData.prizeItems = {}
raffleData.prizeMoney = 0
raffleData.raffleName = ""
if raffleData.timers then
for i,v in ipairs(raffleData.timers) do
v:Destroy()
end
end
raffleData.timers = {}
end
-- ###### #### ## ## ######## #### ######## ### ## ## ########
-- ## ## ## ## ## ## ## ## ## ## ## ## ## ##
-- ## ## ## ## ## #### ## ## ## ## ## ##
-- ## #### ## ## ## ###### #### ## ## ## ##### ######
-- ## ## ## ## ## ## ## ## ## ## ######### ## ## ##
-- ## ## ## ## ## ## ## ## ## ## ## ## ## ##
-- ###### #### ### ######## #### ## ## ## ## ## ## ########
-- Removes items from the given inventory inventory
function PLUGIN:TakeItem(raffleData, prizeData)
local inventory = raffleData.inventory
local amount = prizeData.amount
local isWeapon = prizeData.isWeapon
local datablock = rust.GetDatablockByName(prizeData.itemName)
local item = inventory:FindItem(datablock)
local i = 0
-- Remove item until required amount is reached or no more of that item is available
if item then
if isWeapon then
while (i < amount) do
inventory:RemoveItem(item)
i = i + 1
item = inventory:FindItem(datablock)
if (not item) then
break
end
end
else
while (i < amount) do
if (item.uses > 0) then
item:SetUses( item.uses - 1 )
i = i + 1
else
inventory:RemoveItem(item)
item = inventory:FindItem(datablock)
if (not item) then
break
end
end
end
end
if (item and item.uses <= 0) then
inventory:RemoveItem(item)
end
if amount ~= i then
prizeData.amount = i
end
end
end
-- Adds the specified item to the inventory provided
function PLUGIN:GiveItem(inventory, itemData)
local datablock = rust.GetDatablockByName(itemData.itemName)
local prefs = rust.InventorySlotPreference(InventorySlotKind.Default, false, InventorySlotKindFlags.Belt)
inventory:AddItemAmount(datablock, itemData.amount, prefs)
end
-- Removes money from the user's balance using the installed economy plugin
function PLUGIN:TakeMoney(netuser, amount)
if EconPlugin then
local econName = string.lower(self.Config.econPlugin)
if econName == "market" then
EconPlugin:RemoveBalance(netuser, amount)
elseif econName == "econ" then
EconPlugin:takeMoneyFrom(netuser, amount)
elseif econName == "econfork" then
EconPlugin:takeMoneyFrom(netuser, amount)
end
else
self:SendMessage(netuser, "Cannot take money. No valid economy plugin found.")
end
end
-- Gives money to the user's balance using the installed economy plugin
function PLUGIN:GiveMoney(netuser, amount)
if EconPlugin then
local econName = string.lower(self.Config.econPlugin)
if econName == "market" then
EconPlugin:AddBalance(netuser, amount)
elseif econName == "econ" then
EconPlugin:giveMoneyTo(netuser, amount)
elseif econName == "econfork" then
EconPlugin:giveMoneyTo(netuser, amount)
end
else
self:SendMessage(netuser, "Cannot give money. No valid economy plugin found.")
end
end
-- Hand out prize items and money to the specified user
function PLUGIN:GivePrizes(netuser, prizeData, prizeMoney)
local inventory = netuser.playerClient.rootControllable.idMain:GetComponent("Inventory")
print("Total of " .. #prizeData .. " items in the raffle")
for i,itemData in ipairs(prizeData) do
self:GiveItem(inventory, itemData)
end
if prizeMoney > 0 then
self:SendMessage(netuser, "Giving $" .. prizeMoney)
self:GiveMoney(netuser, prizeMoney)
end
end
-- ######## ### ######## ######## ## ########
-- ## ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ## ##
-- ######## ## ## ###### ###### ## ######
-- ## ## ######### ## ## ## ##
-- ## ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ######## ########
-- /raffle ["raffleName] [duration] [maxEntries] ["item:amount"] ["password"]
-- Starts a raffle based on the given arguments
function PLUGIN:CmdRaffle(netuser, cmd, args)
local userID = rust.GetUserID(netuser)
local raffleData = RaffleData[tostring(userID)]
-- if doesn't exist, setup user data
if not raffleData then
raffleData = self:SetupUser(netuser)
end
if not raffleData.isRunning then
if (netuser:CanAdmin() or oxminPlugin:HasFlag(netuser, self.FLAG_CANRAFFLEADMIN, true) or oxminPlugin:HasFlag(netuser, self.FLAG_CANRAFFLE, true)) then
self:ResetRaffleData(raffleData)
raffleData.isRunning = true
local argIndex = 1
local skipArgs = false
if not args[1] then
skipArgs = true
end
local raffleName = args[argIndex]
-- if raffleName isn't a number, we know the args don't start with duration or maxEntries
if (not tonumber(raffleName) and not skipArgs) then
local name = split(args[1], ":")
-- if the length of the table is 1, then this should be the raffleName. Otherwise, we know it's an item.
if #name == 1 then
raffleData.raffleName = raffleName
argIndex = argIndex + 1
else
raffleData.raffleName = netuser.displayName
skipArgs = true
end
else
raffleData.raffleName = netuser.displayName
end
-- if the first argument was an item, don't bother checking for the duration and maxEntries args
if not skipArgs then
local duration = tonumber(args[argIndex])
if duration then
if duration < 10 then
duration = 10
end
raffleData.duration = duration
argIndex = argIndex + 1
else
raffleData.duration = self.Config.defaultDuration
end
local entries = tonumber(args[argIndex])
if entries then
if entries >= 0 then
raffleData.maxEntries = entries
else
raffleData.maxEntries = self.Config.defaultMaxEntries
end
argIndex = argIndex + 1
else
raffleData.maxEntries = self.Config.defaultMaxEntries
end
else
raffleData.duration = self.Config.defaultDuration
raffleData.maxEntries = self.Config.defaultMaxEntries
end
raffleData.inventory = netuser.playerClient.rootControllable.idMain:GetComponent("Inventory")
-- Store item names and amounts in raffleData
for i = argIndex, #args, 1 do
--[[TODO: Add support for "all"
-- check if the user is raffling entire inventory
if args[i] == "all" then
-- Something with all inventory
if args[i+1] then
raffleData.joinPass = args[i+1]
break
end
end
--]]
local prizes = split(args[i], ":")
if #prizes > 1 then
local msg = self:GetPrizeList(raffleData, prizes)
if msg then
self:SendMessage(netuser, msg)
self:ResetRaffleData(raffleData)
return
end
elseif (i == #args and #prizes == 1) then
raffleData.joinPass = args[i]
else
self:SendMessage(netuser, "Invalid syntax for item '" .. args[i] .. "'")
self:ResetRaffleData(raffleData)
return
end
end
-- if all items and amounts were valid, remove them from the owner's inventory and store them in RaffleData
for i,v in ipairs(raffleData.prizeData) do
self:TakeItem(raffleData, v)
end
-- Remove the prize money from the owner's balance
if raffleData.prizeMoney > 0 then
self:TakeMoney(netuser, raffleData.prizeMoney)
end
self:SendMessageAll("The raffle '" .. raffleData.raffleName .. "' has begun! Duration: " .. raffleData.duration .. " seconds")
if raffleData.joinPass ~= "" then
self:SendMessageAll("This raffle requires a password")
end
local winTimer = timer.Once(raffleData.duration, function() self:GetWinner(raffleData) end)
table.insert(raffleData.timers, winTimer)
if (raffleData.duration > 15) then
winTimer = timer.Once(raffleData.duration - 10, function() self:BroadcastAlert(raffleData.raffleName) end)
table.insert(raffleData.timers, winTimer)
end
else
self:SendMessage(netuser, "You need the 'canRaffle' Oxmin flag to start a raffle")
end
else
self:SendMessage(netuser, "You already have a raffle in progress")
end
end
-- Inserts a list of all prize names with their amounts into raffleData.prizeData
function PLUGIN:GetPrizeList(raffleData, prizes)
local itemName = prizes[1]
local amount = tonumber(prizes[2])
if ((not amount) or amount <= 0) then
return "Invalid amount " .. prizes[2]
end
if (string.lower(itemName) == "money") then
raffleData.prizeMoney = amount
else
local isWeapon = self:IsWeapon(itemName)
if ((not isWeapon) or self.Config.allowWeapons) then
local item = self:GetInventoryItemByName(raffleData.inventory, itemName)
if item then
local prizeData = {}
prizeData.itemName = itemName
prizeData.item = item
prizeData.amount = amount
prizeData.isWeapon = isWeapon
table.insert(raffleData.prizeData, prizeData)
else
return itemName .. " was not found in your inventory"
end
else
return "Weapon prizes are disabled"
end
end
return nil
end
-- Returns true if the itemName is found in the WeaponsList table
function PLUGIN:IsWeapon(itemName)
for i = 0, #WeaponList, 1 do
if WeaponList[i] == itemName then
return true
end
end
return false
end
-- Finds and returns an item in a players inventory
function PLUGIN:GetInventoryItemByName(inventory, itemName)
local datablock = rust.GetDatablockByName(itemName)
-- check if the item exists
if datablock then
local item = inventory:FindItem(datablock)
-- check if the user has the item in their inventory
if item then
return item
else
return nil
end
else
return nil
end
end
-- ## ####### #### ## ##
-- ## ## ## ## ### ##
-- ## ## ## ## #### ##
-- ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ####
-- ## ## ## ## ## ## ###
-- ###### ####### #### ## ##
-- /joinraffle ["raffleName"] ["password"]
-- Enters the sender into the specified raffle
-- If no raffleName is specified, the sender will be entered into all public raffles
function PLUGIN:CmdJoinRaffle(netuser, cmd, args)
local userID = rust.GetUserID(netuser)
-- if no args, join all public raffles
if not args[1] then
local count = 0
for k,v in pairs(RaffleData) do
if v.isRunning and v.joinPass == "" then
local msg = self:JoinRaffle(netuser, userID, v)
if (not msg) then
count = count + 1
end
end
end
if count == 0 then
self:SendMessage(netuser, "There were no public raffles to join")
end
else
local ownerID, msg = self:GetOwnerID(args[1])
if ownerID then
local raffleData = RaffleData[tostring(ownerID)]
if raffleData then
if (raffleData.joinPass == "" or (args[2] and args[2] == raffleData.joinPass)) then
local msg = self:JoinRaffle(netuser, userID, raffleData)
if msg then
self:SendMessage(netuser, msg)
end
else
self:SendMessage(netuser, "Incorrect password for this raffle")
end
else
self:SendMessage(netuser, "No raffle data for " .. args[1] .. " exists")
end
else
self:SendMessage(netuser, msg)
end
end
end
-- Finds the raffleName in RaffleData and returns the ownerID
function PLUGIN:GetOwnerID(raffleName)
for k,v in pairs(RaffleData) do
if v.raffleName == raffleName then
return v.ownerID, nil
end
end
return nil, "Raffle '" .. raffleName .. "' not found"
end
-- Enters the user into the speficied raffle if they have not already entered
function PLUGIN:JoinRaffle(netuser, userID, raffleData)
if raffleData.isRunning then
if (raffleData.maxEntries <= 0 or #raffleData.entries < raffleData.maxEntries) then
local isDuplicate = false
for i,v in ipairs(raffleData.entries) do
if userID == v then
isDuplicate = true
break
end
end
if not isDuplicate then
local userData = {}
userData.userName = netuser.displayName
userData.ID = userID
userData.netuser = netuser
table.insert(raffleData.entries, userData)
else
return "You have already entered the raffle '" .. raffleData.raffleName .. "'"
end
else
return "Max number of entries has been reached for the raffle '" .. raffleData.raffleName .. "'"
end
else
return "There is no raffle named '" .. raffleData.raffleName .. "'"
end
return nil
end
-- ######## ## ## ######## ## ###### ### ## ## ###### ######## ##
-- ## ### ## ## ## ## ## ## ## ## ### ## ## ## ## ##
-- ## #### ## ## ## ## ## ## ## #### ## ## ## ##
-- ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ##
-- ## ## #### ## ## ## ## ######### ## #### ## ## ##
-- ## ## ### ## ## ## ## ## ## ## ## ### ## ## ## ##
-- ######## ## ## ######## ## ###### ## ## ## ## ###### ######## ########
-- /endraffle ["raffleName"]
-- Ends the raffle belonging to the specified user immediately
function PLUGIN:CmdEndRaffle(netuser, cmd, args)
local netowner, raffleData, msg = self:VerifyEndArgs(netuser, args[1])
if not netowner then
self:SendMessage(netuser, msg)
return
end
-- Attempt to end the raffle
if (netuser == netowner or netuser:CanAdmin() or oxminPlugin:HasFlag(netuser, self.FLAG_CANRAFFLEADMIN, true))then
self:SendMessageAll("The raffle '" .. raffleData.raffleName .. "' was ended prematurely by " .. netuser.displayName)
self:GetWinner(raffleData)
else
self:SendMessage(netuser, "You do not have permission to use this command on raffles you do not own.")
end
end
-- /cancelraffle ["raffleName"]
-- Cancels the given user's raffle in progress and returns the prizes to the owner
function PLUGIN:CmdCancelRaffle(netuser, cmd, args)
local netowner, raffleData, msg = self:VerifyEndArgs(netuser, args[1])
if not netowner then
self:SendMessage(netuser, msg)
return
end
-- Attempt to cancel the raffle
if (netuser == netowner or netuser:CanAdmin() or oxminPlugin:HasFlag(netuser, self.FLAG_CANRAFFLEADMIN, true)) then
self:GivePrizes(netuser, raffleData.prizeData, raffleData.prizeMoney)
self:ResetRaffleData(raffleData)
self:SendMessageAll("The raffle '" .. raffleData.raffleName .. "' has been canceled by " .. netuser.displayName)
else
self:SendMessage(netuser, "You do not have permission to use this command on raffles you do not own.")
end
end
-- Checks if the arguments are valid for /endraffle and /cancelraffle
-- returns nil, nil, msg if any errors occur
function PLUGIN:VerifyEndArgs(netuser, raffleName)
local netowner = nil
local raffleData = nil
if raffleName then
local ownerID, msg = self:GetOwnerID(raffleName)
if ownerID then
raffleData = RaffleData[tostring(ownerID)]
end
if raffleData then
if raffleData.isRunning then
local isFound, tempNetowner = rust.FindNetUsersByName(raffleData.ownerName)
netowner = tempNetowner
if not netowner then
return nil, nil, "The raffle '" .. raffleName .. "' was not found."
end
else
return nil, nil, "The raffle '" .. raffleName .. "' is not running."
end
else
self:SetupUser(netuser)
return nil, nil, msg
end
else
local userID = rust.GetUserID(netuser)
raffleData = RaffleData[tostring(userID)]
if raffleData then
if raffleData.isRunning then
netowner = netuser
else
return nil, "You have no raffle active."
end
else
self:SetupUser(netuser)
return nil, nil, "There is no raffle data associated with your user ID. Creating data now."
end
end
return netowner, raffleData, nil
end
-- Randomly picks an entry from the raffleData.entries table and awards the prizes to the winner
function PLUGIN:GetWinner(raffleData)
if raffleData.isRunning then
raffleData.isRunning = false
if #raffleData.entries > 0 then
local index = math.random(#raffleData.entries)
for i,userData in ipairs(raffleData.entries) do
if index == i then
self:GivePrizes(userData.netuser, raffleData.prizeData, raffleData.prizeMoney)
self:SendMessageAll(userData.userName .. " has won the '" .. raffleData.raffleName .. "' raffle!")
break
end
end
else
self:GivePrizes(raffleData.netowner, raffleData.prizeData, raffleData.prizeMoney)
self:SendMessageAll("There were no entries for the raffle '" .. raffleData.raffleName .. "'...")
end
end
self:ResetRaffleData(raffleData)
end
-- ## ## ######## ## ########
-- ## ## ## ## ## ##
-- ## ## ## ## ## ##
-- ######### ###### ## ########
-- ## ## ## ## ##
-- ## ## ## ## ##
-- ## ## ######## ######## ##
-- /rafflehelp [commandName]
-- Prints out information about the various raffle commands
function PLUGIN:CmdRaffleHelp(netuser, cmd, args)
local str = args[1] or "rafflehelp"
if str == "raffle" then
self:SendMessage(netuser, "-------------------------------------Raffle Help-------------------------------------")
self:SendMessage(netuser, "/raffle [\"raffleName\"] [duration] [maxEntries] [\"item:amount\"] [\"password\"]")
self:SendMessage(netuser, "Starts a new raffle. If no items are specified, the raffle will begin with no prizes")
self:SendMessage(netuser, "Multiple items can be added as prizes (e.g. /raffle \"itemA:3\" \"itemB:5\").")
self:SendMessage(netuser, "If the item amount is greater than your stock. All available items will be taken.")
self:SendMessage(netuser, "NOTE: Arguments surrounded by '[]' are optional. You do not need to type the brackets.")
self:SendMessage(netuser, "NOTE: Quotations are required for arguments that include spaces (e.g \"9mm Pistol:1\").")
self:SendMessage(netuser, "-------------------------------------------------------------------------------------")
elseif (str == "joinraffle" or str == "rafflejoin") then
self:SendMessage(netuser, "----------------------------------Join Raffle Help-----------------------------------")
self:SendMessage(netuser, "/joinraffle [\"rafflename\"] [\"password\"]")
self:SendMessage(netuser, "Joins a raffle in progress. All public raffles will be entered if no arguments given.")
self:SendMessage(netuser, "NOTE: Arguments surrounded by '[]' are optional. You do not need to type the brackets.")
self:SendMessage(netuser, "NOTE: Quotations are required for arguments that include spaces (e.g \"9mm Pistol:1\").")
self:SendMessage(netuser, "-------------------------------------------------------------------------------------")
elseif (str == "endraffle" or str == "raffleend") then
self:SendMessage(netuser, "-----------------------------------End Raffle Help-----------------------------------")
self:SendMessage(netuser, "/endraffle [\"rafflename\"]")
self:SendMessage(netuser, "Ends a raffle in progress. Your raffle will be ended if no arguments given.")
self:SendMessage(netuser, "NOTE: Arguments surrounded by '[]' are optional. You do not need to type the brackets.")
self:SendMessage(netuser, "NOTE: Quotations are required for arguments that include spaces (e.g \"9mm Pistol:1\").")
self:SendMessage(netuser, "-------------------------------------------------------------------------------------")
elseif (str == "cancelraffle" or str == "rafflecancel") then
self:SendMessage(netuser, "---------------------------------Cancel Raffle Help----------------------------------")
self:SendMessage(netuser, "/cancelraffle [\"rafflename\"]")
self:SendMessage(netuser, "Cancels a raffle in progress. Your raffle will be canceled if no arguments given.")
self:SendMessage(netuser, "NOTE: Arguments surrounded by '[]' are optional. You do not need to type the brackets.")
self:SendMessage(netuser, "NOTE: Quotations are required for arguments that include spaces (e.g \"9mm Pistol:1\").")
self:SendMessage(netuser, "-------------------------------------------------------------------------------------")
elseif (str == "helpraffle" or str == "rafflehelp") then
self:SendMessage(netuser, "-----------------------------------Raffle Commands-----------------------------------")
self:SendMessage(netuser, "/raffle [\"raffleName\"] [duration] [maxEntries] [\"item:amount\"] [\"password\"]")
self:SendMessage(netuser, "/joinraffle [\"rafflename\"] [\"password\"]")
self:SendMessage(netuser, "/endraffle [\"rafflename\"]")
self:SendMessage(netuser, "/cancelraffle [\"rafflename\"]")
self:SendMessage(netuser, "**ADMIN ONLY** /raffleconfig configName [newValue]")
self:SendMessage(netuser, "NOTE: Arguments surrounded by '[]' are optional. You do not need to type the brackets.")
self:SendMessage(netuser, "NOTE: Quotations are required for arguments that include spaces (e.g \"9mm Pistol:1\").")
self:SendMessage(netuser, "For info on a specific command, use /rafflehelp commandName")
self:SendMessage(netuser, "-------------------------------------------------------------------------------------")
elseif (str == "configraffle" or str == "raffleconfig")then
self:SendMessage(netuser, "---------------------------------Raffle Config Help----------------------------------")
self:SendMessage(netuser, "/raffleconfig [configKeyName] [newValue]")
self:SendMessage(netuser, "Gets or sets the value of the given config variable.")
self:SendMessage(netuser, "If no arguments are given, all config values will be printed.")
self:SendMessage(netuser, "NOTE: Config key is case-sensitive")
self:SendMessage(netuser, "NOTE: Arguments surrounded by '[]' are optional. You do not need to type the brackets.")
self:SendMessage(netuser, "**THIS COMMAND REQUIRES ADMIN**")
self:SendMessage(netuser, "-------------------------------------------------------------------------------------")
end
end
-- Directs the user to use /rafflehelp for help with this plugin
function PLUGIN:SendHelpText(netuser)
self:SendMessage(netuser, "Use /rafflehelp to see all Raffle plugin commands")
end
-- ## ## ######## #### ## #### ######## ## ##
-- ## ## ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ## ####
-- ## ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ## ##
-- ## ## ## ## ## ## ## ##
-- ####### ## #### ######## #### ## ##
-- Alerts users that a raffle is about to end
function PLUGIN:BroadcastAlert(raffleName)
self:SendMessageAll("10 seconds remaining before " .. raffleName .. "'s raffle ends!")
end
-- Sends a message to the specified netuser
function PLUGIN:SendMessage(netuser, msg)
rust.SendChatToUser(netuser, self.Config.chatName, msg)
end
-- Broadcasts a message to all connected users
function PLUGIN:SendMessageAll(msg)
rust.BroadcastChat(self.Config.chatName, msg)
end
-- For testing
function PLUGIN:PrintRaffleData(userID)
for k,v in pairs(RaffleData[userID]) do
print(k .. " = " .. tostring(v))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment