Jump to content

[Help] Warping into Vehicle


Recommended Posts

How can i completly disable warping into vehicle. so when someone try to warp into vehicle it will warp him as normal, not inside vehicle?

if anyone know, please help me.

thanks.


 

function warpMe(targetPlayer)
    if getElementData ( source, "attached" ) then return end
    if isPedDead(source) then
        spawnMe()
    end

    local vehicle = getPedOccupiedVehicle(targetPlayer)
    if not vehicle then
        -- target player is not in a vehicle - just warp next to him
        local x, y, z = getElementPosition(targetPlayer)
        clientCall(source, 'setPlayerPosition', x + 2, y, z)
    else
        -- target player is in a vehicle - warp into it if there's space left
        if getPedOccupiedVehicle(source) then
            --removePlayerFromVehicle(source)
            outputChatBox('Get out of your vehicle first.', source)
            return
        end
        local numseats = getVehicleMaxPassengers(vehicle)
        for i=0,numseats do
            if not getVehicleOccupant(vehicle, i) then
                if isPedDead(source) then
                    local x, y, z = getElementPosition(vehicle)
                    spawnMe(x + 4, y, z + 1)
                end
                warpPedIntoVehicle(source, vehicle, i)
                return
            end
        end
        outputChatBox('No free seats left in ' .. getPlayerName(targetPlayer) .. '\'s vehicle.', source, 255, 0, 0)
    end
    local interior = getElementInterior(targetPlayer)
    setElementInterior(source, interior)
    setCameraInterior(source, interior)
end

 

Link to comment

Try this. (Assuming spawnMe is a function which exists and sets the player's position.)

function warpMe(targetPlayer)
    if getElementData ( source, "attached" ) then return end
    if isPedDead(source) then
        spawnMe()
    end

    local vehicle = getPedOccupiedVehicle(targetPlayer)
    if not vehicle then
        -- target player is not in a vehicle - just warp next to him
        local x, y, z = getElementPosition(targetPlayer)
        clientCall(source, 'setPlayerPosition', x + 2, y, z)
    else
        -- target player is in a vehicle - warp into it if there's space left
        if getPedOccupiedVehicle(source) then
            --removePlayerFromVehicle(source)
            outputChatBox('Get out of your vehicle first.', source)
            return
        end
    	local x, y, z = getElementPosition(vehicle)
    	spawnMe(x, y + 3, z + 1)
    end
    local interior = getElementInterior(targetPlayer)
    setElementInterior(source, interior)
    setCameraInterior(source, interior)
end

 

Edited by Skully
  • Thanks 1
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...