Jump to content

[client-side] Label and label.attachTo(entity, ...)


Recommended Posts

Posted
mp.events.add({
	'entityStreamIn': (entity) => {
		if (entity.type !== 'vehicle') return; // Not a vehicle
		//create a basic label
		let label = mp.labels.new('my text here', entity.position,
            {
                los: false,
                font: 1,
                drawDistance: 100,
            }
        );
      	//trying to attach label to vehicle
		//i traied to delete this line to check if mp.labesl.new is the problem but everything that happens above is ok
		label.attachTo(entity, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 2, true);
	},
	'entityStreamOut': (entity) => {
		mp.events.callRemote('server:responseStream', (entity));
		if (entity.type !== 'vehicle') return; // Not a vehicle
		//rest of code where label need to be deleted and other stuff..
	}
});

I'm trying to attach a label to a vehicle in 'entityStreamIn' and delete it in 'entityStreamOut'. Everything goes well but when I add the line to attach the vehicle label I get the error 'label.attachTo(entity, .....) is not a function' I understood that this function is used for the 'camera' but I looked for another function for attaching a text label to the car and I can't find it.

Posted (edited)

Labels are not really world entities. They don't have script handles, and so you cannot use EntityMp.attachTo. Maybe constantly setting position could work, but that seems impractical.

You're better off using mp.game.graphics.world3dToScreen2d to get the position of the vehicle or the position of a bone on the vehicle, and then draw your text using mp.game.graphics.drawText each frame using the render event.

Edited by Nutter

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...