Jump to content

[WIP|F+|1.1]awesomeufo 2.4


qaisjp

Recommended Posts

theres an variable called zoom in front of freecam script.i even commented it in the script.

if u don't want z, then remove the z velocity, and the z recalculation based on speed.

and to change rotation of ufo, just use math.deg(rotX) as z rotation for the obj/model.

(check PMS if you havent)

Link to comment
  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

To get the latest script click below, remember this is incomplete!

NEW UPDATE!

Syncing with the server should now be made!

Object Rotation is now corresponding to Camera Rotation

Better camera rotation, implemented on the Z axis, I can't do the X and Y axis since I'm shit with the mathematics aspect of that.

bugfix: no longer can accelerate using W when mouse is showing!

To do/Coming next:

  • Less server side script due to non-need of events (objects aren't synced, but vehicles are)
  • Perhaps a few extras ( I NEED HELP ON THE WORLD COLLIDE!!!!!!!!!!!!!!!! )
  • Nuke enhancement and/or fixes.
  • A release and screenshot updates (maybe or maybe not..)
  • Model+Texture for a new UFO ~ I cannot do this, calling all modellers ;_;! ~ Interior and Exterior needed!

ENJOY =)

edit1: onoes a bug, very slowly the ufo decreases it's Z position. unfortunately, i dunno how to fix this.

edit2: hacky fix. client script updated.

edit3: sorry for forgetting to thank you karlis =) I didn't quite get what you meant but I understood later on ;D

edit4: took out the hacky fix of edit2 that fixed edit1 and replaced it with a proper fix.

Link to comment
  
local zoom=10 --how far is camera target from ufo 
local mouseFrameDelay = 0 
local ratio = 3 --how many times distance from camera to ufo is smaller then distance from ufo to camera target 
local mouseSensetivity = 0.25 --ovbious much? 
local width, height = guiGetScreenSize() 
local PI = math.pi 
local hit 
local zOffset = 3 --how much the camera is higher then ufo itself. 
-- state variables 
local speed = 0 
local rotX, rotY = 0,0 
  
-- configurable parameters 
local options = { 
    invertMouseLook = false, 
    normalMaxSpeed = 2, 
    slowMaxSpeed = 0.2, 
    fastMaxSpeed = 12, 
    smoothMovement = true, 
    acceleration = 0.3, 
    decceleration = 0.15, 
    maxYAngle = 188, 
    key_fastMove = "lshift", 
    key_slowMove = "lalt", 
    key_forward = "w", 
} 
  
local rootElement = getRootElement() 
  
local getKeyState = getKeyState 
do 
    local mta_getKeyState = getKeyState 
    function getKeyState(key) 
        if isMTAWindowActive() then 
            return false 
        else 
            return mta_getKeyState(key) 
        end 
    end 
end 
  
--heavily modified freecam resource's core 
function freecamFrame() 
    local cameraAngleX = rotX 
    local cameraAngleY = rotY 
    local freeModeAngleZ = math.sin(cameraAngleY) 
    local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX) 
    local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX) 
    local camPosX, camPosY, camPosZ = getElementPosition(ufo) 
    local camPosZ = camPosZ + zOffset 
    local mspeed = options.normalMaxSpeed 
    if getKeyState ( options.key_fastMove ) then 
        mspeed = options.fastMaxSpeed 
    elseif getKeyState ( options.key_slowMove ) then 
        mspeed = options.slowMaxSpeed 
    end 
    if options.smoothMovement then 
        local acceleration = options.acceleration 
        local decceleration = options.decceleration 
        -- Check to see if the forwards key are pressed 
        local speedKeyPressed = false 
        if getKeyState ( options.key_forward ) then 
            speed = speed + acceleration  
            speedKeyPressed = true 
        end 
        -- If no forwards key were pressed, then gradually slow down the movement towards 0 
        if not speedKeyPressed then 
            speed = speed - decceleration 
        end 
        -- Check the ranges of values - set the speed to 0 if its very close to 0 (stops jittering), and limit to the maximum speed 
        if speed < decceleration then 
            speed = 0 
        elseif speed > mspeed then 
            speed = mspeed 
        end 
    else 
        speed = 0 
        if getKeyState ( options.key_forward ) then speed = mspeed end 
    end 
    -- Update the camera position based on the forwards/backwards speed 
    camPosX = camPosX + freeModeAngleX * speed 
    camPosY = camPosY + freeModeAngleY * speed 
    -- calculate a target based on the current position and an offset based on the angle 
    local camTargetX = camPosX + freeModeAngleX * zoom 
    local camTargetY = camPosY + freeModeAngleY * zoom 
    local camTargetZ = camPosZ + freeModeAngleZ * zoom 
    camPosX = camPosX - ( camTargetX - camPosX ) / ratio 
    camPosY = camPosY - ( camTargetY - camPosY ) / ratio 
    camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio 
    if not isLineOfSightClear(camPosX,camPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,localPlayer) then 
        _,camPosX,camPosY,camPosZ=processLineOfSight(camPosX,camPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,false,localPlayer) 
    end 
    -- Set the new camera position and target 
    setElementRotation(ufo,0,0,math.deg(rotX)) 
    setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetRealX, camTargetRealY, camTargetRealZ ) 
