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

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

addEventHandler("onClientPreRender", root, 	
		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)

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)
		if fire[player] then
		attachedEffects[fire[player]] = nil
		fire[player] = nil
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)
addEventHandler("onPlayerVehicleExit", root, onPlayerVehicleEnter)


Edited by Clipper_

Share this post

Link to post
13 hours ago, Gaborboy95 said:


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.