Jump to content

My clientscript doesn't work very well (onclientvehicleenter) :(


Andres99907

Recommended Posts

I'm using this script to make Thruster fly, only the Player who uses the Thruster will fly, but if other player enters to other Thruster, the script executes one more time the function and the Player in the First Thruster stop flying (because the function is executed again by the other player) I don't know how to make this script not affect the other players :(

 

here is a video.

 

Video

 

and this the part of the script wich has the Problem:

 

addEventHandler("onClientVehicleEnter", getRootElement(),
function()
	if (isPedInVehicle(localPlayer) and Cars[getElementModel(getPedOccupiedVehicle(localPlayer))]) then
		if isWorldSpecialPropertyEnabled("aircars") then
			setWorldSpecialPropertyEnabled ( "aircars", false )
			setWorldSpecialPropertyEnabled ( "hovercars", false )
			setAircraftMaxVelocity( 2.3 )
			setWorldSoundEnabled ( 11, true, true)
			setWorldSoundEnabled ( 7, true, true)
			setWorldSoundEnabled ( 8, true, true)
			setWorldSoundEnabled ( 9, true, true)
			setWorldSoundEnabled ( 10, true, true)
			setWorldSoundEnabled ( 12, true, true)
			setWorldSoundEnabled ( 13, true, true)	
			setWorldSoundEnabled ( 14, true, true)
			setWorldSoundEnabled ( 15, true, true)
			setWorldSoundEnabled ( 16, true, true)			
			setWorldSoundEnabled ( 40, true, true)
			playSound("ThrusterOff.wav")
			setSoundVolume(sound, 0.3)
			if isFlying then
				removeEventHandler("onClientRender", root, checkFlight)
			end
			isFlying = false
		else
			setWorldSpecialPropertyEnabled ( "aircars", true )
			setWorldSpecialPropertyEnabled ( "hovercars", true )
			triggerServerEvent ( "onjetpack", resourceRoot)
			setWorldSoundEnabled ( 11, false, true)
			setWorldSoundEnabled ( 7, false, true)
			setWorldSoundEnabled ( 8, false, true)
			setWorldSoundEnabled ( 9, false, true)
			setWorldSoundEnabled ( 10, false, true)
			setWorldSoundEnabled ( 12, false, true)
			setWorldSoundEnabled ( 13, false, true)	
			setWorldSoundEnabled ( 14, false, true)
			setWorldSoundEnabled ( 15, false, true)
			setWorldSoundEnabled ( 16, false, true)	
			setWorldSoundEnabled ( 40, false, true)
			playSound("ThrusterOn.wav")
			setAircraftMaxVelocity( 1)
			setSoundVolume(sound, 0.9)
			if not isFlying then
				addEventHandler("onClientRender", root, checkFlight)
			end
			isFlying = true
		end
	end
end)
	
function checkFlight()
	if (not isPedInVehicle(localPlayer)) or (not Cars[getElementModel(getPedOccupiedVehicle(localPlayer))]) or isPlayerDead(localPlayer) then
		setWorldSpecialPropertyEnabled ( "aircars", false )
		setWorldSpecialPropertyEnabled ( "hovercars", false )
		setAircraftMaxVelocity( 2.3 )
		setWorldSoundEnabled ( 11, true, true)
		setWorldSoundEnabled ( 7, true, true)
		setWorldSoundEnabled ( 8, true, true)
		setWorldSoundEnabled ( 9, true, true)
		setWorldSoundEnabled ( 10, true, true)
		setWorldSoundEnabled ( 12, true, true)
		setWorldSoundEnabled ( 13, true, true)	
		setWorldSoundEnabled ( 14, true, true)
		setWorldSoundEnabled ( 15, true, true)
		setWorldSoundEnabled ( 16, true, true)	
		setWorldSoundEnabled ( 40, true, true)
		playSound("ThrusterOff.wav")
		setAircraftMaxVelocity( 2.3 )
		setSoundVolume(sound, 0.3)
		if isFlying then
			removeEventHandler("onClientRender", root, checkFlight)
		end
		isFlying = false
	end
end

local ms = 1000

 

 

Link to comment
  • Moderators
3 hours ago, Andres99907 said:

 I don't know how to make this script not affect the other players

 

That would be a little bit hard, since the effect is applied globally, so there will always be a little bit desync.

 

 


 

But you can make sure the code doesn't do anything when other players are entering vehicles:

 

addEventHandler("onClientVehicleEnter", getRootElement(),
function(thePlayer)
	if thePlayer ~= localPlayer then
		return
	end
	

 

 

Note: Even if the "onClientVehicleEnter" event is clientside, it does still trigger for remote players.

  • Like 1
  • Thanks 1
Link to comment
On 10/09/2020 at 17:37, IIYAMA said:

 

That would be a little bit hard, since the effect is applied globally, so there will always be a little bit desync.

 

 


 

But you can make sure the code doesn't do anything when other players are entering vehicles:

 


addEventHandler("onClientVehicleEnter", getRootElement(),
function(thePlayer)
	if thePlayer ~= localPlayer then
		return
	end
	

 

 

Note: Even if the "onClientVehicleEnter" event is clientside, it does still trigger for remote players.

You helped me a loot bro : D thank you

  • Like 1
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...