end 
  
function freecamMouse(_,_,aX,aY) 
    --ignore mouse movement if the cursor or MTA window is on 
    --and do not resume it until at least 5 frames after it is toggled off 
    --(prevents cursor mousemove data from reaching this handler) 
    if isCursorShowing() or isMTAWindowActive() then 
        mouseFrameDelay = 5 
        return 
    elseif mouseFrameDelay > 0 then 
        mouseFrameDelay = mouseFrameDelay - 1 
        return 
    end 
    if options.invertMouseLook then 
        aY = -aY 
    end 
    -- how far have we moved the mouse from the screen center? 
    aX = aX - width / 2  
    aY = aY - height / 2 
    rotX = rotX + aX *  0.01745 * mouseSensetivity 
    rotY = rotY - aY *  0.01745 * mouseSensetivity 
    if rotX > PI then 
        rotX = rotX - 2 * PI 
    elseif rotX < -PI then 
        rotX = rotX + 2 * PI 
    end 
    if rotY > PI then 
        rotY = rotY - 2 * PI 
    elseif rotY < -PI then 
        rotY = rotY + 2 * PI 
    end 
    -- limit the camera to stop it going too far up or down - PI/2 is the limit, but we can't let it quite reach that or it will lock up 
    -- and strafeing will break entirely as the camera loses any concept of what is 'up' 
    if rotY < -PI / 3 then 
       rotY = -PI / 3 
    elseif rotY > PI / 3 then 
        rotY = PI / 3 
    end 
    -- work out an angle in radians based on the number of pixels the cursor has moved (ever) 
end 
  

report bugs if any.

ufo elem is ur ufo btw.

Link to comment

Didn't exactly work :| kinda fucked up beyond description

