Jump to content

[Question] Offset in direction?


Jakus

Recommended Posts

Hey,

Just trying to get this script working. All it does is spawn you inside the Andromeda cargo hold when you step onto the ramp (anywhere you can step on) of an Andromeda. Then spawn you outside the Andromeda when you walk on the ramp out. I'm using the "getPointFromDistanceRotation" example in the wiki. But my problem is it keeps spawning me randomly around the plane when I walk out. Anyway here's my code (beginner, so tips and corrections very welcome).

  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
function vehicleAndromadaHandling(pe,ce) 
    if isElement(ce) and getElementType(ce) == "vehicle" and getElementModel(ce) == 592 then 
            setPedRotation(source, 180) 
            setCameraTarget(source,source) 
            setElementData(source,"entveh",ce,false) 
            setElementData(source,"onplane",true,true) 
            setElementInterior(source,9,315.64258,1031.65771,1947.08655) 
             
            if isTimer(AndroTimer) ~= true then 
            AndroTimer = setTimer( 
                function() 
                count = 0 
                for index, player in ipairs(getElementsByType("player")) do 
                    if getElementData(player,"onplane") then 
                        count = count + 1 
                        local x,y,z = getElementPosition(player) 
                        if getElementInterior(player) == 9 and z>1900 and z<1946.72034 then                          
                            local px,py,pz = getElementPosition(getElementData(player,"entveh")) 
                            local rotx,roty,rotz = getVehicleRotation(getElementData(player,"entveh")) 
                            local newx, newy = getPointFromDistanceRotation(px,py,25,rotz) 
                            setElementInterior(player,0,newx,newy,pz) 
                            setPedRotation(player,rotz) 
                            setCameraTarget(player,player) 
                        end 
                    end 
                end 
                if count == 0 then killTimer(AndroTimer) end 
            end 
            ,250,0) 
                 
            end 
        end 
end 
addEventHandler("onPlayerContact",getRootElement(),vehicleAndromadaHandling) 
  

Link to post
setElementData(source,"onplane",true,true) 

edit: sry, this is synchro. Try now

  
  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
 local count = 0 
  
function vehicleAndromadaHandling(pe,ce) 
    if isElement(ce) and getElementType(ce) == "vehicle" and getElementModel(ce) == 592 then 
            setPedRotation(source, 180) 
            setCameraTarget(source,source) 
            setElementData(source,"entveh",ce,false) 
            setElementData(source,"onplane",true,true) 
            setElementInterior(source,9,315.64258,1031.65771,1947.08655) 
            if isTimer(AndroTimer) ~= true then 
            AndroTimer = setTimer( 
                function() 
                for index, player in ipairs(getElementsByType("player")) do 
                    if getElementData(player,"onplane") then 
                        count = 1 
                        local x,y,z = getElementPosition(player) 
                        if getElementInterior(player) == 9 and z>1900 and z<1946.72034 then                         
                            local px,py,pz = getElementPosition(getElementData(player,"entveh")) 
                            local rotx,roty,rotz = getVehicleRotation(getElementData(player,"entveh")) 
                            local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z) 
                            local newx, newy = getPointFromDistanceRotation(px,py,distance,rotz) 
                            setElementInterior(player,0,newx,newy,pz) 
                            setPedRotation(player,rotz) 
                            setCameraTarget(player,player) 
                        end 
                    else 
                        count = 0 
                    end 
                end 
                if count == 0 then killTimer(AndroTimer) end 
            end 
            ,250,0) 
                
            end 
        end 
end 
addEventHandler("onPlayerContact",getRootElement(),vehicleAndromadaHandling) 
  
  

Link to post

Thanks for the help, figured it out. Tuned it a little; this is the best I could get it. For anyone looking for an andromada you can walk inside of...

  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
function vehicleAndromadaHandling(pe,ce) 
    if isElement(ce) and getElementType(ce) == "vehicle" and getElementModel(ce) == 592 then 
            setPedRotation(source, 180) 
            setCameraTarget(source,source) 
            setElementData(source,"entveh",ce,false) 
            setElementData(source,"onplane",true,true) 
            setElementInterior(source,9,315.64258,1031.65771,1947.08655) 
            if isTimer(AndroTimer) ~= true then 
            AndroTimer = setTimer( 
                function() 
                count = false 
                for index, player in ipairs(getElementsByType("player")) do 
                    if getElementData(player,"onplane") then 
                        count = true 
                        local x,y,z = getElementPosition(player) 
                        if getElementInterior(player) == 9 and z>1900 and z<1946.72034 then  
                            local thePlane = getElementData(player,"entveh")                         
                            local px,py,pz = getElementPosition(thePlane) 
                            local rotx,roty,rotz = getVehicleRotation(thePlane) 
                            local newx, newy = getPointFromDistanceRotation(px,py,25,180 - rotz) 
                            setElementInterior(player,0,newx,newy,pz - 1) 
                            setPedRotation(player,360 - rotz) 
                            outputChatBox(rotz .. " : " .. getPedRotation(player)) 
                            setCameraTarget(player,player) 
                            setElementData(player,"onplane",false,true) 
                        end 
                    end 
                end 
                if count == false then killTimer(AndroTimer) end 
            end 
            ,250,0) 
                 
            end 
        end 
end 
addEventHandler("onPlayerContact",getRootElement(),vehicleAndromadaHandling) 
  

Link to post

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