Jump to content

vehicle component manipulation


Xwad

Recommended Posts

Hmmm i'm wondering why does this not work. 

line 3: unexpected symbol near '

 

function rotate()
	for i,v in ipairs(getElementsByType("vehicle")) do
		local _,_,rh = getVehicleComponentRotation(v, "misc_a")                    
		setVehicleComponentRotation(v, "misc_a", _,_,rh+2)
	end
end
addEventHandler("onClientRender", root, rotate)

 

Link to comment
  • Moderators

@Xwad

You used or copied+past a special/invisible characters on line 3.

 

Fixed:

local _, _, rh = getVehicleComponentRotation(v, "misc_a")

 

 

Which is somehow located in here:

local _,_,rh = getVehicleComponentRotation(v, "misc_a")                    

 

 

And if we debug that:

local theString = "                    "
print(string.byte(theString,1,#theString))

 

32	239	187	191	239	187	191	32	239	187	191	239	187	191	32	239	187	191	32	32	32	32	32	32	32	32	32	32	32	32	32	239	187	191	239	187	191	32	32	32	32

Holy  ?? ?? ?? ?? ?? ?? !

 

 

Edited by IIYAMA
  • Haha 1
Link to comment
  • Moderators
7 minutes ago, Xwad said:

yeah but i get the value with getVehicleComponentRotation, so why is it not working?

 

It returns nil/false when:

  • Maybe the vehicle doesn't have that component? (for sure)
  • There is no vehicle. (for sure)
  • Or it might not be counted if it has fallen off. (maybe)
  • Or if the vehicle isn't streamed in. (maybe)
  • etc.

 

So take always in account that something can go wrong. Always validate the output.

 

In most cases this is enough: (especially when it is a MTA function)

if rh then
	
end

 

 

 

Edited by IIYAMA
Link to comment

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...