Jump to content

Ghostmode Problem!


Recommended Posts

Everything works fine except the part when we reach a certain checkpoint with vehicles around the player..The ghostmode should be enabled until nobody is around. It just doesn't work..The ghostmode disables no matter the distance between vehicles. Please help me out here, thanks.

the script :

addEvent("onPlayerReachCheckpoint") 
addEventHandler("onPlayerReachCheckpoint",root, 
   function (cp) 
    if  cp == 7 then  
          outputChatBox ( "#FF0000Disabling Ghostmode at the next checkpoint!", source, 255, 255, 255, true ) 
        end 
          
      if cp == 8 then 
        
    local playerX, playerY, playerZ = getElementPosition(source) 
    local vehicles = getElementsByType("vehicle") 
    for k,v in ipairs(vehicles) do 
        local vehicleX, vehicleY, vehicleZ = getElementPosition(v) 
        -- get the distance between the player and the vehicle: 
        local distance = tostring(getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ)) 
        if (distance < tostring(20)) then 
            cancelEvent() 
            else 
            setElementData( source, "overrideCollide.uniqueblah", 255, false ) 
            setElementData( source, "overrideAlpha.uniqueblah", 255, false)  
            outputChatBox ( "#FF0000Ghostmode has been disabled!", source, 255, 255, 255, true )  
        end 
    end 
end 
         
         end 
   ) 

Link to comment

tostring in numbers? Good job lol

addEvent ( 'onPlayerReachCheckpoint', true ) 
addEventHandler ( 'onPlayerReachCheckpoint', root, 
    function ( eCheckpoint ) 
        if ( eCheckpoint == 7 ) then 
            outputChatBox ( '#FF0000Disabling GhostMode at the next checkpoint!', source, 255, 255, 255, true ) 
        end 
         
        if ( eCheckpoint == 8 ) then 
            local fX, fY, fZ = getElementPosition ( source ) 
            for _, pVehicle in ipairs ( getElementsByType 'vehicle' ) do 
                local fVehicleX, fVehicleY, fVehicleZ = getElementPosition ( pVehicle ) 
                local fDistance = getDistanceBetweenPoints3D ( iVehicleX, iVehicleY, iVehicleZ, iX, iY, iZ ) 
                if ( fDistance <= 20 ) then 
                    return 
                end 
            end 
            setElementData ( source, 'overrideCollide.uniqueblah', 255, false ) 
            setElementData ( source, 'overrideAlpha.uniqueblah', 255, false ) 
            outputChatBox ( '#FF0000GhostMode has been disabled!', source, 255, 255, 255, true ) 
        end 
    end 
) 

Not tested. It will disable ghostmode if vehicles distance are bigger than 20. Note that this will only happens when you reach a checkpoint, not everytime the distance is major / minor.

Link to comment

I re edited but the problem still remains, no erros at all, the script seems to be including the source vehicle too, how can I make it ignore

addEvent ( 'onPlayerReachCheckpoint', true ) 
addEventHandler ( 'onPlayerReachCheckpoint', root, 
    function ( eCheckpoint ) 
        if ( eCheckpoint == 1 ) then 
            outputChatBox ( '#FF0000Disabling GhostMode at the next checkpoint!', source, 255, 255, 255, true ) 
        end 
        
        if ( eCheckpoint == 2 ) then 
            local fX, fY, fZ = getElementPosition ( source ) 
            for _, pVehicle in ipairs ( getElementsByType 'vehicle' ) do 
                local fVehicleX, fVehicleY, fVehicleZ = getElementPosition ( pVehicle ) 
                local fDistance = getDistanceBetweenPoints3D ( fVehicleX, fVehicleY, fVehicleZ, fX, fY, fZ ) 
                if ( fDistance <= 20 ) then 
                outputChatBox ( '#FF0000players around!', source, 255, 255, 255, true ) 
                    return 
                end 
            end 
            setElementData ( source, 'overrideCollide.uniqueblah', 255, false ) 
            setElementData ( source, 'overrideAlpha.uniqueblah', 255, false ) 
            outputChatBox ( '#FF0000GhostMode has been disabled!', source, 255, 255, 255, true ) 
        end 
    end 
) 

Link to comment
Check conditions. Also, is the event being called?

i'm not sure what do you mean, but when i reach the second checkpoint it outputs the text, even though there are no vehicles around my car, i tried with more than one players online and without anyone. It should disable the ghostmode. It doesn't show any kind of erros on debug mode, sorry but...as you see here, i'm a noob at this

Link to comment
Check value returned by getDistanceBetweenPoints3D.

3553.3244846787

247.96236788842

0

i used this: outputChatBox(tostring(fDistance))

edit: the other player ( virtual machine) was at the start line, far enough and i tried at a close distance,

3553.4269125745

0

Link to comment
Oh, I know now. The loop is comparing your vehicle position too.

so, the source is my player? I tried this : local iX, iY, iZ = getElementPosition (getPedOccupiedVehicle ( source ) )

but the values are almost the same as the other ones, it still says there are vehicles around me

Link to comment

No, no, no. You should pass to next index on table if it's your vehicle.

Try that:

addEvent ( 'onPlayerReachCheckpoint', true ) 
addEventHandler ( 'onPlayerReachCheckpoint', root, 
    function ( eCheckpoint ) 
        if ( eCheckpoint == 1 ) then 
            outputChatBox ( '#FF0000Disabling GhostMode at the next checkpoint!', source, 255, 255, 255, true ) 
        end 
        
        if ( eCheckpoint == 2 ) then 
            doLoop ( 1, source ) 
        end 
    end 
) 
  
function doLoop ( index, player ) 
    for iCount = index, #getElementsByType 'vehicle' do  
        if ( getElementsByType 'vehicle' [ iCount ] == getPedOccupiedVehicle ( player ) ) then 
            doLoop ( iCount + 1, player ) 
            break 
        end 
        local pVehicle = getElementsByType 'vehicle' [ iCount ] 
        local fX, fY, fZ = getElementPosition ( player ) 
        local fVehicleX, fVehicleY, fVehicleZ = getElementPosition ( pVehicle ) 
        local fDistance = getDistanceBetweenPoints3D ( fVehicleX, fVehicleY, fVehicleZ, fX, fY, fZ ) 
        if ( fDistance <= 20 ) then 
            outputChatBox ( '#FF0000players around!', source, 255, 255, 255, true ) 
            return 
        end 
    end 
    setElementData ( source, 'overrideCollide.uniqueblah', 255, false ) 
    setElementData ( source, 'overrideAlpha.uniqueblah', 255, false ) 
    outputChatBox ( '#FF0000GhostMode has been disabled!', source, 255, 255, 255, true ) 
end 

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