Andres99907

Help me :( in my script pls.

Recommended Posts

I´m creating this script :) 

This script mimics the operation of the machine Gun of Valkyrie helicopter 

is this : 

restrictedTo = 488

 
 bindKey ( "o", "down",  function ( thePlayer, seat)
 local vehicle = getPedOccupiedVehicle ( localPlayer )
 if ( vehicle and getElementModel (vehicle)  == restrictedTo ) then
 x,y,z = getElementPosition(getLocalPlayer())
 if not createProjectile(getLocalPlayer(), 19, x, y, z - 5, 1, nil, nil, nil, nil, -1, -1, -1, 0) then
 end
 end
 end
 )

 

but only the passengers can use the mg , the driver cannot >:( 

can you help me? 

only the passenger can use the mg  but it's not like that.

Share this post


Link to post

Your code is makes no sense in here from what i see also please use Code editor to post a code and select Lua.

  • Like 2

Share this post


Link to post

So you want to restrict the command to passengers only? If so, here's the code:

 

bindKey ( "o", "down",  function ( thePlayer, seat)
    local vehicle = getPedOccupiedVehicle ( localPlayer )
    if ( vehicle and getElementModel (vehicle) == restrictedTo and getPedOccupiedVehicle (localPlayer) ~= 0) then -- seat 0 -> driver
    x,y,z = getElementPosition(getLocalPlayer())
    if not createProjectile(getLocalPlayer(), 19, x, y, z - 5, 1, nil, nil, nil, nil, -1, -1, -1, 0) then
        end
    end
end)

I changed line 3 so it checks if the player is not the driver. 

  • Like 1

Share this post


Link to post

getPedOccupiedVehicle returns the vehicle element or false - not the seat. To get the seat you need to use getPedOccupiedVehicleSeat.

Also, you're not using bindKey properly. You're using the client-sided version which returns the key pressed and then the state. So in this case, thePlayer would return "o" and seat would return "down" or "up".

  • Like 2

Share this post


Link to post

Yea, sorry, my bad, was meant to use getPedOccupiedVehicleSeat (localPlayer) ~= 0

 

He has thePlayer and seat there for no reason, he is not actually using it in the code anyway.

  • Like 1

Share this post


Link to post
local restrictedTo = {[488]=true}

function functionName()
    if isPedInVehicle(localPlayer) then
        local vehicle = getPedOccupiedVehicle (localPlayer)
        local model = getElementModel(vehicle)
        local seat = getPedOccupiedVehicleSeat(localPlayer)
        if (restrictedTo[model] and seat ~= 0) then 
            local x,y,z = getElementPosition(localPlayer)
            createProjectile(localPlayer, 19, x, y, z + 2, 1, nil, nil, nil, nil, -1, -1, -1, 0) 
        end
    end 
end
bindKey ("o", "down",functionName)

 

  • Like 4

Share this post


Link to post

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.