knightscript Posted June 8, 2017 Share Posted June 8, 2017 Hello, I am trying to make an elevator script using an createObject, moveObject and attachElements to attach a vehicle to the object, the problem is, the vehicle goes through the object even if I add an Z offset, this is my code: local elevatorcolshape = createColRectangle ( 1666, 1188, 30.6, 20.0 ) local elevator = createObject(3115, 1676.9, 1197.8, 24.2) local elevatorSTATE = "techo" function elevator1337(source,command,goto ) local playeraccount = getPlayerAccount( source ) local accname = getAccountName( playeraccount ) local playerx,playery,playerz = getElementPosition( source ) local elevatorx,elevatory,elevatorz = getElementPosition(elevator) if (accname == "knight") then if (goto) then if (goto == "piso") then if (elevatorSTATE ~= "piso") then if (isElementWithinColShape(source, elevatorcolshape ) and playerz < 20) then outputChatBox( "[BASE 1337]: NO PUEDES LLAMAR EL ELEVADOR PORQUE TE VA A APLASTAR",source,255,0,0,true ) else local isinveh = isPedInVehicle( source ) if (isinveh) then attachElements(getPedOccupiedVehicle(source),elevator) end elevatorSTATE = "piso" outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true ) moveObject( elevator, 1000, 1676.9, 1197.8, 18.2) setTimer(moveObject, 1250, 1, elevator, 1000, 1685.9, 1197.8, 18.2) setTimer(moveObject, 2500, 1, elevator, 1000, 1685.9, 1197.8, 9.7) if (isinveh) then setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator) end end else outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true ) end end if (goto == "techo") then if (elevatorSTATE ~= goto) then local isinveh = isPedInVehicle( source ) if (isinveh) then attachElements(getPedOccupiedVehicle(source),elevator,0,0,3) end elevatorSTATE = goto outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true ) moveObject( elevator, 500, 1685.9, 1197.8, 18.2) setTimer(moveObject, 750, 1, elevator, 500, 1676.9, 1197.8, 18.2) setTimer(moveObject, 1500, 1, elevator, 500, 1676.9, 1197.8, 24.2) if (isinveh) then setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator) end else outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true ) end end end end end addCommandHandler("elev", elevator1337 ) I would like to know if there is a way to avoid the car going through the item and fall, thanks Link to comment
idarrr Posted June 8, 2017 Share Posted June 8, 2017 Maybe use setElementCollisionsEnabled to disable physical interaction between vehicle and an object. Link to comment
Hale Posted June 8, 2017 Share Posted June 8, 2017 Try using setElementFrozen instead of attaching the vehicle and object, and a short setTimer for ~500ms. Link to comment
knightscript Posted June 9, 2017 Author Share Posted June 9, 2017 19 hours ago, Hale said: Try using setElementFrozen instead of attaching the vehicle and object, and a short setTimer for ~500ms. Hello, sorry for late reply, just tried using setElementFrozen, and it just freezes the vehicle and the elevator object goes through the car and goes up 20 hours ago, idarrr said: Maybe use setElementCollisionsEnabled to disable physical interaction between vehicle and an object. Hello, sorry for late reply, tried this yesterday and the problem persists Hello, I fixed it in a funny way, what I did is add a second elevator object, and made its alpha 0 (invisible) and attached it to the original elevator, it works now, I´ll leave the code for whoever needs it local elevatorcolshape = createColRectangle ( 1666, 1188, 30.6, 20.0 ) local elevator = createObject(3115, 1676.9, 1197.8, 24.2) local elevatorclone = createObject(3115, 1676.9, 1197.8, 24.2) attachElements(elevatorclone,elevator ) setElementAlpha(elevatorclone, 0 ) local elevatorSTATE = "techo" function elevator1337(source,command,goto ) local playeraccount = getPlayerAccount( source ) local accname = getAccountName( playeraccount ) local playerx,playery,playerz = getElementPosition( source ) local elevatorx,elevatory,elevatorz = getElementPosition(elevator) local distance = getDistanceBetweenPoints3D(playerx, playery, playerz, elevatorx,elevatory,elevatorz ) if (accname == "knight") then if (goto) then if getPedOccupiedVehicle ( source ) then outputDebugString( distance ) -- get the vehicle element local playerVehicle = getPlayerOccupiedVehicle ( source ) attachElements(playerVehicle, elevator,0,0,1) -- get the current freeze status setElementFrozen ( playerVehicle, true ) setTimer(setElementFrozen, 1950, 1, playerVehicle,false ) setTimer(detachElements, 1950, 1, playerVehicle,elevator ) end if (goto == "piso") then if (elevatorSTATE ~= "piso") then if (isElementWithinColShape(source, elevatorcolshape ) and playerz < 20) then outputChatBox( "[BASE 1337]: NO PUEDES LLAMAR EL ELEVADOR PORQUE TE VA A APLASTAR",source,255,0,0,true ) else -- local isinveh = isPedInVehicle( source ) -- if (isinveh) then -- attachElements(getPedOccupiedVehicle(source),elevator,0,0,15) -- end elevatorSTATE = "piso" outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true ) moveObject( elevator, 500, 1676.9, 1197.8, 18.2) setTimer(moveObject, 750, 1, elevator, 500, 1685.9, 1197.8, 18.2) setTimer(moveObject, 1500, 1, elevator, 500, 1685.9, 1197.8, 9.7) -- if (isinveh) then -- setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator) -- end end else outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true ) end end if (goto == "techo") then if (elevatorSTATE ~= goto) then -- local isinveh = isPedInVehicle( source ) -- if (isinveh) then -- attachElements(getPedOccupiedVehicle(source),elevator,0,0,15) -- end elevatorSTATE = goto outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true ) moveObject( elevator, 500, 1685.9, 1197.8, 18.2) setTimer(moveObject, 750, 1, elevator, 500, 1676.9, 1197.8, 18.2) setTimer(moveObject, 1500, 1, elevator, 500, 1676.9, 1197.8, 24.2) -- if (isinveh) then -- setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator) -- end else outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true ) end end end end end addCommandHandler("elev", elevator1337 ) Thanks for the help guys 1 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