how to activate the dynamic fuel prices on gas station signs

Discussion in 'Programming' started by Blood-PawWerewolf, Dec 18, 2023.

  1. Blood-PawWerewolf

    Blood-PawWerewolf
    Expand Collapse

    Joined:
    Jan 18, 2016
    Messages:
    713
    i heard that there was a feature with the gas stations that makes the signs have dynamic prices (it's not a static texture anymore). does anyone know where the scripts are so i could just play with it? just curious.
     
  2. 23Terrabytes

    23Terrabytes
    Expand Collapse

    Joined:
    Aug 1, 2022
    Messages:
    195
    C:\Steam\steamapps\common\BeamNG.drive\lua\ge\extensions\freeroam\facilities\fuelPrice.lua

    No idea if its actually implemented yet or how to go about it. From what I can tell its mostly place holder code. It uses names like "objName" instead of actual object names. And references using "quarter_mile_display" as part of the signage. But I am pretty sure the file above is whats going to be used for dynamic pricing.
     
    #2 23Terrabytes, Dec 18, 2023
    Last edited: Dec 18, 2023
  3. r3eckon

    r3eckon
    Expand Collapse

    Joined:
    Jun 15, 2013
    Messages:
    603
    They are implemented but only on west coast for now. I played around with the displays yesterday and this is what I've been using. Put the below code in a lua script in userfolder/lua/ge/extensions and give it some unique name like gasDisplayUtil.lua, the function calls will assume you're using that name so just change it up if you end up using a different name.

    Code:
    local M = {}
    
    local function getGasStationByID(id)
    local stations = extensions.freeroam_facilities.getFacilities("west_coast_usa").gasStations
    local toRet = {}
    for k,v in pairs(stations) do
    if v.id==id then toRet = v end
    end
    return toRet
    end
    
    local function setGasStationDisplayValue(id, fueltype, value, enabled, ustax)
    local station = getGasStationByID(id)
    station.prices[fueltype].priceBaseline = value
    station.prices[fueltype].priceRandomnessBias = nil
    station.prices[fueltype].priceRandomnessGain = nil
    station.prices[fueltype].disabled = not enabled
    station.prices[fueltype].us_9_10_tax = ustax
    if ustax then station.prices[fueltype].priceBaseline = value - 0.01 end --remove 1 cent from actual value for display in US maps
    end
    
    local function applyGasStationsDisplays()
    extensions.freeroam_facilities_fuelPrice.setDisplayPrices()
    end
    
    M.setGasStationDisplayValue = setGasStationDisplayValue
    M.applyGasStationsDisplays = applyGasStationsDisplays
    M.getGasStationByID = getGasStationByID
    
    return M
    
    First step is to figure out the station ids, you can print them in console with this line:
    Code:
    for k,v in pairs(extensions.freeroam_facilities.getFacilities("west_coast_usa").gasStations) do print(v.id) end


    Next step is to call this function from the script you added to the userfolder:
    Code:
    extensions.gasDisplayUtil.setGasStationDisplayValue("tyranos_island", "gasoline", 1.24,true,true)
    First parameter is the station id found from the above list, next is fuel type, next is fuel value, next is a true or false toggle for the value (replaces price with dashes when false), final parameter is true or false for the US 9/10 cent tax which should be true given this map is based in the US, otherwise the display will show 0/10.

    Fuel types are:
    • "gasoline" for Regular Unleaded
    • "gasoline2" for Mid-Grade Unleaded
    • "gasoline3" for Premium Unleaded
    • "diesel" for Diesel
    For my own use case I added a condition that will remove 1 cent from the value when the US tax is on, since afaik the 9/10 cents is basically rounded up to a cent when you pay for gas. This is for continuity with the prices shown in interactive menus from my mod, just keep this in mind if you want to show 1.23 send the value 1.24. If you want to remove this comment out the line that starts with "if ustax". I also set priceRandomnessBias and priceRandomnessGain to nil to disable the price randomness since my mod handles the random fuel price generation with daily seeded RNG. Like the last line you can comment these out so the randomness comes back, or even set these to different values to see how they affect the price. For this station by default the gain is 0.1 while the bias is 0.2. You can see these values (and all the data related to a particular fuel station) with:

    Code:
    dump(extensions.gasDisplayUtil.getGasStationByID("tyranos_island"))


    Anyway, to get values to show up on displays use this function:
    Code:
    extensions.gasDisplayUtil.applyGasStationsDisplays()
     
    • Like Like x 2
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice