Noah_Antilles Posted September 7, 2017 Share Posted September 7, 2017 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 IIYAMA Posted September 7, 2017 Moderators Share Posted September 7, 2017 (edited) The code of the function. It is not a MTA function, but a custom one. https://wiki.multitheftauto.com/wiki/AttachEffect Edited September 7, 2017 by IIYAMA 1 Link to comment
Noah_Antilles Posted September 7, 2017 Author Share Posted September 7, 2017 Thanks for your reply, I had no idea this was a custom function. To bother you once more; where can I download this custom function? Link to comment
Moderators IIYAMA Posted September 7, 2017 Moderators Share Posted September 7, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now