--[[ 
    This resource has been created by qaisjp
    Find more epic resources at [url=http://www.code.google.com/p/mta-freeroamplus]http://www.code.google.com/p/mta-freeroamplus[/url]
    Please give me credit!
]]
-------------------[..]
--///////////////--
-------------------
--[[do -- This contains content from the freecam resource and has been editied by karlis, so thanks to him.
     TO DO LIST:
        When moving forward, the ufo will move forward. Only forward is supported (W)
        Cursor look-at direction changes the rotation of the ufo.
        So when moving the ufo will always move forward, but in the camera lookat direction
]]
 
 
local zoom=10 --how far is camera target from ufo
local mouseFrameDelay = 0
local ratio = 3 --how many times distance from camera to ufo is smaller then distance from ufo to camera target
local mouseSensetivity = 0.25 --ovbious much?
local width, height = guiGetScreenSize()
local PI = math.pi
local hit
local zOffset = 3 --how much the camera is higher then ufo itself.
-- state variables
local speed = 0
local rotX, rotY = 0,0
 
-- configurable parameters
local options = {
    invertMouseLook = false,
    normalMaxSpeed = 2,
    slowMaxSpeed = 0.2,
    fastMaxSpeed = 12,
    smoothMovement = true,
    acceleration = 0.3,
    decceleration = 0.15,
    maxYAngle = 188,
    key_fastMove = "lshift",
    key_slowMove = "lalt",
    key_forward = "w",
}
 
local rootElement = getRootElement()
 
local getKeyState = getKeyState
do
    local mta_getKeyState = getKeyState
    function getKeyState(key)
        if isMTAWindowActive() then
            return false
        else
            return mta_getKeyState(key)
        end
    end
end
 
--heavily modified freecam resource's core
function freecamFrame()
    if not data.enabled then return end
    if getKeyState(options.key_fastMove) then
        options.mouseSensitivity = 0.7
    elseif getKeyState(options.key_slowMove) then
        options.mouseSensitivity = 0.1
    else
        options.mouseSensitivity = 0.3
    end
   
    do
        local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
        for i,v in ipairs(additions) do
            local gui, show = getControl(v), isCursorShowing()
            guiSetAlpha(gui, show and 1 or 0.9)
            guiSetEnabled(gui, show)
        end
    end
       
    setElementPosition(getPedOccupiedVehicle(me) or me, getElementPosition(ufo))
    local cameraAngleX = rotX
    local cameraAngleY = rotY
    local freeModeAngleZ = math.sin(cameraAngleY)
    local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
    local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX)
    local camPosX, camPosY, camPosZ = getElementPosition(ufo)
    local camPosZ = camPosZ + zOffset
    local mspeed = options.normalMaxSpeed
    if getKeyState ( options.key_fastMove ) then
        mspeed = options.fastMaxSpeed
    elseif getKeyState ( options.key_slowMove ) then
        mspeed = options.slowMaxSpeed
    end
    if options.smoothMovement then
        local acceleration = options.acceleration
        local decceleration = options.decceleration
        -- Check to see if the forwards key are pressed
        local speedKeyPressed = false
        if getKeyState ( options.key_forward ) then
            speed = speed + acceleration
            speedKeyPressed = true
        end
        -- If no forwards key were pressed, then gradually slow down the movement towards 0
        if not speedKeyPressed then
            speed = speed - decceleration
        end
        -- Check the ranges of values - set the speed to 0 if its very close to 0 (stops jittering), and limit to the maximum speed
        if speed < decceleration then
            speed = 0
        elseif speed > mspeed then
            speed = mspeed
        end
    else
        speed = 0
        if getKeyState ( options.key_forward ) then speed = mspeed end
    end
    -- Update the camera position based on the forwards/backwards speed
    camPosX = camPosX + freeModeAngleX * speed
    camPosY = camPosY + freeModeAngleY * speed
    local camX, camY = camPosX, camPosY
    -- calculate a target based on the current position and an offset based on the angle
    local camTargetX = camPosX + freeModeAngleX * zoom
    local camTargetY = camPosY + freeModeAngleY * zoom
    local camTargetZ = camPosZ + freeModeAngleZ * zoom
    camPosX = camPosX - ( camTargetX - camPosX ) / ratio
    camPosY = camPosY - ( camTargetY - camPosY ) / ratio
    camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio
    if not isLineOfSightClear(camPosX,camPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,localPlayer) then
        _,camPosX,camPosY,camPosZ=processLineOfSight(camPosX,camPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,false,localPlayer)
    end
    -- Set the new camera position and target
    setElementRotation(ufo,0,0,math.deg(-rotX))
    setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetRealX, camTargetRealY, camTargetRealZ )
    -- Set the new camera position and target
    local _,_,ufoZ = getElementPosition(ufo)
    setElementPosition(ufo, camX, camY, ufoZ)
end
 
local function freecamMouse (cX,cY,aX,aY)
    --ignore mouse movement if the cursor or MTA window is on
    --and do not resume it until at least 5 frames after it is toggled off
    --(prevents cursor mousemove data from reaching this handler)
    if not data.enabled then return end
    if isCursorShowing() or isMTAWindowActive() then
        mouseFrameDelay = 5
        return
    elseif mouseFrameDelay > 0 then
        mouseFrameDelay = mouseFrameDelay - 1
        return
    end
   
    -- how far have we moved the mouse from the screen center?
    local width, height = guiGetScreenSize()
    aX = aX - width / 2
    aY = aY - height / 2
   
    --invert the mouse look if specified
    if options.invertMouseLook then
        aY = -aY
    end
   
    rotX = rotX + aX * options.mouseSensitivity * 0.01745
    rotY = rotY - aY * options.mouseSensitivity * 0.01745
   
    local PI = math.pi
    if rotX > PI then
        rotX = rotX - 2 * PI
    elseif rotX < -PI then
        rotX = rotX + 2 * PI
    end
   
    if rotY > PI then
        rotY = rotY - 2 * PI
    elseif rotY < -PI then
        rotY = rotY + 2 * PI
    end
    -- limit the camera to stop it going too far up or down - PI/2 is the limit, but we can't let it quite reach that or it will lock up
    -- and strafeing will break entirely as the camera loses any concept of what is 'up'
    if rotY < -PI / 2.05 then
       rotY = -PI / 2.05
    elseif rotY > PI / 2.05 then
        rotY = PI / 2.05
    end
