[EN] Speed - JuniorDjjr/VehFuncs GitHub Wiki

For programmers.


Read realistic vehicle speed

VehFuncs realistically calculates vehicle speed (as explained here). If you wish to read this speed value to use in your cleo mod etc (eg some speedometer mod on the screen), here it is:

Sanny Builder:

{$cleo}

const
    pVehFuncs = 0@
    pGetVehicleSpeedRealistic = 1@
    
    hVeh = 10@
    pVeh = 11@
    fSpeed = 12@
end

if 0AA2: pVehFuncs = load_library "VehFuncs.asi"
then
    if 0AA4: pGetVehicleSpeedRealistic = get_proc_address "Ext_GetVehicleSpeedRealistic" library pVehFuncs
    then
        0AA3: free_library pVehFuncs
    else
        0AA3: free_library pVehFuncs
        0ACD: show_text_highpriority "~r~Fail to load 'VehFuncs.asi'. Update it." time 5000
        0A93: end_custom_thread
    end
else
    0ACD: show_text_highpriority "~r~'VehFuncs.asi' was not found." time 5000
    0A93: end_custom_thread
end

while true
    wait 0
    if 00DF:   actor $player_actor driving
    then
        hVeh = actor.CurrentCar($player_actor)
        0A97: pVeh = car hVeh struct
        0AA7: call_function_return pGetVehicleSpeedRealistic num_params 1 pop 1 pVeh -> fSpeed
        0AD1: show_formatted_text_highpriority "Speed: ~y~%.3f" time 2000 fSpeed
    end
end