Recommended Posts

I got a problem with created effects.

In normal dimension I created an effect that is attached to the player's vehicle. The problem is that players from other dimensions can see it too moving around. Any idea how I can restrict the effects only for dimension 0?

local attachedEffects = {}

function getPositionFromElementOffset(element,offX,offY,offZ)
	local m = getElementMatrix ( element )  -- Get the matrix
	local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform
	local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
	local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
	return x, y, z  -- Return the transformed point
end

function attachEffect(effect, element, pos)
	attachedEffects[effect] = { effect = effect, element = element, pos = pos }
	addEventHandler("onClientElementDestroy", effect, function() attachedEffects[effect] = nil end)
	addEventHandler("onClientElementDestroy", element, function() attachedEffects[effect] = nil end)
	return true
end

addEventHandler("onClientPreRender", root, 	
	function()
		for fx, info in pairs(attachedEffects) do
			local x, y, z = getPositionFromElementOffset(info.element, info.pos.x, info.pos.y, info.pos.z)
			setElementPosition(fx, x, y, z)
		end
	end
)

local fire = {}

function createCustomEffect(player, vehicle, value)
	if value then
	local x, y, z = getElementPosition(vehicle)
		if not fire[player] then
		fire[player] = createEffect("fire_bike", x, y, z, 0, 0, 0, 0, true)
		attachEffect(fire[player], vehicle, Vector3(0, 0, 0))
		setElementDimension(fire[player], 0)
		end
	else
		if fire[player] then
		attachedEffects[fire[player]] = nil
		destroyElement(fire[player])
		fire[player] = nil
		end
	end	
end
addEvent("triggerCustomEffect", true)
addEventHandler("triggerCustomEffect", root, createCustomEffect)

The event is triggered in server when a player enters a vehicle, motorcycle in this case. Attaching functions are taken from 'MTA Wiki > Suggested functions

function onPlayerVehicleEnter(vehicle, seat, jacked)
	if getElementModel(vehicle) == 463 then
		if seat == 0 then
		triggerClientEvent("triggerCustomEffect", source, source, vehicle, false)
		end		
	end
end
addEventHandler("onPlayerVehicleExit", root, onPlayerVehicleEnter)

 

Edited by Clipper_

Share this post


Link to post
13 hours ago, Gaborboy95 said:

Try


setElementDimension(fire[player], 0)

After creating it

Doesn't work.

I just want to see the effect in dimension 0, not all dimensions :(

Share this post


Link to post

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.