speedometer on passenger mod

Hello,
I got a darkrp server and i am working on a speedometer, during testing i notice that the speedoMeter is visible to the driver and also to the passengers, I want the speedoMeter to be visible only to the driver but i failed with so many tries, and here I am asking for help.

Thanks

Info : the script is fully client side.

You could use this http://wiki.garrysmod.com/page/Vehicle/GetDriver but it is server side, so i’m not sure if it would be much help as it sounds like you want it client side only?

Am painting the speedometer when the hook “HUDPaint” fires up and heres is the condition am using :

cl_speedo.lua:


hook.Add("HUDPaint","paintit",function()
	
        local ply = LocalPlayer()
	if ply:InVehicle() and ply:GetVehicle():GetClass() == "prop_vehicle_jeep" then
                 --Draw the speedo meter
        end
end)


As you said GetDriver() work only server side so i can’t use it here.
Thanks for help.

[editline]22nd June 2014[/editline]

I tested the code again and it works as it should be without making any modifications, I think that was happening because of some Lua errors i had on another script.
So as you can see verifying the vehicle class is the key to get the driver of the vehicle.
Sorry for the post.

For mine, I ensure player is valid, then if the hud element should be drawn, then I get the vehicle and make sure the vehicle is of proper type. It should work for you, even if you use a seat / passenger mod. GetVehicle should only return prop_vehicle_jeep or prop_vehicle_airboat for the driver, and vehicle_seat_jeep or something similar for passengers…

I do this for mine:

[lua]hook.Add(“HUDPaint”, “LuaHUDVehicleSpeedometer”, function( )
// Don’t continue if player isn’t valid
local _p = LocalPlayer( );
if ( !IsValid( _p ) ) then return; end

// Make sure the player isn't spectator, and that the hud should be drawn
local _shoulddraw = hook.Call( "HUDShouldDraw", GAMEMODE, "LuaHUDVehicleSpeedometer" );
if ( _p:Unassigned( ) || !_shoulddraw ) then return; end

// Get the vehicle and make sure it is valid; if invalid then not in vehicle. Make sure is driver.
local _v = _p:GetVehicle( );
if ( !IsValid( _v ) || ( _v:GetClass( ) != "prop_vehicle_jeep" && _v:GetClass( ) != "prop_vehicle_airboat" ) ) then return; end
local _r = 115;
local _buffer = 15;
DrawSpeedo( ScrW( ) - _r - _buffer, ScrH( ) - _r - _buffer, _r );

end );[/lua]