Example Scripts - tayjay/SCriPt GitHub Wiki
Readding Skeleton
-- Start by creating a table to hold our functions
scp3114 = SCriPt:Module('Scp3114')
-- Load function, called when the script is loaded
function scp3114:load()
-- Add the function to the event
Events.Server.RoundStarted:add(scp3114.onRoundStarted)
end
-- Unload function, called when the script is unloaded
function scp3114:unload()
-- Remove the function from the event
Events.Server.RoundStarted:remove(scp3114.onRoundStarted)
end
-- Function called when the round starts
function scp3114:onRoundStarted()
-- Get a random number between 1 and 100
local chance = math.random(1, 100)
-- If the number is less than or equal to 25
if chance <= 25 then
-- Get a random player
local player = Player.Random()
-- Change the player's role to Scp3114
player:SetRole(RoleTypeId.Scp3114)
end
end
Put this in a file Scp3114.lua
.
Place the file in Scripts
and it will run when the server starts.
Custom Commands
By specifying some key variables into your script table you can tell SCriPt that it should be loaded as a command. These commands are registered to RemoteAdmin or the client ~
and will have a help entry and auto-complete like any plugin command.
Here is an example of a command that will list all the words CASSIE can say.
cassiewords = SCriPt:Module('CassieWords')
cassiewords.command = SCriPt:Command(
CommandType.Client, -- This is a client command
'cassiewords', -- The command name
{'cwords'}, -- Aliases for the command
'Get a list of words CASSIE can say.', -- Description of the command
'', -- No permissions required for this command
cassiewords.execute
)
function cassiewords:execute(args,sender)
local words = Cassie:GetAllWords()
local output = ''
for i=1, #words do
output = output .. ', ' .. words[i]
end
return {
response=output,
result=true
}
end
Note that there are some strict requirements when making a command object.
- First, like any other script it will be contained in a global table.
- The table should contain a
command_type
field, which can be eitherClient
orRemoteAdmin
. If not specified,RemoteAdmin
will be selected. - The table must contain a
command
field, which is the command name. - An optional table
aliases
can be added to provide additional command names. - An optional string
description
can be added to provide a description of the command for the help display. - An optional string
permissions
can be added which will check the EXILED permission list for whether an RemoteAdmin command be be ran.- Client commands are always allowed.
- If no permissions are supplied, they will be ignored.
- The function
execute
must be defined.- The function must take two arguments,
args
(string[]) andsender
(CommandSender). - The function must return a table with a
response
and aresult
field.
- The function must take two arguments,