Inputs - photonle/Photon-v2 GitHub Wiki

This is a reference of Photon 2's standardized inputs. While Photon 2's input scheme is fully customizable, it is recommended to use standardized inputs to maximize inter-component compatibility (as this is what default components are based on).

Priorities

These are the default input priorities. Inputs with higher numbers override those with lower numbers. Input priorities can be adjusted per component.

-- These are the approximate default values.

-- As they may occasionally change, the actual values can be
-- found in the lua/photon-v2/meta/base_entity.lua file.

ENT.DefaultInputPriorities = {
   ["Emergency.Cut"]            = 160,
   ["Emergency.Illuminate"]     = 150,
   ["Emergency.SceneForward"]   = 140,
   ["Emergency.SceneLeft"]      = 130,
   ["Emergency.SceneRight"]     = 120,
   ["Vehicle.Signal"]           = 110,
   ["Vehicle.Brake"]            = 100,
   ["Vehicle.Transmission"]     = 90,
   ["Emergency.Directional"]    = 80,
   ["Emergency.Auxiliary"]      = 70,
   ["Emergency.Siren2Override"] = 61,
   ["Emergency.SirenOverride"]  = 60,
   ["Emergency.Siren2"]         = 51,
   ["Emergency.Siren"]          = 50,
   ["Emergency.Warning"]        = 40,
   ["Emergency.Marker"]         = 30,
   ["Vehicle.HighBeam"]         = 20,
   ["Vehicle.Lights"]           = 10,
   ["Vehicle.Ambient"]          = 0
}

Emergency.Warning

Use for the primary warning lights.

  • MODE1 Stage 1 lighting mode. Typically a rear-facing flash pattern with minimal or no forward-facing warning lights activated. Sometimes used to steady-burn all warning lights with a very brief flash on modern setups.
  • MODE2 Stage 2 lighting mode. Usually flashes forward-facing warning lights. The rear patterns may be the same as mode 1 or they may flash faster.
  • MODE3 Stage 3 lighting mode. Often adds white flashing (including headlights) and occasionally disables any rear-facing amber lighting. Sometimes uses faster flash patterns than mode 2.

Emergency.Scene...

Used for scene lighting/illumination.

SceneForward

  • ON Takedown lighting. Adds dedicated forward-facing white lights.
  • FLOOD Flood lighting. Typically sets most or all forward-facing lights to steady-burn white and is brighter than takedown lighting.

SceneLeft

  • ON Left alley/left side.

SceneRight

  • ON Right alley/left side.

Emergency.Marker

For cruise/marker lighting.

  • ON Normal cruise/marker lighting mode.

Emergency.Directional

For traffic advisor patterns.

  • LEFT Arrow left.
  • RIGHT Arrow right.
  • CENOUT Arrow center-out/diverge.

Emergency.Cut

  • FRONT Cut out front-facing lights.
  • REAR Cut out rear-facing lights.

Vehicle.Ambient

  • OFF Vehicle in a bright/daytime environment.
  • DARK Vehicle in a dark/nighttime environment.

Vehicle.Lights

  • HEADLIGHTS Vehicle headlights on.
  • PARKING Vehicle parking lights on.
  • DRL AUTO Daytime running lights and automatic headlights.

Vehicle.Brake

  • BRAKE Vehicle brake lights.

Vehicle.Signal

  • LEFT Left turn signal.
  • RIGHT Right turn signal.
  • HAZARD Hazard lights (four-way flashers).

Vehicle.Transmission

  • PARK Vehicle parked (i.e. no driver).
  • DRIVE Vehicle driving (i.e. has driver).
  • REVERSE Vehicle reversing.

Virtual Inputs

[!NOTE] There are no default virtual outputs. They must be either manually configured or automatically added using COMPONENT.Flags as outputs to be utilized. Furthermore, virtual inputs added from flags will usually copy from an existing channel mode. You only need to implement these modes manually in unusual circumstances.

Emergency.ParkedWarning

  • MODE3 When vehicle is parked and Emergency.Warning is set to MODE3.

