Jump to content

Can some one please explain (triggerClientEvent)


Recommended Posts

Can some one please explain to me what's wrong with this, I've tried triggering it with both getRootElement() as well as without it, the trigger needs to be sent to everyone.

Currently, it only sends the trigger to the player in the seat, it's not sending it globally to every player, however, the trigger at the very top is being sent to everyone... I've tried everything so far, and it's not being triggered globally for every player, only the guy in the seat itself. I know I can make it as easy as lowering all windows once it's being triggered but I only want the window for the occupied seat to be lowered.

Anyone have any clue? I'm completely lost and I have no clue how to solve it, I took a break from MTA for 6 months, I came back and if I had 50 bugs before on my server, it now has 500 bugs it's like LUA or what ever got a big stroke, nothing works anymore. I went over everything, double checked wiki and everything seems to be fine but yet it's not being triggered globally.

 

Line: 19 is the issue, line 12 is working perfectly

function toggleWindow(thePlayer)
	if not thePlayer then
		thePlayer = source
	end
	
	local theVehicle = getPedOccupiedVehicle(thePlayer)
	if theVehicle then
		if hasVehicleWindows(theVehicle) then
			if (getVehicleOccupant(theVehicle) == thePlayer) or (getVehicleOccupant(theVehicle, 1) == thePlayer) then
				if not (isVehicleWindowUp(theVehicle)) then
					for i = 0, getVehicleMaxPassengers(theVehicle) do
						triggerClientEvent(getRootElement(), "vehicle:syncWindows", thePlayer, theVehicle, i, false)
						setElementData(theVehicle, "vehicle:window_"..tostring(i), false, true)
					end
				else
					for i = 0, getVehicleMaxPassengers(theVehicle) do
						local player = getVehicleOccupant(theVehicle, i)
						if (player) then
							triggerClientEvent(getRootElement(), "vehicle:syncWindows", player, theVehicle, i, true)
							setElementData(theVehicle, "vehicle:window_"..tostring(i), true, true)
						end
					end
				end
			end
		end
	end
end
addEvent("vehicle:togWindow", true)
addEventHandler("vehicle:togWindow", root, toggleWindow)
addCommandHandler("togwindow", toggleWindow)

 

Clientside Function

local seatWindows = {[0] = 4, [1] = 2, [2] = 5, [3] = 3}

function syncWindows(theVehicle, seat, state)
	outputDebugString("SEAT "..tostring(seat))
	setVehicleWindowOpen( theVehicle, seatWindows[seat], state )
end
addEvent("vehicle:syncWindows", true)
addEventHandler("vehicle:syncWindows", localPlayer, syncWindows)

 

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