end
addEventHandler("onClientRender", root, freecamFrame)
addEventHandler("onClientCursorMove", root, freecamMouse)
--[[state variables
local speed = 0
local strafespeed = 0
local rotX, rotY = 0,0
local velocityX, velocityY, velocityZ
 
-- configurable parameters
local options = {
    invertMouseLook = false,
    normalMaxSpeed = 1,
    slowMaxSpeed = 0.2,
    fastMaxSpeed = 9,
    smoothMovement = true,
    acceleration = 0.3,
    decceleration = 0.15,
    mouseSensitivity = 0.3,
    maxYAngle = 188,
    key_fastMove = "lshift",
    key_slowMove = "lalt",
    key_forward = "w",
    zoom = 100,
    ratio = 3, --how many times distance from camera to player is smaller then distance from player to camera target
}
 
local mouseFrameDelay = 0
local getKeyState = getKeyState
do
    local mta_getKeyState = getKeyState
    function getKeyState(key)
        if isMTAWindowActive() or isCursorShowing()then
            return false
        else
            return mta_getKeyState(key)
        end
    end
end
 
-- PRIVATE
 
local function freecamFrame ()
    if not data.enabled then return end
       
        if getKeyState(options.key_fastMove) then
            options.mouseSensitivity = 0.7
        elseif getKeyState(options.key_slowMove) then
            options.mouseSensitivity = 0.1
        else
            options.mouseSensitivity = 0.3
        end
       
        do
            local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
            for i,v in ipairs(additions) do
                local gui, show = getControl(v), isCursorShowing()
                guiSetAlpha(gui, show and 1 or 0.9)
                guiSetEnabled(gui, show)
            end
        end
       
        setElementPosition(getPedOccupiedVehicle(me) or me, getElementPosition(ufo))
       
    -- work out an angle in radians based on the number of pixels the cursor has moved (ever)
    local cameraAngleX = rotX
    local cameraAngleY = rotY
 
    local freeModeAngleZ = math.sin(cameraAngleY)
    local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
Link to comment

ok done, took me 20min, sorry for so long waiting.

  
      
    local zoom=350 --how far is camera target from ufo 
    local mouseFrameDelay = 0 
    local ratio = 3 --how many times distance from camera to ufo is smaller then distance from ufo to camera target 
    local mouseSensetivity = 0.25 --ovbious much? 
    local width, height = guiGetScreenSize() 
    local PI = math.pi 
    local hit 
    local zOffset = 3 --how much the camera is higher then ufo itself. 
    -- state variables 
    local speed = 0 
    local rotX, rotY = 0,PI/1.5 
      
    -- configurable parameters 
    local options = { 
        invertMouseLook = false, 
        normalMaxSpeed = 2, 
        slowMaxSpeed = 0.2, 
        fastMaxSpeed = 12, 
        smoothMovement = true, 
        acceleration = 0.3, 
        decceleration = 0.15, 
        maxYAngle = 188, 
        key_fastMove = "lshift", 
        key_slowMove = "lalt", 
        key_forward = "w", 
    } 
      
    local rootElement = getRootElement() 
      
    local getKeyState = getKeyState 
    do 
        local mta_getKeyState = getKeyState 
        function getKeyState(key) 
            if isMTAWindowActive() then 
                return false 
            else 
                return mta_getKeyState(key) 
            end 
        end 
    end 
      
    --heavily modified freecam resource's core 
    function freecamFrame() 
        local cameraAngleX = rotX 
        local cameraAngleY = rotY 
        local freeModeAngleZ = math.sin(cameraAngleY) 
        local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX) 
        local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX) 
        local camPosX, camPosY, camPosLastZ = getElementPosition(ufo) 
        local camPosZ = camPosLastZ + zOffset 
        local mspeed = options.normalMaxSpeed 
        if getKeyState ( options.key_fastMove ) then 
            mspeed = options.fastMaxSpeed 
        elseif getKeyState ( options.key_slowMove ) then 
            mspeed = options.slowMaxSpeed 
        end 
        if options.smoothMovement then 
            local acceleration = options.acceleration 
            local decceleration = options.decceleration 
            -- Check to see if the forwards key are pressed 
            local speedKeyPressed = false 
            if getKeyState ( options.key_forward ) then 
                speed = speed + acceleration 
                speedKeyPressed = true 
            end 
            -- If no forwards key were pressed, then gradually slow down the movement towards 0 
            if not speedKeyPressed then 
                speed = speed - decceleration 
            end 
            -- Check the ranges of values - set the speed to 0 if its very close to 0 (stops jittering), and limit to the maximum speed 
            if speed < decceleration then 
                speed = 0 
            elseif speed > mspeed then 
                speed = mspeed 
            end 
        else 
            speed = 0 
            if getKeyState ( options.key_forward ) then speed = mspeed end 
        end 
        -- Update the camera position based on the forwards/backwards speed 
        ufoPosX = camPosX + freeModeAngleX * speed 
        ufoPosY = camPosY + freeModeAngleY * speed 
        camPosZ = camPosLastZ + freeModeAngleZ * speed 
        -- calculate a target based on the current position and an offset based on the angle 
        local camTargetX = ufoPosX + freeModeAngleX * zoom 
        local camTargetY = ufoPosY + freeModeAngleY * zoom 
        local camTargetZ = camPosZ + freeModeAngleZ * zoom 
        camPosX = ufoPosX - ( camTargetX - ufoPosX ) / ratio 
        camPosY = ufoPosY - ( camTargetY - ufoPosY ) / ratio 
        camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio 
        if not isLineOfSightClear(ufoPosX,ufoPosY,camPosLastZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,realufo) then 
            _,camPosX,camPosY,camPosZ=processLineOfSight(ufoPosX,ufoPosY,camPosLastZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,false,realufo) 
        end 
        -- Set the new camera position and target 
        setElementRotation(ufo,0,0,-math.deg(rotX)) 
        setElementPosition(ufo,ufoPosX,ufoPosY,camPosLastZ) 
        setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ ) 
    end 
      
    function freecamMouse(_,_,aX,aY) 
        --ignore mouse movement if the cursor or MTA window is on 
        --and do not resume it until at least 5 frames after it is toggled off 
        --(prevents cursor mousemove data from reaching this handler) 
        if isCursorShowing() or isMTAWindowActive() then 
            mouseFrameDelay = 5 
            return 
        elseif mouseFrameDelay > 0 then 
            mouseFrameDelay = mouseFrameDelay - 1 
            return 
        end 
        if options.invertMouseLook then 
            aY = -aY 
        end 
        -- how far have we moved the mouse from the screen center? 
        aX = aX - width / 2 
        aY = aY - height / 2 
        rotX = rotX + aX *  0.01745 * mouseSensetivity 
        rotY = rotY - aY *  0.01745 * mouseSensetivity 
        if rotX > PI then 
            rotX = rotX - 2 * PI 
        elseif rotX < -PI then 
            rotX = rotX + 2 * PI 
        end 
        if rotY > PI then 
            rotY = rotY - 2 * PI 
        elseif rotY < -PI then 
            rotY = rotY + 2 * PI 
        end 
        -- limit the camera to stop it going too far up or down - PI/2 is the limit, but we can't let it quite reach that or it will lock up 
        -- and strafeing will break entirely as the camera loses any concept of what is 'up' 
        if rotY < -PI / 3 then 
           rotY = -PI / 3 
        elseif rotY > PI / 3 then 
            rotY = PI / 3 
        end 
        -- work out an angle in radians based on the number of pixels the cursor has moved (ever) 
    end 
    addEventHandler("onClientRender", root, freecamFrame) 
    addEventHandler("onClientCursorMove", root, freecamMouse) 
      
  

NOTE: as camera start is about 120m from the ufo, and on start its facing up,don't let the camera get stuck under the map by putting the ufo about 150m in air on start.

PS: the handling is too plain imo...its good for a freecam, but not a psyhical object, even tough its hightech.

you should probably a bit influence it by wind velocity, and add a bit of gravity, inertia, rotation inertia, stuff like that.

if ill finish ivhud ill help you.

Link to comment

"PS: the handling is too plain imo...its good for a freecam, but not a psyhical object, even tough its hightech.

you should probably a bit influence it by wind velocity, and add a bit of gravity, inertia, rotation inertia, stuff like that." I really don't understand what you mean by making the UFO interact with gravity, intertia, rotinertia and 'stuff like that' - I'm clueless.

Thanks, i will try the code later =)

Link to comment

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