Sign in to follow this  
jeanclau

Speedmeter?

Recommended Posts

okay but i need a function which repeats very fast for speedometer e.g. so this is not a performance issue then? because it would loop the getspeed and browser.execute in a very fast way? thanks so far for your feedback :)

Share this post


Link to post
Share on other sites

Mmmh when is use this function on client side:

function getSpeed() {
	if(mp.players.local.isInAnyVehicle(true)) {
		let vehicle_velocity = mp.players.local.vehicle.getVelocity();
		let vehicle_speed = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y + velocity.z * velocity.z);
		let vehicle_speed_converter = velocity_length * 3.6;
		return vehicle_speed_converter;
	}
}

And this snippet to put speed in CEF div container of my overlay:

setInterval(function(){
    var CurrentSpeed = getSpeed();
    browser.execute('document.getElementById(\'speed\').innerHTML = \'<b>' + CurrentSpeed + '</b>\';'); 
}, 3000);

The game crashes immediately after i join.... What's wrong with that?

 

Share this post


Link to post
Share on other sites
function showSpeed() {
    const player = mp.players.local;
    if (player.isSittingInAnyVehicle(true)) {
        let velocity = player.vehicle.getVelocity();
        let speed = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y + velocity.z * velocity.z);
        speed = Math.round(speed)
          mp.game.graphics.drawText(`Speed: ${speed}`, [0.825, 0.875], {  
            font: 6, 
            color: [255, 255, 255, 255], 
            scale: [0.9, 0.9], 
            outline: true
        });
    }
}

mp.events.add('render', () => {
    showSpeed();
});

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for that @TH3RM4L but i am looking for a solution to display the vars in cef browser in realtime. Because i also did a Menu in cef browser which should be filled (player inventory and such).

Also i can't get 

mp.game.graphics.drawText

working to justify the text on left side. Only middle seems to work for me. Param "justify" does not exist or is ignored.

 

Regards

Share this post


Link to post
Share on other sites

Just use render event which is called every frame and check if the player is in the car and get its speed. Take a look on my example native speedo resource

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   1 member