Jump to content

Gravity Problem


Agon

Recommended Posts

function playerOptions() 
    setPedCanBeKnockedOffBike(source,false) 
    addEventHandler("onClientPlayerVehicleEnter",source,enableGravityWheels) 
    addEventHandler("onClientPlayerVehicleExit",source,disableGravityWheels) 
end 
  
function checkCarWheels() 
if isVehicleOnGround(car) == true then changeGravity() 
else return end 
end 
  
  
function changeGravity() 
setVehicleGravity(car,underx - x,undery - y,underz - z) 
end 
  
function disableGravityWheels() 
setVehicleGravity(car, 0, 0, -1) 
end 
  
function enableGravityWheels() 
local car = getPedOccupiedVehicle(source) 
local x,y,z = getElementPosition(car) 
local underX,underY,underZ = getVehicleUnderGravity(car) 
if (isVehicleOnGround(car) == false) and if (isPedInVehicle(source) == false) then return end 
else setTimer(checkCarWheels, 1000, 0)   
end 
end 
  
function getVehicleUnderGravity(element) 
    local matrix = getElementMatrix (element) 
    local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1] 
    local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2] 
    local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3] 
    return offX,offY,offZ 
end 
  
addCommandHandler("gravity",enableGravityWheels) 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),playerOptions) 

I wanted to make a gravity script (with some help of resources) i can enable it (but doesn't work :P) but don't know how to disable it again. should i use "addCommandHandler("gravity",disableGravityWheels)" ?

Link to comment

Tested.

  
local timer,state 
local underX,underY,underZ 
local x,y,z 
  
function playerOptions( ) 
    setPedCanBeKnockedOffBike( localPlayer,false ) 
    addEventHandler( "onClientPlayerVehicleEnter",localPlayer,enableGravityWheels ) 
    addEventHandler( "onClientPlayerVehicleExit",localPlayer,disableGravityWheels ) 
end 
  
function checkCarWheels( vehicle ) 
    if isVehicleOnGround( vehicle ) then  
        changeGravity( vehicle ) 
    end 
end 
  
  
function changeGravity( vehicle ) 
    setVehicleGravity( vehicle,underX - x,underY - y,underZ - z ) 
end 
  
function disableGravityWheels( vehicle ) 
    setVehicleGravity( vehicle, 0, 0, -1 ) 
end 
  
function enableGravityWheels( vehicle ) 
    local vehicle 
    if not isElement( vehicle ) then vehicle = getPedOccupiedVehicle( localPlayer ) end 
    x,y,z = getElementPosition( vehicle ) 
    underX,underY,underZ = getVehicleUnderGravity( vehicle ) 
    if isVehicleOnGround( vehicle ) and isPedInVehicle( source or localPlayer ) then 
        if isTimer( timer ) then killTimer( timer ) end 
        timer = setTimer( checkCarWheels, 1000, 0,vehicle )   
    end 
end 
  
function getVehicleUnderGravity( element ) 
    local matrix = getElementMatrix ( element ) 
    local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1] 
    local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2] 
    local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3] 
    return offX,offY,offZ 
end 
addCommandHandler( "gravity",enableGravityWheels ) 
addEventHandler( "onClientResourceStart",resourceRoot,playerOptions ) 

or maybe you need this?

local state  
addCommandHandler( "gravity", 
    function( ) 
        local veh = getPedOccupiedVehicle( localPlayer ) 
        if veh then 
            state = not state 
            if state then 
                setVehicleGravity( veh, 0, 0, 0 ) 
            else 
                setVehicleGravity( veh, 0, 0, -1 ) 
            end 
        end  
    end 
) 

/debugscript 3 use.

You need learn lua http://www.lua.org/manual/5.1/

And this https://wiki.multitheftauto.com/wiki/Scr ... troduction

Updated again.

Link to comment

i used /debugscript 3 but i didn't get any error and i can't drive on walls :(

btw your second script may be good but i want to check if the vehicle's wheels on the ground. i saw some resources which didn't check that and it makes you fly sometimes...

Link to comment

I know that resources but they make me fly wall to wall and sometimes to sky... and that's annoying. i want to make it with checking if vehicle is touching a wall or something else. if it doesn't touch (i mean if it is on the air), it won't perform gravity change.. hope you understand me :(

Link to comment
I know that resources but they make me fly wall to wall and sometimes to sky... and that's annoying. i want to make it with checking if vehicle is touching a wall or something else. if it doesn't touch (i mean if it is on the air), it won't perform gravity change.. hope you understand me :(

isVehicleOnGround doesn't work with all vehicles, and wont work on non-flat ground (walls, loops etc).

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