Emergency.NightParkedWarning

  • MODE3 When vehicle is parked, Emergency.Warning is set to MODE3, and the vehicle is in a dark environment.

Vehicle.AutomaticLighting

  • HEADLIGHTS Headlights that are automatically activated.

Creating Custom Channels

For special actions that don't fit the provided default channels, you can use a custom channel instead. Creating and using a new channel requires only three things: a unique name, an input priority, and a command you can bind keys to.

For this example, a channel called Emergency.Command will be created for the purpose of activating green steady-burn lights on a lightbar. The following segment has been created:

COMPONENT.Segments = {
   -- New "Command" segment
   Command = {
      Frames = {
         [1] = "[G] 12 14 16 18 11 13 15 17"
      },
      Sequences = {
         ["ON"] = { 1 }
      }
   }
}

Adding a channel to the COMPONENT.Inputs section without an assigned input priority will result in an error when saving the component, so the input priority will be added first. To ensure the steady-burn green lights are visible while warning lights are flashing, an input priority number higher than Emergency.Warning should be used. In this example, we will use 41.

As it's uncommon to adjust input priorities on components, a new COMPONENT.InputPriorities block will likely need to be added.

COMPONENT.InputPriorities = {
   -- This is the new channel, and 41 means it will take 
   -- priority over Emergency.Warning, which is 40.
   ["Emergency.Command"] = 41
}

Now that an input priority has been assigned, the new channel can be safely added to COMPONENT.Inputs. As this channel needs only a basic on/off functionality, the mode used will simply be "ON".

COMPONENT.Inputs = {
   -- This is the new channel
   ["Emergency.Command"] = {
      -- This is the new mode
      ["ON"] = {
         -- And this is the new segment
         Command = "ON"
      }
   }
}

The component file should now save without any errors or warnings. To verify that the changes were registered, the component can be inspected in the preview browser, where the new input channel and mode should appear under the "Inputs" node.

gmod_DrMZb2P6c0

Next, a command must be created so players actually activate the mode from the vehicle. In the addon project folder, create a new file for the Commands library to load. The path should be based on the following:

garrysmod\addons\my_photon_addon\photon-v2\library\commands\custom_command_file.lua

For this example, a basic toggle on/off command will be used (which will also trigger control panel beeps). This means a button is pressed to turn the channel on, and pressing the same button will turn the channel off again. Adapt the code block to your new channel and mode:

Photon2.RegisterCommand({
   -- Use a unique command name
   Name = "toggle_command_mode",
   -- Use your name
   Author = "Your Name",
   -- Give the command a short title
   Title = "Command Mode",
   -- Use an appropriate category (can be anything)
   Category = "Custom",
   -- Describe what the command does
   Description = "Toggles command mode lighting.",
   -- Actions that occur when the key is pushed down
   OnPress = {
      -- Activates controller beep (leave this)
      { Action = "SOUND",  Sound = "Controller" },
      -- Insert the new channel, then the mode under `Value`
      { Action = "TOGGLE", Channel = "Emergency.Command", Value = "ON" },
   },
   -- Actions that occur when the key is lifted
   OnRelease = {
      -- Activates controller beep (leave this)
      { Action = "SOUND", Sound = "Controller" },
   }
})

Save the file and restart the game to ensure the file is discovered and loaded correctly.

Next, the command needs to be bound to button. To do this, open the Control Options menu (also called the Input Configuration menu). The new command should appear in the list.

image

At the bottom of the window, click the button under "Key/Button" that says NONE, and press a key you wish to bind to the command. As soon as the Input Configuration menu detects a change, a save and discard button will appear at the very bottom of the window. To apply your changes, press "Save Changes."

gmod_g68CcSNTiJ

[!NOTE] As of March 11, 2024, it is not possible for vehicle files to manipulate user controls automatically. That means users of your component/vehicle will need to bind a button to the command on their own.

An automatic solution to skip this is planned and being worked on.

Your new channel and command are now ready for use. To test it, simply spawn and enter the vehicle with the component you modified. When you press the assigned button, the mode will toggle on and off.

gmod_NIOwUdxIZt