Jump to content

Need help; unlocking vehicle outside it, turn signals


Play3rPL

Recommended Posts

Hello!

Thanks for coming here. First at all, let me say that my English is not perfect, so it can be bad sometimes. :P

Okay. I am asking You for help with two things:

1#: Unlocking locked vehicle outside it.

Look: I made my own script for my RPG server; it allows You to enable lights using ; key, engine using K, enable Freeze-aka-handbrake using RCTRL, and lock vehicle using L key. Only driver can perform these things.

So, there is my question:

When car is locked, and You will exit that, You cannot unlock it anymore. I want to make script, that will allow You to unlock it, when ped is standing next to driver's doors using L key again. How can I script that?

I have been thinking of making an INVISIBLE marker, next to driver's door. When ped will stay at it, he is able to unlock it using L key.

Marker could be done by taking vehicle's x, y, z, and adding some numbers to x/y. But how can I do it invisible? VisibleTo function, or anything else? And how Can I cause unlock by using L?

2#: Turn signals.

It's kinda important thing for RPG servers. Actually, I have no clue about making them. Using SetLightState probably, but I'm do not understand the use of them.

--------------------------------

I am NOT asking for ready code; I'm asking for help and some clues about doing these things.

Here's my actual code. I'm going to show it also to prove, that I actually did something:

-------------------------------------- KONTROLKI - 8.0 
  
local root = getRootElement () 
local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        bindKey ( v, ";", "down", toggleVehicleLights, "Lights on/off" ) 
                bindKey ( v, "k", "down", toggleVehicleEngine, "Engine on/off" ) 
                bindKey ( v, "rctrl", "down", toggleVehicleHandbrake, "Handbrake on/off") 
                bindKey ( v, "l", "down", toggleVehicleLock, "Doors locked/unlocked") 
    end 
end 
  
  
  
function playerJoin () 
        bindKey ( v, ";", "down", toggleVehicleLights, "Lights on/off" ) 
                bindKey ( v, "k", "down", toggleVehicleEngine, "Engine on/off" ) 
                bindKey ( v, "rctrl", "down", toggleVehicleHandbrake, "Handbrake on/off") 
                bindKey ( v, "l", "down", toggleVehicleLock, "Doors locked/unlocked") 
end 
  
addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) 
addEventHandler ( "onPlayerJoin", root, playerJoin ) 
-- Lampy 
function toggleVehicleLights ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
        if ( getVehicleOverrideLights ( veh ) ~= 2 ) then 
            setVehicleOverrideLights ( veh, 2 ) 
            outputChatBox ( "Światła Włączone!", player, 0, 255, 0 ) 
        else 
            setVehicleOverrideLights ( veh, 1 ) 
            outputChatBox ( "Światła Wyłączone!", player, 255, 0, 0 ) 
        end 
    end 
end 
-- Silnik 
function toggleVehicleEngine ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
        if ( getVehicleEngineState ( veh ) == true ) then 
            setVehicleEngineState ( veh, false ) 
                        outputChatBox ( "Silnik Wyłączony!", player, 255, 0, 0 ) 
        else 
            setVehicleEngineState ( veh, true ) 
                        outputChatBox ( "Silnik Włączony!", player, 0, 255, 0 ) 
        end 
    end 
end 
-- Ręczny 
function toggleVehicleHandbrake ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
                local speed = getElementVelocity ( veh ) 
                if ( speed == 0 ) then 
                        if ( isElementFrozen ( veh ) == false ) then 
                                setElementFrozen ( veh, true ) 
                                outputChatBox ( "Ręczny Zaciągnięty!", player, 255, 0, 0 ) 
                        else 
                                setElementFrozen ( veh, false ) 
                                outputChatBox ( "Ręczny Spuszczony!", player, 0, 255, 0 ) 
                        end 
                else 
                        setControlState( player, handbrake, true) 
                end                     
    end 
end 
-- Zamek 
function toggleVehicleLock ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
        if ( isVehicleLocked( veh ) == false ) then 
            setVehicleLocked ( veh, true ) 
                        outputChatBox ( "Pojazd Zamknięty!", player, 255, 0, 0 ) 
        else 
            setVehicleLocked ( veh, false ) 
                        outputChatBox ( "Pojazd Otwarty!", player, 0, 255, 0 ) 
        end 
    end 
end 

I'm sorry for Polish chat outputs and --s; script is done one hundred % by me.

Thanks, again, for any help!

Cheers,

Play3rPL

Link to comment

idk if its works the marker make it visible and try to find where is close to door

function toggleVehicleLock(thePlayer, key, state) 
    if (getPedOccupiedVehicleSeat(thePlayer)== 0) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        if isVehicleLocked(veh) == false then 
           setVehicleLocked(veh, true) 
        else 
           setVehicleLocked(veh, false) 
        end 
        local x, y, z = getElementPosition(veh) 
        local marker = createMarker(x+5, y, z, "cylinder", 1, 255, 0, 0, 0) 
    end 
end 
        addEventHandler("onMarkerHit", getRootElement(), 
           function() 
               if isPedInVehicle(thePlayer) == false then 
                  if isVehicleLocked(veh, true) and state == "down" then 
                     setVehicleLocked(veh, false) 
                  end 
               end 
            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...