1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

working on a no clip mod for pc and controller help

Discussion in 'Mod Requests' started by iamproforthewin, Oct 3, 2017.

Tags:
  1. working on a no clip mod for pc and controller here is my scrip Need Help


    local noclip = {}

    local enabled = false
    local timer = 0
    local timer2 = 0
    local allowtoggle = true
    local controllermode = false
    local speedmult = 0.5
    local vehiclerotation = 0

    function noclip.unload()

    end
    function noclip.init()

    end

    function noclip.tick()
    local player = PLAYER.PLAYER_PED_ID()
    local playerped = PLAYER.GET_PLAYER_PED(player)
    local jumping = PED.IS_PED_JUMPING(player)
    local falling = PED.IS_PED_FALLING(player)
    local parastate = PED.GET_PED_PARACHUTE_STATE(player)
    local vehiclecheck = PED.IS_PED_IN_ANY_VEHICLE(player, true)
    local vehicle = PED.GET_VEHICLE_PED_IS_IN(player, true)
    local speed = ENTITY.GET_ENTITY_SPEED(player)
    local detentity

    if vehiclecheck then
    detentity = vehicle
    else
    detentity = player
    end

    local velocity = ENTITY.GET_ENTITY_VELOCITY(detentity)
    local rotation = ENTITY.GET_ENTITY_ROTATION(detentity, false)
    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)



    if ( allowtoggle == false ) then
    if timer > 20 and ( not (get_key_pressed(Keys.N) or CONTROLS.IS_CONTROL_PRESSED(2,74)) ) then
    timer = 0
    allowtoggle = true
    else
    timer = timer + 1
    end
    end

    if ( ( get_key_pressed(Keys.N) or (CONTROLS.IS_CONTROL_PRESSED(2,74) and controllermode) ) and allowtoggle ) then
    timer2 = timer2 + 1

    if ( timer2 == 60 )then
    if enabled then
    controllermode = not controllermode
    else
    controllermode = true
    end
    enabled = true
    allowtoggle = false
    timer2 = 0
    timer = 0
    end
    end

    if ( ( not (get_key_pressed(Keys.N) or CONTROLS.IS_CONTROL_PRESSED(2,74)) and timer2 > 0 ) and allowtoggle ) then
    if timer2 < 60 then
    enabled = not enabled
    timer = 0
    timer2 = 0
    allowtoggle = false
    end
    end


    if ( enabled ) then


    if controllermode then
    UI.SET_TEXT_FONT(0)
    UI.SET_TEXT_SCALE(0.1, 0.35)
    UI.SET_TEXT_COLOUR(255, 255, 255, 255)
    UI.SET_TEXT_CENTRE(true)
    UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)
    UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)
    UI._SET_TEXT_ENTRY("STRING")
    UI._ADD_TEXT_COMPONENT_STRING("Noclip Enabled - Controller (Beta)")
    UI._DRAW_TEXT(0.1,0.1)
    else
    UI.SET_TEXT_FONT(0)
    UI.SET_TEXT_SCALE(0.1, 0.35)
    UI.SET_TEXT_COLOUR(255, 255, 255, 255)
    UI.SET_TEXT_CENTRE(true)
    UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)
    UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)
    UI._SET_TEXT_ENTRY("STRING")
    UI._ADD_TEXT_COMPONENT_STRING("Noclip Enabled - M+Keyboard")
    UI._DRAW_TEXT(0.1,0.1)
    end

    if get_key_pressed(Keys.J) or get_key_pressed(Keys.K) then
    UI.SET_TEXT_FONT(0)
    UI.SET_TEXT_SCALE(0.1, 0.35)
    UI.SET_TEXT_COLOUR(255, 255, 255, 255)
    UI.SET_TEXT_CENTRE(true)
    UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)
    UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)
    UI._SET_TEXT_ENTRY("STRING")
    UI._ADD_TEXT_COMPONENT_STRING("Speed Multiplier: " .. tostring(speedmult))
    UI._DRAW_TEXT(0.1,0.12)
    end

    if get_key_pressed(Keys.J) then
    speedmult = speedmult + 0.01
    end
    if get_key_pressed(Keys.K) then
    if speedmult > 0 then
    speedmult = speedmult - 0.01
    end
    end

    if controllermode == false then

    ENTITY.SET_ENTITY_MAX_SPEED(player, 0)

    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if (not vehiclecheck) then

    vehiclerotation = 0

    ENTITY.SET_ENTITY_COLLISION(vehicle, true, true)

    if ( get_key_pressed(Keys.W) or get_key_pressed(Keys.A) or get_key_pressed(Keys.D) or get_key_pressed(Keys.S)) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x + ENTITY.GET_ENTITY_FORWARD_X(detentity)*speedmult, position.y + ENTITY.GET_ENTITY_FORWARD_Y(detentity)*speedmult, (position.z - 1), true, true, true, true)
    end

    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.LShiftKey) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x, position.y, ((position.z - 1) + 0.5*speedmult), true, true, true, true)
    end

    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.LControlKey) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x, position.y, ((position.z - 1) - 0.5*speedmult), true, true, true, true)
    end

    elseif vehiclecheck then

    ENTITY.SET_ENTITY_COLLISION(vehicle, false, false)
    ENTITY.SET_ENTITY_MAX_SPEED(vehicle, 0)

    local rotation = ENTITY.GET_ENTITY_ROTATION(detentity, true)
    if (vehiclerotation < 1) and (vehiclerotation > -1) then
    local vehiclerotation = rotation.z
    end
    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.W) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x + ENTITY.GET_ENTITY_FORWARD_X(detentity)*speedmult, position.y + ENTITY.GET_ENTITY_FORWARD_Y(detentity)*speedmult, (position.z - 0.6), false, false, false, false)
    end

    if ( get_key_pressed(Keys.S) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x - ENTITY.GET_ENTITY_FORWARD_X(detentity)*speedmult, position.y - ENTITY.GET_ENTITY_FORWARD_Y(detentity)*speedmult, (position.z - 0.6), false, false, false, false)
    end

    local rotation = ENTITY.GET_ENTITY_ROTATION(detentity, true)
    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.A) ) then
    vehiclerotation = vehiclerotation + 1
    end

    local rotation = ENTITY.GET_ENTITY_ROTATION(detentity, true)
    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.D) ) then
    vehiclerotation = vehiclerotation - 1
    end

    ENTITY.SET_ENTITY_ROTATION(detentity, 0, 0, vehiclerotation, 0, true)

    local rotation = ENTITY.GET_ENTITY_ROTATION(detentity, true)
    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.LShiftKey) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x, position.y, ((position.z + 4) + 0.5*speedmult), true, true, true, true)
    end

    local rotation = ENTITY.GET_ENTITY_ROTATION(detentity, true)
    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( get_key_pressed(Keys.LControlKey) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x, position.y, ((position.z - 4) - 0.5*speedmult), true, true, true, true)
    end

    end


    else

    ENTITY.SET_ENTITY_MAX_SPEED(player, 1.5)

    if (speed > 0.4) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x + ENTITY.GET_ENTITY_FORWARD_X(detentity)*speedmult, position.y + ENTITY.GET_ENTITY_FORWARD_Y(detentity)*speedmult, (position.z - 1), true, true, true, true)
    end

    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( CONTROLS.IS_CONTROL_PRESSED(2,183) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x, position.y, ((position.z - 1) + 0.5*speedmult), true, true, true, true)
    end

    local position = ENTITY.GET_ENTITY_COORDS(detentity, true)
    local direction = ENTITY.GET_ENTITY_FORWARD_VECTOR(detentity)

    if ( CONTROLS.IS_CONTROL_PRESSED(2,185) ) then
    ENTITY.SET_ENTITY_COORDS(detentity, position.x, position.y, ((position.z - 1) - 0.5*speedmult), true, true, true, true)
    end

    end

    if (not vehiclecheck) then
    local position = ENTITY.GET_ENTITY_COORDS(player, true)
    if jumping or falling or (parastate == 0) then
    ENTITY.SET_ENTITY_COORDS(player, position.x, position.y, (position.z - 1), false, false, false, false)

    end
    end

    ENTITY.SET_ENTITY_VELOCITY(detentity, 0, 0, 0)

    --Just testing stuff, probably isn't good for anything.
    --[[if ( CONTROLS.IS_CONTROL_PRESSED(2,87) or CONTROLS.IS_CONTROL_PRESSED(2,65) or CONTROLS.IS_CONTROL_PRESSED(2,68) or CONTROLS.IS_CONTROL_PRESSED(2,83)) then
    ENTITY.SET_ENTITY_COORDS(player, position.x + ENTITY.GET_ENTITY_FORWARD_X(player), position.y + ENTITY.GET_ENTITY_FORWARD_Y(player), (position.z - 1), true, true, true, true)
    end]]



    else

    ENTITY.SET_ENTITY_MAX_SPEED(player, 500)

    vehiclerotation = 0
    if vehiclecheck then
    ENTITY.SET_ENTITY_COLLISION(vehicle, true, true)
    ENTITY.SET_ENTITY_MAX_SPEED(vehicle, 500)
    end

    end
    end

    return noclip
     
    Admixon likes this.
  2. Grand Theft Auto 5 and most if not all the Saints Row games use Lua Script, this script is from GTA5:
    Code (Text):

        local noclip = {}
        function noclip.unload()
        end
        noclip.loaded = false
        noclip.speed = 1
        noclip.keyTimeout = 300
        noclip.useGround = false
        noclip.enabled = false
        noclip.zSpeed = 2
        noclip.levelDistance = 2
       
        function noclip.tick()
       
            if (get_key_pressed(Keys.F10)) then
                noclip.enabled = not noclip.enabled
                print("No Clip: " .. (noclip.enabled and 'On' or 'Off') )
                wait(noclip.keyTimeout)
            end
         
            if (noclip.enabled) then
             
                local playerPed = PLAYER.PLAYER_PED_ID()
                local isUsingVeh = false
                if (PED.GET_VEHICLE_PED_IS_IN(playerPed,false) ~= 0) then
                    playerPed = PED.GET_VEHICLE_PED_IS_IN(playerPed,false)
                    isUsingVeh = true
                end
             
                if (ENTITY.DOES_ENTITY_EXIST(playerPed)) then
             
                    local playerPosition = ENTITY.GET_ENTITY_COORDS(playerPed, false)
                 
                    local newPosition = { x=playerPosition.x, y=playerPosition.y, z=playerPosition.z-1 }
                 
                    local cam1Heading = CAM.GET_GAMEPLAY_CAM_RELATIVE_HEADING()
                    local cam1Pitch = CAM.GET_GAMEPLAY_CAM_RELATIVE_PITCH()
                 
                    local xOffset = 0
                 
                    -- Adjust player direction to camera direction
                    ENTITY.SET_ENTITY_HEADING(playerPed, ENTITY.GET_ENTITY_HEADING(playerPed)+cam1Heading)
                    -- Attempt to fix any animations which will destroy character functionality
                    PED.SET_PED_MOVE_ANIMS_BLEND_OUT(playerPed)
                    -- Do not let the player go all ragdolly
                    PED.SET_PED_CAN_RAGDOLL(playerPed, false)
                 
                 
                 
                    -- TILDE (~) toggles ground
                    if (get_key_pressed(Keys.Oemtilde)) then
                        noclip.useGround = not noclip.useGround
                        print("No Clip: [Use Ground]: " .. (noclip.useGround and 'On' or 'Off') )
                        wait(noclip.keyTimeout)
                    end
                 
                    -- SHIFT ramps up the speed
                    if (get_key_pressed(Keys.LShiftKey)) then
                        -- Toggle through 7 settings
                        noclip.speed = ((noclip.speed + 1) % 9) + 1
                        print("No Clip: [Speed]: " .. noclip.speed )
                        wait(noclip.keyTimeout)
                    end
                 
                    -- A = Strafe Left
                    if (get_key_pressed(Keys.A)) then
                        xOffset = -1
                    -- D = Strafe Right
                    elseif (get_key_pressed(Keys.D)) then
                        xOffset = 1
                    end
                 
                    -- W KEY = Forwards
                    if (get_key_pressed(Keys.W)) then
                        newPosition = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(playerPed, xOffset+-math.sin(math.rad(cam1Heading)), noclip.speed, -1 + (math.sin(math.rad(cam1Pitch))*noclip.zSpeed))      
                 
                    -- S KEY = Backwards .. Backwards is weird right now... camera is goofy. I'll fix this later.
                    elseif (get_key_pressed(Keys.S)) then
                        newPosition = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(playerPed, xOffset-math.sin(math.rad(cam1Heading)), 0-noclip.speed, -1 + (math.sin(math.rad(cam1Pitch))*noclip.zSpeed))
                        -- @@@ Fix this later
                        --CAM.SET_GAMEPLAY_CAM_RELATIVE_HEADING(cam1Heading)
                        --ENTITY.SET_ENTITY_ROTATION(playerPed, entityRotation.x, entityRotation.y, entityRotation.z, 1, true)
                    else
                        newPosition = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(playerPed, xOffset, 0, -1)      
                    end
                 
                    -- Adjust Z coordinate if using ground
                    if (noclip.useGround) then
                     
                        local startZ = 1
                        local endZ = 800
                        local stepZ = 1
                     
                        -- SPACE = Up a level (attempt)
                        if (get_key_pressed(Keys.Space)) then
                            stepZ = noclip.levelDistance
                     
                        -- Left CTRL = Down a level (attempt)
                        elseif (get_key_pressed(Keys.LControlKey)) then
                            stepZ = -noclip.levelDistance
                            startZ = -noclip.levelDistance
                            endZ = -800
                        end
                     
                        for i=startZ,endZ,stepZ do
                     
                            local height = select(2, GAMEPLAY.GET_GROUND_Z_FOR_3D_COORD(newPosition.x, newPosition.y, newPosition.z + i, 0))
                            if (height > 0) then
                                if (get_key_pressed(Keys.Space) and height > newPosition.z+1) then
                                    print("UP LEVEL Z: " .. height .. " at " .. i)
                                    newPosition.z = height
                                    break
                                elseif (get_key_pressed(Keys.LControlKey) and height < newPosition.z-1) then
                                    print("DOWN LEVEL Z: " .. height .. " at " .. i)
                                    newPosition.z = height
                                    break
                                elseif ((not get_key_pressed(Keys.Space)) and (not get_key_pressed(Keys.LControlKey))) then
                                    newPosition.z = height
                                    break
                                end
                            end
                        end
                 
                    -- When not using ground, can move up and down with SPACE/LCTRL
                    else
                        -- SPACE = Jump
                        if (get_key_pressed(Keys.Space)) then
                            newPosition.z = newPosition.z + 1
                     
                        -- Left CTRL = Duck
                        elseif (get_key_pressed(Keys.LControlKey)) then
                            newPosition.z = newPosition.z - 1
                        end
                    end
                 
                    -- Set position
                    ENTITY.SET_ENTITY_COORDS(playerPed, newPosition.x, newPosition.y, newPosition.z, true, true, true, true)
                 
                    if (noclip.useGround and (get_key_pressed(Keys.Space) or get_key_pressed(Keys.LControlKey))) then
                        wait(noclip.keyTimeout)
                    end
                end
            end
        end
        return noclip
     
     
    Last edited: Oct 4, 2017