DjSt3rios Posted June 22, 2011 Share Posted June 22, 2011 Hello, I have a problem with a script im working on. I have this code: addEventHandler("onVehicleEnter", getRootElement(), function(thePlayer, seat, jacked) local currentElement = createObject(360, 0.0, 0.0, 0.0) attachElements(currentElement, source, 0.0, 1.8, 0.0, 0.0, 0.0, 90.0) end) so it attach the element to the player(or to the vehicle, not 100% sure) Anyway, and i tried this: function removeobject ( thePlayer, seat, jacked ) occupiedVehicle = getPedOccupiedVehicle( thePlayer ) local attached = getElementAttachedTo ( thePlayer ) destroyElement ( attached ) end addEventHandler ( "onVehicleExit", getRootElement(), removeobject ) addEventHandler ("onVehicleExplode", getRootElement(), removeobject) Server side both of them, but it does not delete the element that it is attached, as you saw in the first function. I also tried to use where it says local attached = getElementAttachedTo ( thePlayer ) make it local attached = getElementAttachedTo ( occupiedVehicle ) but still it is not working. Maybe any idea how to fix it? Thanks. Link to comment
Castillo Posted June 22, 2011 Share Posted June 22, 2011 addEventHandler("onVehicleEnter", getRootElement(), function(thePlayer, seat, jacked) currentElement = createObject(360, 0.0, 0.0, 0.0) attachElements(currentElement, source, 0.0, 1.8, 0.0, 0.0, 0.0, 90.0) end) function removeobject ( thePlayer, seat, jacked ) occupiedVehicle = getPedOccupiedVehicle( thePlayer ) local attached = getElementAttachedTo ( source ) destroyElement ( attached ) end addEventHandler ( "onVehicleExit", getRootElement(), removeobject ) addEventHandler ("onVehicleExplode", getRootElement(), removeobject) Try that? the source of onVehicleEnter is the vehicle the player just entered. Link to comment
Castillo Posted June 22, 2011 Share Posted June 22, 2011 addEventHandler("onVehicleEnter", getRootElement(), function(thePlayer, seat, jacked) currentElement = createObject(360, 0.0, 0.0, 0.0) attachElements(currentElement, source, 0.0, 1.8, 0.0, 0.0, 0.0, 90.0) end) function removeobject ( thePlayer, seat, jacked ) local attached = getAttachedElements (source) if (attached) then for i,element in ipairs(attached) do if getElementType (element) ~= "object" then return end destroyElement(element) end end end addEventHandler ( "onVehicleExit", getRootElement(), removeobject ) addEventHandler ("onVehicleExplode", getRootElement(), removeobject) Works ( tested ). Link to comment
DjSt3rios Posted June 22, 2011 Author Share Posted June 22, 2011 Yeah now it works, Thanks 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