Adding a device with included textures

table.insert(Sprites, DetailSprite("hud-detail-sandbags-large", "HUD-Details-SandBagsLarge", path)) table.insert(Sprites, ButtonSprite("hud-sandbags-large-icon", "HUD/HUD-SandbagsLarge", nil, ButtonSpriteBottom, nil, nil, path))

table.insert(Devices, IndexOfDevice("sandbags") + 1, { SaveName = "sandbags_large", FileName = path .. "/devices/sandbags_large.lua", Icon = "hud-sandbags-large-icon", Detail = "hud-detail-sandbags-large", Prerequisite = "upgrade", BuildTimeIntermediate = 0, BuildTimeComplete = 30, ScrapPeriod = 8, MetalCost = 20, EnergyCost = 800, MetalRepairCost = 20, EnergyRepairCost = 800, MetalReclaimMin = 0, MetalReclaimMax = 0, EnergyReclaimMin = 0, EnergyReclaimMax = 0, MaxUpAngle = StandardMaxUpAngle, BuildOnGroundOnly = false, SelectEffect = "ui/hud/devices/ui_devices", })

cannon20mm = FindProjectile("cannon20mm") if cannon20mm then table.insert(cannon20mm.DamageMultiplier, { SaveName = "sandbags_large", Direct = 0.2, Splash = 0.2 }) end

We created the Large Sandbags mod as a comprehensive example of how to add a new device to Forts. Once you are subscribed, navigate to your Steam library and then steamapps\workshop\content\410900\1293804859. This is an example of where a Workshop mod ends up after you upload it and someone subscribes to it. The original folder name is changed to a number, but everything else is the same. The change of location is why prefixing filenames with the path variable is so important - more below.The critical file in this mod is devices/device_list.lua. The first part of this script creates new sprites based on the included textures, found in ui/textures/HUD. The DetailSprite and ButtonSprite helper functions are defined in data/ui/uihelper.lua, and the Sprites table is read by the game to create any sprites defined by the configuration script. Thevariable is set by the game to the relative or absolute path of the mod (in the case of a subscribed mod), allowing it to reference new texture assets stored in the mod's directory. You don't need to understand exactly how this works, but if you keep your texture files in the same location and update the names it should work.Moving down a bit, you'll see where the new device is added to the Devices table.The IndexOfDevice function allows us to put the new device in a sensible position (after the original sandbag). The third parameter is the new item we're adding. We define the SaveName, the FileName which sets the detailed configuration of the device, the Icon and Detail HUD sprites, which we defined at the top, the prerequisite tech structure - the Upgrade Centre, and several other basic parameters (build time, cost and reclaim settings).You can open devices/sandbags_large.lua to see what detailed parameters are set. This is where you would make the device behave different to other devices. You can look at the devices included with the game and the weapon_pack mod to see what variables to change and what values would be appropriate. It's a good idea to play around with the values to see what feels good, rather than just using the first values that occur to you. Testing with friends helps to get feedback.In the middle of the file you'll see a new Sprites table, which sets the single-frame sprite of the sandbag to the included texture /devices/SandbagsLarge.tga. Note the use of the path variable again. The following forward slash is important as it's not included in the path variable.Further down you'll see the Root table, which configures how multiple sprites fit together to make a single device. This can be a complex set of nested tables for a weapon, as there are multiple parts and a pivot where the gun rotates. This structure specifies where projectiles and beams are emitted from by creating a "Hardpoint0" child node (with no Sprite value set). If you want to create a new weapon it's best to copy an existing one and experiment with Root until you understand how it works. The Angle, Pivot and PivotOffset values determine how child nodes are positioned relative to the parent. UserData is set to the percentage of construction at which the node will appear (or disappear on scrap).The other gameplay related change the Large Sandbags mod does is reduce the damage the 20mm cannon does to it. You'll find this in mods\weapon_pack\weapons\projectile_list.lua. This is a mod of a mod (or a nested mod). It's changing the way the weapon_pack works because the damage multiplier versus a device is associated with the projectile. It is set like this: