Custom items
A plugin can make new items out of the game’s own with DefineItem, in OnLoaded:
var m4 = ItemDatabase.Find( "M4" );var golden = new PluginItem { Id = "legendary_golden_m4", Base = "M4", Title = "Golden M4", Description = "Hits harder." };golden.Stats["Damage"] = m4.Damage * 1.25f;DefineItem( golden );Give( player, "Golden M4" );PluginItem |
|
|---|---|
Id |
Unique and stable: it is what the world save keeps. Prefix it with your plugin’s name |
Base |
The game item it is made from. It keeps that item’s model, sounds and rules: ammo, crafting, durability, building |
Title, Description |
What players see |
Icon |
An image address (see Images) or another item’s name to borrow its icon; empty: the base’s |
Tint |
Its color, "#rrggbb": on its icon, as a frame around it in the inventory, on its name, and on its model in hand. Give every custom item one, so players can tell it from its base at a glance |
PaintModel |
true: its model in hand is painted all in Tint (a golden gun) instead of only tinted, since a tint barely shows on a dark weapon |
Texture |
A skin: an image address (see Images) that replaces its model’s texture in first person. Several addresses separated by spaces make an animated skin. See Skins below. Wins over PaintModel |
WorldTexture |
The same for the model the other players see in its hand, which has its own texture. Empty: the others see the base’s |
TextureFps |
Frames per second of an animated skin, 8 by default |
Stats |
Values changed, by name: Damage, DamageMin, Spread, FireRate, ClipSize, MaxStack, ReloadTime, Range, MaxUses, MaxHealth… any number of the item’s definition |
Model |
Objects you place only: its model once placed, a model package of the s&box cloud (see Models and sounds from the s&box cloud) or a model path of the game; empty: the base’s. Not for doors and window bars, whose frame fits the base’s model. Its collision is the model’s bounding box. While placing, the ghost and the room checks are the base’s: pick a base about the model’s size |
UseLabel |
Objects you place only: an action in the use menu (E), "Open shop". Choosing it calls OnDeployableUse |
Give( player, "Golden M4" ) gives it by its title or its id, and IsItem( stack, "legendary_golden_m4" ) tells if a
stack is one. A custom item never stacks with its base, but it counts as its base wherever the game counts items: a
custom ammo is fired like the plain ammo, a custom wood burns and builds like wood. If its plugin is removed, the item
stays where it is as its base, and comes back when the plugin does.
New objects and building pieces. A custom item made from something you place stays itself once placed, and in the
world save: its tint shows on it, its Stats apply (a MaxHealth of 5000 makes a sturdier wall), PlacedItem and
IsItem recognise it. A placed object can also get its own Model and an action (UseLabel), which makes a new
object out of a box, a stash or a furnace: it keeps its base’s rules (storage, fuel, health, protection against
raids), and your plugin adds the behaviour:
DefineItem( new PluginItem { Id = "shop_terminal", Base = "Wood Storage Box", Title = "Shop", Tint = "#ffcc00", Model = "facepunch.present_box", UseLabel = "Open shop" } );
public override void OnDeployableUse( RustPlayer player, GameObject deployable ){ if ( IsItem( deployable, "shop_terminal" ) ) ShowMenu( player, ShopMenu() );}Building pieces (walls, foundations…) keep the base’s shape, since the building grid fits it: a custom piece changes its tint, its name and its values, not its model. Plugins cannot add a new weapon behaviour.
Skins. A weapon or a tool in hand can wear your own picture. Each model wraps its texture by a fixed layout, so a
skin is a repaint of the base’s texture, not any picture: the
skins folder has the texture of every item you can
hold, two per item, first person (Texture) and the model the others see (WorldTexture).
- Download the two textures of your base item and paint over them, keeping their size and where things are.
- Upload both to Imgur or GitHub (see Images). Avoid Discord for skins: its image links expire.
- Put the addresses in your item:
DefineItem( new PluginItem { Id = "myplugin_neon_m4", Base = "M4", Title = "Neon M4", Tint = "#ff40ff", Texture = "https://i.imgur.com/AbCd123.png", WorldTexture = "https://i.imgur.com/EfGh456.png" } );An animated skin lists its frames, in order, separated by spaces, and TextureFps sets its speed. It plays in a
loop, the same on every model. A frame can come back in the list: it is downloaded once.
A GIF does not work as a skin by itself (it stays on its first frame on a weapon): split it into frames first (ezgif.com’s Split tool does it), keep 16 at most, and upload them as PNG or JPG. A long GIF does not fit in 16 frames: keep a short stretch of it and play it back and forth, there is no jump at the loop. A pattern that has no shape of its own (liquid, fire, lightning, a galaxy) looks good without following the model’s layout, and the same frames then fit both models. This liquid metal M4 is 9 frames out of the first 1.3 seconds of a GIF, 512 × 512, played 1 → 9 → 2:
var dir = "https://raw.githubusercontent.com/rustlegacyio/rustlegacy-plugins/main/skins/examples/liquid_metal/";var frames = "";foreach ( var n in new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2 } ) frames += dir + "0" + n + ".jpg ";DefineItem( new PluginItem { Id = "myplugin_liquid_m4", Base = "M4", Title = "Liquid Metal M4", Tint = "#c8ccd4", Texture = frames, WorldTexture = frames, TextureFps = 6 } );Limits, checked by every player’s game: one image is 4096 pixels on a side and 8 megapixels at most (the biggest template, the Bolt Action Rifle’s, is 4096 × 2048). An animation has 16 frames at most and 4 megapixels in all (16 frames of 512 × 512, or 4 of 1024 × 1024), since every player keeps all of them in memory: a frame smaller than the template works, it is only less sharp. Players download the images the first time they see the item and see the plain item until then. If an image fails to load or breaks a limit, the item keeps its base’s look and the game’s console says why (on your own game: test with 3. Test on your own computer). The skin covers the weapon itself: the arms, the hands, and small separate parts (a flare’s cap, a pipe shotgun’s shell) keep their texture.