Jump to content

First Person Height Change + Remove Leaning in Vehicle?


[PXG]Blue

Recommended Posts

Hello, i have a script here ( its not made by me nor do i claim ownership of it ) wich enables first person, and i need a little help making it register height changes, because as of yet it only registers changes if i'm going left or right

EDIT: is it also possible to remove the character leaning to the left / right when steering?

here my code:

local rotX, rotY = 0, 0 
local camVehRot = 0 
local rot = 0 
  
local curVehRot = 0 
local oldVehRot = 0 
  
local egoEnabled = false 
  
local mouseSensitivity = 0.1 
  
local delay = 0 
  
lp = getLocalPlayer() 
local PI = math.pi 
  
  
function vehAlpha() 
setElementAlpha(lp,0) 
end 
addEventHandler("onClientPlayerVehicleEnter",root, vehAlpha ) 
  
function vehAlpha2() 
setElementAlpha(lp,255) 
end 
addEventHandler("onClientPlayerVehicleExit",root, vehAlpha2 ) 
local function freecamFrame ( slice ) 
  
  
    local camPosX, camPosY, camPosZ = getPedBonePosition ( lp, 8 ) 
     
    local angleZ = math.sin(rotY) 
    local angleY = math.cos(rotY) * math.cos(rotX) 
    local angleX = math.cos(rotY) * math.sin(rotX) 
     
    local camTargetX = camPosX + ( angleX ) * 100 
    local camTargetY = camPosY + angleY * 100 
    local camTargetZ = camPosZ + angleZ * 100 
     
     
    if isPedInVehicle(lp) then 
    setElementAlpha(lp,0) 
    else 
    setElementAlpha(lp,255) 
    end 
    local veh = getPedOccupiedVehicle ( lp ) 
    if veh then 
         
        local rx, ry, curVehRot = getElementRotation ( veh ) 
        local changedRotation = oldVehRot - curVehRot 
         
        oldVehRot = curVehRot 
         
        if not totalRot then 
            totalRot = curVehRot 
        end 
         
        totalRot = changedRotation * 2 + totalRot 
         
        local rotX = ( ( rotX * 360 / PI ) + totalRot ) / 360 * PI 
        if rotX > PI then 
            rotX = rotX - 2 * PI 
        elseif rotX < -PI then 
            rotX = rotX + 2 * PI 
        end 
         
        camTargetX = camPosX + ( math.cos(rotY) * math.sin(rotX) ) * 100 
        camTargetY = camPosY + ( math.cos(rotY) * math.cos(rotX) ) * 100 
    end 
     
    setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ ) 
end 
  
local function freecamMouse (cX,cY,aX,aY) 
  
    if isCursorShowing() or isMTAWindowActive() then 
        delay = 5 
        return 
    elseif delay > 0 then 
        delay = delay - 1 
        return 
    end 
     
    local width, height = guiGetScreenSize() 
    aX = aX - width / 2  
    aY = aY - height / 2 
     
    rotX = rotX + aX * mouseSensitivity * 0.01745 
    rotY = rotY - aY * mouseSensitivity * 0.01745 
  
    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 
     
    if rotY < -PI / 2.05 then 
       rotY = -PI / 2.05 
    elseif rotY > PI / 2.05 then 
        rotY = PI / 2.05 
    end 
end 
  
function setEgoEnabled (x, y, z) 
  
    if (x and y and z) then 
        setCameraMatrix ( camPosX, camPosY, camPosZ ) 
    end 
    addEventHandler("onClientPreRender", getRootElement(), freecamFrame) 
    addEventHandler("onClientRender", getRootElement(), freecamFrame) 
    addEventHandler("onClientCursorMove",getRootElement(), freecamMouse) 
end 
  
function setEgoDisabled() 
  
    if egoEnabled then 
        egoEnabled = false 
        removeEventHandler("onClientPreRender", getRootElement(), freecamFrame) 
        removeEventHandler("onClientRender", getRootElement(), freecamFrame) 
        removeEventHandler("onClientCursorMove",getRootElement(), freecamMouse) 
        setCameraTarget ( lp ) 
    end 
end 
addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), setEgoDisabled ) 
  
function ego_func () 
  
    if egoEnabled then 
        setEgoDisabled() 
    else 
        egoEnabled = true 
        local x, y, z = getElementPosition ( lp ) 
        setEgoEnabled ( x, y, z ) 
    end 
end 
addCommandHandler ( "ego", ego_func ) 
addCommandHandler ( "fp", ego_func ) 
addCommandHandler ( "fps", ego_func ) 
addCommandHandler ( "firstperson", ego_func ) 

thanks in advance

Link to comment
  • Moderators

You can detect it with:

local camPosX, camPosY, [color=#FF0000]camPosZ[/color] = getPedBonePosition ( lp, 8 ) 

Line: 46 t/m 69 is for the leaning left and right, you can rip it out < reason why I compile my scripts....

Link to comment
You can detect it with:

local camPosX, camPosY, [color=#FF0000]camPosZ[/color] = getPedBonePosition ( lp, 8 ) 

Line: 46 t/m 69 is for the leaning left and right, you can rip it out < reason why I compile my scripts....

Thanks for the Help,

also, i dont get this hate when i ask for help when editing a script thats not mine, thats why many people DONT compile their scripts, so others can be creative.

Link to comment
  • Moderators

Because the developer of a script is a designer. Not always a graphical designer, but also a designer of a system made by code. When you rip code out of a script, the design changes. Most of the time the design becomes uglier because 90% don't understand how it works. Ugly in a way that it doesn't work well any more, ugly in the interaction with the user or ugly at the level of graphical design(gui's, dx).

But that is not the problem, the problem lies with the publishing.

Two ways of publishing, with negative attention for the developer:

- Badly edited the resource and published it on a server. And it will shows all visitors how badly you(developer) designed it. And no they will not look at the unknown person that edited it, but YOU as developer.

- Ripping out the code and places it in badly designed resource. Mostly without author copy right. They will be reminded by the code you published before and make that LINK between your resource and that badly designed one.

Link to comment

As far as I'm aware there's no "hate" towards helping people with a script that isn't theirs, at least I have no issues with it and I'd gladly help.

What I do have issues with, however, is when people use someone else's work and don't give credit where credit is due. Even more so, people that use leaked scripts or decompiled scripts without the author's permission.

So long as you don't make the claim that it is yours, you'll be fine. And giving credit where due is always a nice thing to do.

If someone has a fit because you're using something you didn't make, simply ignore them. They're usually no better themselves and calling people out is a way for them to make themselves feel good. :lol:

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