

Make NPCs play music!
Uses the Kits and GUI Announcements (optional) plugins from umod.org.
Current version: 1.2.6
As of version 1.2.6, no external NPC plugins are used, and we manage our own musician NPCs. Keep this in mind and save your data files in case you need to go back to 1.2.5!
Playback converted midi files in ToneJs format. Ability to assign NPCs to each track including a single NPC on multiple tracks per song. NPCs are associated with a song by their band number and the type of instrument.
The NPCs must be assigned to a band number (1 - XX with 99 for Outpost), and must have a kit with either a held instrument or positioned within 1.5m of a mountable instrument and with allowsit set to true.
The ToneJs format converts midi to json format with information for track, notes and octave for each track along with other information. We can't use of what it provides such as control changes for pitch bending. This is not currently implemented into Rust instruments. Anyway, Rust is a game, not a DAW or MIDI sequencing app. So, this is a nice to have not an absolute requirement.
Hire NPCs where you stand to assign them to your band.
You may optionally spawn a band on the Outpost stage. This will be band 99.
You will need to convert your midi files to ToneJs format using our converter or this converter. There are other examples out there as well.
The following permissions are used by NPC Music Player:
npcplay.use
=> Allow user to run the /song, /band, /hire, and /movem commands{
"Use GUIAnnouncements plugin for autostart bands: ": false,
"AutoSpawn Outpost: ": false,
"Outpost Band Trigger Start: ": false,
"Outpost Band Trigger Stop: ": false,
"Outpost Band Autostart: ": false,
"Outpost Band Repeat: ": false,
"Repeat Delay: ": 5.0,
"AutoSpawn Outpost Song: ": null
"Trigger Start/Stop Distance: ": 10.0,
"Version": {
"Major": 1,
"Minor": 2,
"Patch": 6
}
}
The trigger start/stop settings determine whether the band will start playing when a player is in range or stop when they leave.
Many/most of these commands work best when used via the band gui (/band NUM gui):
/song list
= List songs in the data/NPCPlay/songs subdirectory
/song load ID
= Load a song (for use in previewing, showing info, etc.
/song info
= Show track info for loaded song
/band list
= List configured bands (group of NPCs and a song)
/band ID gui
= A graphical user interface for editing song track assignments for a band. THIS IS THE MAIN GUI YOU WILL WORK FROM.
/band ID info
= Show info for a particular band
/band ID play
= Start band number ID
/band ID stop
= Stop band number ID
/band ID song ID
= Add song with ID from song list to a band (NOTE THAT THIS HAS CHANGED)
/band ID assign NPCID TRACKNUM
= Add an existing npc with NPCID to a band, assigning to a specific track
/band ID drum TRACKNUM
= Setup a single track to be the drum track. There is special handling for octave on this track.
/band ID tstart
= Allow trigger start (NPC Enter, etc.)
/band ID tstop
= Allow trigger stop (NPC Leave, etc.)
/band ID hire
= Start or stop the hiring process. When active, you can select NPCs for your band by pressing "E" in front of each NPC.
These are definitely easier to use via the band GUI:
/band musician select ID
- Opens a GUI to edit the musicians for a band (ID) including name, assigned kit, and whether they can sit.
/band musician name NPCID NEWNAME
- Sets the name for a musician with id NPCID to NEWNAME
/band musician cansit NPCID
- Toggles the status of whether or not the musician with id NPCID can sit
/band musician remove NPCID
- Compltely removes this musician
/band musician selkit NPCID
- Opens a gui to select the kit for the musician with id NPCID
/band musician kitsel NPCID KITNAME
- Sets the kit variable for the musician with id NPCID to KITNAME, and also issues the kit to them.
/hire
= If already in hire mode for a band, spawn a new musician. Otherwise, do nothing...
/movem
= If already in move mode for a musician, move them to your current location.
/movem NPCID
= Start moving the musician with this ID
You will need to, using the Kits plugin, create kits that include the desired instrument. Do not include more than one held instrument in the tool belt of the kit.
Type /band new and then /band list. You should see a new BANDID number.
Type /song list and note the SONGID of the song you wish to have this band play.
Type /band BANDID song SONGID
Type /band BANDID gui
Click the "Hire" button at the upper right
Move to each positition where you want to spawn a musician and type /hire. A new basic player model should spawn there.
Type /band BANDID gui
Click the "Musicians" button at the lower right
For each musician, enter a new name (NO SPACES) if desired and press enter. Click each button below "Select Kit" to apply a kit to each musician. Finally, click the buttons below "Can Sit" for each musician you want to be able to sit. This last step is critical for piano, drums, and xylophone.
Once you have all your new NPCs in place, clothed, seated and/or holding instruments, close the Musicians menu.
REWORK IN PROGRESS - please use the GUI:
Hooks have been implemented to allow other plugins to interact with this one:
Start band playback. tstart for band must be set to true.
BandPlay(int bandnum)
Stop band playback. tstop for band must be set to true.
BandStop(int bandnum)
For the calls below, note that the plugin will keep track of created bands and musicians. You should not ever need to recreate or respawn bands or musicians separately. However, if you want to manage them yourself to ensure they do not reload when no longer needed, you must delete them yourself. Users of the plugin will also be able to see them, although this access typically should not be handed out to anyone other than a server admin.
Create a new band, optionally passing a bandid. Use numbers above 99 to avoid conflict with native bands.
private int CreateBand(int id = 0)
Remove/delete a band
private bool RemoveBand(int id)
Return or set band info (BandData class)
private object GetBandInfo(int bandid)
private void SetBandInfo(int bandid, object data)
public class BandData
{
public int id;
public string name;
public string song;
public bool autostart = false;
public bool repeat = false;
public bool npcTriggerStart = false;
public bool npcTriggerStop = false;
public int drumtrack;
public Dictionary<int, ulong> channels = new Dictionary<int, ulong>(32);
public Dictionary<int, string> description = new Dictionary<int, string>(32);
}
Return or set musician info (MusicianInfo class)
private object GetMusicianInfo(ulong npcid)
private void SetMusicianInfo(ulong npcid, object data)
public class MusicianInfo
{
public int band;
public string displayName;
public Vector3 position;
public Quaternion rotation;
public string kit;
public bool allowsit;
}
Spawn a musician object with given name at desired position and rotation for a band. Returns the NPC userID
private ulong SpawnMusician(string name, Vector3 position, Quaternion rot, int band, ulong olduserid=0)
Give a musician object an item in wear, belt, or main containers. If loc == "kit", pass a kit name for the Kits plugin.
private void GiveMusician(ulong musid, string itemname, string loc = "belt")
Check if a player object is a musician.
private bool IsMusician(BasePlayer player)
Kill a musician by passing its player object.
private void KillMusician(BasePlayer player)