Jump to content

Autowarp into Vehicle - Race


'LinKin

Recommended Posts

Hello,

I've made this fun resource. It's purpose is to remove a ped from his vehicle.

function leaveVehicle(thePlayer) 
    outputChatBox("Command Executed") 
    for i, player in ipairs (getElementsByType("player")) do 
        if player == thePlayer then 
            outputChatBox("Player = Source") 
            if isPedInVehicle (player) then 
                outputChatBox("Ejecting...") 
                removePedFromVehicle ( player ) 
            end 
        end 
    end 
end 
addCommandHandler("eject", leaveVehicle) 

Works fine, but I've got one trouble.

As soon as the player is removed from the vehicle, something auto-warps him again into his vehicle. I think it has something to do with Race scripts. But I'm not sure...

Debugscript 3 ouputs this: INFO: Warping player into vehicle for |GMC|LinKin

How can I avoid this auto-warping after removing the player from the vehicle?

Link to comment
------------------------ 
-- Keep players in vehicles 
g_checkPedIndex = 0 
  
TimerManager.createTimerFor("raceresource","warppeds"):setTimer( 
    function () 
        -- Make sure all players are in a vehicle 
        local maxCheck = 6      -- Max number to check per call 
        local maxWarp = 3       -- Max number to warp per call 
  
        local warped = 0 
        for checked = 0, #g_Players - 1 do 
            if checked >= maxCheck or warped >= maxWarp then 
                break 
            end 
            g_checkPedIndex = g_checkPedIndex + 1 
            if g_checkPedIndex > #g_Players then 
                g_checkPedIndex = 1 
            end 
            local player = g_Players[g_checkPedIndex] 
            if not getPedOccupiedVehicle(player) then 
                local vehicle = g_Vehicles[player] 
                if vehicle and isElement(vehicle) and not isPlayerRaceDead(player) then 
                    outputDebugString( "Warping player into vehicle for " .. tostring(getPlayerName(player)) ) 
                    warpPedIntoVehicle( player, vehicle ) 
                    warped = warped + 1 
                end 
            end 
        end 
    end, 
    50,0 
) 

That's the code that warps the players back into their vehicles, is inside "race/race_server.lua".

Link to comment
------------------------ 
-- Keep players in vehicles 
g_checkPedIndex = 0 
  
TimerManager.createTimerFor("raceresource","warppeds"):setTimer( 
    function () 
        -- Make sure all players are in a vehicle 
        local maxCheck = 6      -- Max number to check per call 
        local maxWarp = 3       -- Max number to warp per call 
  
        local warped = 0 
        for checked = 0, #g_Players - 1 do 
            if checked >= maxCheck or warped >= maxWarp then 
                break 
            end 
            g_checkPedIndex = g_checkPedIndex + 1 
            if g_checkPedIndex > #g_Players then 
                g_checkPedIndex = 1 
            end 
            local player = g_Players[g_checkPedIndex] 
            if not getPedOccupiedVehicle(player) then 
                local vehicle = g_Vehicles[player] 
                if vehicle and isElement(vehicle) and not isPlayerRaceDead(player) then 
                    outputDebugString( "Warping player into vehicle for " .. tostring(getPlayerName(player)) ) 
                    warpPedIntoVehicle( player, vehicle ) 
                    warped = warped + 1 
                end 
            end 
        end 
    end, 
    50,0 
) 

That's the code that warps the players back into their vehicles, is inside "race/race_server.lua".

I think he wanted to remove ped from Vehicle.

here --

        function leaveVehicle (thePlayer) 
                local vehicle = getPedOccupiedVehicle(thePlayer) 
                if vehicle and isElement(vehicle) and not isPlayerRaceDead(thePlayer) then 
                    outputChatBox(getPlayerName(thePlayer).." is out from vehicle ) 
               removePedFromVehicle ( thePlayer ) 
end 
end 
addCommandHandler("eject", leaveVehicle) 
  
  
  
  
 

Link to comment

Thank you both.

I've managed to do it by commenting 2 lines in race_server.lua

--outputDebugString( "Warping player into vehicle for " .. tostring(getPlayerName(player)) )

--warpPedIntoVehicle( player, vehicle )

But I was wondering, is it possible to make a condition in race_server so that it doesn't execute these lines when my custom resource to eject a player from his vehicle is running?

Something like;

if not getResourceData(myscript,"state") == "Running" then

outputDebugString( "Warping player into vehicle for " .. tostring(getPlayerName(player)) )

warpPedIntoVehicle( player, vehicle )

end

Note: I know getResourceData function doesn't exist. It was just an example to make you understand what I am looking for.

Thanks in advance.

Link to comment
------------------------ 
-- Keep players in vehicles 
g_checkPedIndex = 0 
  
TimerManager.createTimerFor("raceresource","warppeds"):setTimer( 
    function () 
        -- Make sure all players are in a vehicle 
        local maxCheck = 6      -- Max number to check per call 
        local maxWarp = 3       -- Max number to warp per call 
  
        local warped = 0 
        for checked = 0, #g_Players - 1 do 
            if checked >= maxCheck or warped >= maxWarp then 
                break 
            end 
            g_checkPedIndex = g_checkPedIndex + 1 
            if g_checkPedIndex > #g_Players then 
                g_checkPedIndex = 1 
            end 
            local player = g_Players[g_checkPedIndex] 
            if not getPedOccupiedVehicle(player) then 
                local vehicle = g_Vehicles[player] 
                if vehicle and isElement(vehicle) and not isPlayerRaceDead(player) then 
                    outputDebugString( "Warping player into vehicle for " .. tostring(getPlayerName(player)) ) 
                    warpPedIntoVehicle( player, vehicle ) 
                    warped = warped + 1 
                end 
            end 
        end 
    end, 
    50,0 
) 

That's the code that warps the players back into their vehicles, is inside "race/race_server.lua".

I think he wanted to remove ped from Vehicle.

here --

        function leaveVehicle (thePlayer) 
                local vehicle = getPedOccupiedVehicle(thePlayer) 
                if vehicle and isElement(vehicle) and not isPlayerRaceDead(thePlayer) then 
                    outputChatBox(getPlayerName(thePlayer).." is out from vehicle ) 
               removePedFromVehicle ( thePlayer ) 
end 
end 
addCommandHandler("eject", leaveVehicle) 
  
  
  
  
  
 

I wasn't posting a solution, I was showing him what was causing the warping-back-to-vehicle problem.

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