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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.