local angle = {} local new_angle = {} local startx = {} local starty = {} local startz = {} local temp = {} local delay = {} pressed = 0 function door_manual_init(e) angle[e] = nil temp[e] = -1 end function door_manual_main(e) if angle[e] == nil then delay[e] = GetTimer(e) + 1100 startx[e] = g_Entity[e]['x'] starty[e] = g_Entity[e]['y'] startz[e] = g_Entity[e]['z'] angle[e] = -1 elseif angle[e] == -1 then if GetTimer(e) < delay[e] then CollisionOff(e) MoveForward(e,50) else angle[e] = RotateToPoint(e,startx[e],startz[e]) angle[e] = angle[e] + 180 SetRotation(e,0,angle[e],0) SetPosition(e,startx[e],starty[e],startz[e]) CollisionOn(e) end else if GetPlayerDistance(e) < 150 then if g_Entity[e]['activated'] == 0 then Prompt("E to open door!") if GetScancode() == 18 and pressed == 0 then PlaySound(e, 0) pressed = 1 SetActivated(e,1) temp[e] = 0 PlaySound(e, 0) end elseif g_Entity[e]['activated'] == 2 then Prompt("E to close door!") if GetScancode() == 18 and pressed == 0 then PlaySound(e, 1) pressed = 1 SetActivated(e,3) temp[e] = 0 end end end if temp[e] >= 0 then if g_Entity[e]['activated'] == 1 then if temp[e] < 90 then temp[e] = temp[e] + 0.5 --adjusts speed of rotation (remember to change the 2nd below) new_angle[e] = angle[e] - temp[e] --change to - (minus) if you want it to rotate the other way & change the other to + (plus) SetRotation(e,0,new_angle[e],0) else angle[e] = new_angle[e] temp[e] = -1 SetActivated(e,2) CollisionOff(e) end elseif g_Entity[e]['activated'] == 3 then if temp[e] < 90 then temp[e] = temp[e] + 0.5 --match the previous temp[e] modifier above new_angle[e] = angle[e] + temp[e] --change this if you change the other 1 SetRotation(e,0,new_angle[e],0) else angle[e] = new_angle[e] temp[e] = -1 SetActivated(e,0) CollisionOn(e) end end end end if GetScancode() == 0 then pressed = 0 end end function RotateToPoint(e,x,z) if g_Entity[e] ~= nil and x > 0 and z > 0 then local destx = x - g_Entity[e]['x'] local destz = z - g_Entity[e]['z'] local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle < 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end SetRotation(e,0,angle,0) return angle end end