I’d like to introduce a “capacitor” vehicle part in my mod, which is essentially just a “leaky” battery even at 100% condition which won’t leak while being charged, but I can’t see any means of accessing items at runtime.
Is it possible to iterate through vehicles or vehicle parts at runtime using Lua? In the end I probably don’t even need any bindings to vehicles’ parts directly, provided the frames, vehicle parts, etc. are tracked as “items” in the world, but I haven’t seen any mod example of a .lua iterator that scans through nearby objects at runtime, nor have I seen any poll/heartbeat-based (rather than event-based, i.e., “iuse”) Lua scripts. Almost all examples of Lua scripting I’ve seen generally revolve around simply modifying the creature templates once in their main.lua.
If I were to define a loop in a .lua script and then poll the game timer to see if the game time has changed, would that be the means by which I could do this, or is Lua given full control over the game loop without pausing (i.e., will freeze game due to infinite loop)?
The pseudocode is the barest-bones:
define leaky_item_id_list: { “classname”, “classname2”, … }
every X in-game ticks:
foreach item in bubble
if item.id is in leaky_item_id_list
if item.ammo_capacity > 0 and item.ammo_current > 0
item.ammo_current = item.ammo_current - 1