diff options
Diffstat (limited to 'advtrains/trainhud.lua')
-rw-r--r-- | advtrains/trainhud.lua | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index b2744ad..f9f4876 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -103,18 +103,20 @@ function advtrains.set_trainhud(name, text, driver) if not player then return end + local drivertext = driver or "" local driverhud = { hud_elem_type = "image", name = "ADVTRAINS_DRIVER", position = {x=0.5, y=1}, offset = {x=0,y=-170}, - text = driver or "", + text = drivertext, alignment = {x=0,y=-1}, - scale = {x=1,y=1},} + scale = {x=1,y=1}, + } if not hud then - hud = {["driver"]={}} + hud = {} advtrains.hud[name] = hud - hud.id = player:hud_add({ + hud.id = player:hud_add { hud_elem_type = "text", name = "ADVTRAINS", number = 0xFFFFFF, @@ -123,18 +125,23 @@ function advtrains.set_trainhud(name, text, driver) text = text, scale = {x=200, y=60}, alignment = {x=0, y=-1}, - }) - hud.oldText=text + } hud.driver = player:hud_add(driverhud) + hud.oldText = text + hud.oldDriver = drivertext else if hud.oldText ~= text then player:hud_change(hud.id, "text", text) hud.oldText=text end if hud.driver then - player:hud_change(hud.driver, "text", driver or "") + if hud.oldDriver ~= drivertext then + player:hud_change(hud.driver, "text", drivertext) + hud.oldDriver = drivertext + end elseif driver then hud.driver = player:hud_add(driverhud) + hud.oldDriver = drivertext end end end |