Jump to content

[Help] Attaching an effect


Noah_Antilles

Recommended Posts

Hello,

I've been trying to attach an effect to a vehicle, which in my understanding should work.

I'm getting this error:

ERROR: attempt to call global 'attachEffect' (a nil value)

function rustlerEngine()
    local vehicle = getPedOccupiedVehicle(localPlayer)
	local x, y, z = getElementPosition(vehicle)
	local rx, ry, rz = getElementRotation(vehicle)
	local engineSmoke = createEffect ( "smoke30m", x-3, y, z, rx, ry, rz )
    if(vehicle)then
        if getElementModel(vehicle) == 476 then
		    toggleControl ( "accelerate", false )
			toggleControl ( "brake_reverse", false )
			attachEffect(engineSmoke, vehicle)
	        setEffectSpeed(engineSmoke, 10)
            outputChatBox ("simulating loss of engine", 0, 190, 255)
		end
	end	
end
bindKey("0", "down", rustlerEngine)

What am I missing?

Link to comment
  • Moderators

At the same link: https://wiki.multitheftauto.com/wiki/AttachEffect

 

Which contains this:

local attachedEffects = {}

-- Taken from https://wiki.multitheftauto.com/wiki/GetElementMatrix example
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
)

By Sbx320

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