Dummies - tayjay/SCriPt GitHub Wiki

SCP:SL has a feature known as "Dummies" that allows you to essentially spawn and control NPCs. This feature is new in SCP:SL and is starting to be utilized in RemoteAdmin, but SCriPt has controls to do more in the meantime.

Dummy Global

Dummy.*

Spawn

Spawns a new dummy with the specified name. The dummy will spawn as a spectator, use .SetRole to set its role.

Type Parameter
String name

Returns a Player object that can be used to control the dummy.

Remove

Type Parameter
Player dummy

GetDummyActions

Type Parameter
Player dummy

Returns a Table of strings that represent the actions available to the dummy. This can be used to see what actions are available for the dummy to perform.

Action

Type Parameter
Player dummy
String action

Run a single action on the dummy. This will wait for the action to complete before returning. See "Actions" below for more information.

ActionSequence

Type Parameter
Player dummy
Table sequence

The second parameter is a table of strings and arrays. Each string cooresponds to an action avaialbe to the dummy. Lines with a string will be ran on their own and wait to complete before moving to the next action. Lines with arrays will run all actions at the same time, and wait for the longest action to complete.

local sequence = {
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    {'CurrentHorizontal-180','Walk forward 0.5m'},
    'WaitSeconds_1',
    {'Jump','Walk forward 0.5m'}
}

Actions

This information is based on best guesses from reverse engineering the dummy code, so final results may vary.

So what are actions? Depending on the role and item held by the dummy, it will have different actions available to it. Using the Dummy.GetDummyActions function will list all actions available to be ran. For example, these are the actions available to a Class D dummy:

CurrentHorizontal-1
CurrentHorizontal+1
CurrentVertical-1
CurrentVertical+1
CurrentHorizontal-10
CurrentHorizontal+10
CurrentVertical-10
CurrentVertical+10
CurrentHorizontal-45
CurrentHorizontal+45
CurrentVertical-45
CurrentVertical+45
CurrentHorizontal-180
CurrentHorizontal+180
CurrentVertical-180
CurrentVertical+180
Walk left 0.05m
Walk right 0.05m
Walk forward 0.05m
Walk back 0.05m
Walk left 0.2m
Walk right 0.2m
Walk forward 0.2m
Walk back 0.2m
Walk left 0.5m
Walk right 0.5m
Walk forward 0.5m
Walk back 0.5m
Walk left 1.5m
Walk right 1.5m
Walk forward 1.5m
Walk back 1.5m
Jump

These can be ran using the Dummy.Action function if you want to run a single action, or you can use the Dummy.ActionSequence function to run a sequence of actions.

I have also added some custom actions to make things easier:

WaitSeconds_X -- Wait for X seconds (accepts decimal values)
Hold_ItemType -- Hold the specified item type, if in inventory (e.g. Hold_Scp500, Hold_None)
Drop -- Drop the currently held item
Emotion_EmotionPresetType -- Set the emotion of the dummy to the specified EmotionPresetType (e.g. Emotion_Happy)

In this example, we will create a remote admin command that spawns a dummy and makes it perform a sequence of actions. The sequence will make the dummy spin 180 degrees every second.

local sequence = { -- Step 0: Define the sequence of actions for the dummy to perform.
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1',
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1',
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1',
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1',
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1',
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1',
    'CurrentHorizontal+180',
    'WaitSeconds_1',
    'CurrentHorizontal-180',
    'WaitSeconds_1'
}

local function execute_npc_command(args, sender) -- Step 3: This function will be called when the 'npc' remote admin command is ran.
    Timing:RunCoroutine(function()  -- Step 4: Use a coroutine to run the command over time.
        local dummy = Dummy.Spawn('Controlled') -- Spawn a new dummy
        coroutine.yield(3) -- Wait a few seconds for it to join.
        dummy.SetRole(RoleTypeId.ClassD) -- Set its role to Class D
        dummy.Position = sender.Player.Position -- Set the dummy's position to the sender's position
        coroutine.yield(1) -- Wait a second to ensure the dummy is ready
        Dummy.ActionSequence(dummy,sequence) -- Step 5: Run the action sequence on the dummy. This happens asynchronously, so it will not block the command from returning.
    end)
end

npc_mod = SCriPt.Mod('NPC') -- Step 1. Create a module for the NPC commands
npc_mod.command = SCriPt.Command( -- Step 2. Create a command for running this in game.
        CommandType.RemoteAdmin, -- Command Type
        'npc', -- Name
        {'npc'}, -- Alternate names
        'Do NPC Lua Command', -- Description
        'script.npc', -- Permission required
        execute_npc_command -- Function to run when called
)