Starbound

Starbound

Vanilla Mechs Energy
 This topic has been pinned, so it's probably important
lophatkao  [developer] 17 Aug, 2016 @ 11:53pm
readme - energy.txt
hi there, welcome to the readme for the vanilla mechs energy patch example
if you're reading this, yay! you obviously want to add energy use to your vehicle :D

until CF adds a way for vehicles to use energy directly, this workaround is probably going to be it
i hope they do :D even tho that would render this obsolete

required:
text editor of choice
a working vehicle ;)
a brain :D

procedure:
-- follow directions closely - don't edit stuff you don't need to! it'll break your vehicle!

part 1 : copy/rename the status effect
copy the /stats folder to your vehicle mod directory --> /mods/<yourmodname>/stats
open /stats/effects/vmech_energyuse/vmech_energyuse.statuseffect in text editor
change "name" from "vmech_energyuse" to '<uniquename>_energyuse'
save and close the .statuseffect file -- Remember what you changed "name" to! need for part 2
rename 'vmech_energyuse.statuseffect' to '<uniquename>_energyuse.statuseffect'
go back to /stats/effects/, rename 'vmech_energyuse' folder to '<uniquename>_energyuse'
done part 1!

part 2 : adding status effect to .vehicle file
open your /vehicles/<path_to_vehicle>/<vehiclename>.vehicle' file
find the section "loungePositions"
take note of the seatname that needs to use energy - ie: "seat" - you will need it for part 3!
if there is not a 'statusEffects' section in the seat, you need to create it - WATCH YOUR COMMAS
-- "statusEffects" : ["<uniquename>_energyuse"]
or just add it to list that exists
done part 2!

part 3 : editing the <vehicle>.lua (the 'worst' part - ohnoes!)
- all relevant sections can be found by searching for 'vmech_energyuse' in supplied mech.lua
- unarmored players only have 100 energy - choose your usage numbers carefully

----init()
copy/paste the energy use section - 2 variables and 2 functions
rename "seat" where indicated with seatname from part 2, add more seats if needed

----update()
required: self.energyToUse[<seatname>] initialize line(s) near beginning, before controlHeld checks
required: the k,v pairs loop at end of update, to use energy for each seat that used energy this frame

check for ""self.energyLocked[<seatname>] and vehicle.controlHeld(<seatname>,~~)"" to block actions when player is out of energy
to set energy use; self.energyToUse[<seatname>] = self.energyToUse[<seatname>] + n , where n = amount of energy to use