Jump to content

GUI Visible While ped in specified Vehicle's


Zuher Laith

Recommended Posts

Hi ..

I'am making a Little script and i need your help with that ..

So my idea is when the player is in Police Vehicle (like specified vehicles list)

Then The GUI are Able to be Visible ( On bindkey )

and if not the player was in the Specified Vehicle , Then The GUI Won't Show Up ( On bindkey )

I Know that i should Use " isPedInVehicle ", but i don't know how to do it in the right way.

So Currently, I have the Bindkey functions & Works Fine:

------------------- 
--Key For Open Panel 
------------------- 
local key = "O"  
  
--------------------- 
--Key to Open Panel 
--------------------- 
  
open = false 
bindKey ( key, "down", 
function ( ) 
if open == false then 
add() 
for k,v in ipairs(mywind) do 
 guiSetVisible(v,true) 
 guiSetAlpha(mywind[13],0.89999997615814) 
end 
showCursor(true) 
open = true 
else 
close() 
guiSetAlpha(mywind[13],0) 
    end 
end 
) 
  
--------------------- 
--Close Panel 
--------------------- 
  
function close() 
for k,v in ipairs(mywind) do 
 guiSetVisible(v,false) 
end 
showCursor(false) 
open = false 
setCameraTarget ( getLocalPlayer() ) 
end 

what i want to do , is just make this work While Player In Specified Vehicle's

Any Help please ?..

Link to comment
Well, lets start with getting you the functions you need. It's a pretty simple solution, I'm sure you'll figure it out no problem.
isPedInVehicle -- This is optional due to the function below(false = not in a vehicle) 
getPedOccupiedVehicle 
getElementModel 

Can you give an example please ? because i don't know how to gather things up at here ..

also i am binding key at client side , and getElementModel works in server side ..

This is confusing a little bit ..

Link to comment

getElementModel also works client sided. Once the player presses the key, you should see if the ped is in a vehicle. I'm just not a fan of isPedInVehicle and therefore I'm always using getPedOccupiedVehicle. Once you got an element in there, you're a 100% sure that the ped is in a vehicle. As a simple setup to get you started;

local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ); 
if ( vehicle ) then 
    if ( getElementModel ( vehicle ) == allowed_model ) then 
        -- your code here 
    end 
end 

Link to comment
getElementModel also works client sided. Once the player presses the key, you should see if the ped is in a vehicle. I'm just not a fan of isPedInVehicle and therefore I'm always using getPedOccupiedVehicle. Once you got an element in there, you're a 100% sure that the ped is in a vehicle. As a simple setup to get you started;
local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ); 
if ( vehicle ) then 
    if ( getElementModel ( vehicle ) == allowed_model ) then 
        -- your code here 
    end 
end 

Hi ..

Thanks for Clearing up the Idea , got it ..

but i have one question please ,

I can i make a list of "allowed_model" ? like multiple ID's ..

Link to comment

If you would create a table and make the index equally to the vehicle model and always assign the value 'true' to it, you can use it to see if it's allowed. like so;

local allowedVehicles = { [ 599 ] = true }; 
if ( allowedVehicles [ getElementModel ( vehicle ) ] ) then 
    -- your code here 
end 

Link to comment
If you would create a table and make the index equally to the vehicle model and always assign the value 'true' to it, you can use it to see if it's allowed. like so;
local allowedVehicles = { [ 599 ] = true }; 
if ( allowedVehicles [ getElementModel ( vehicle ) ] ) then 
    -- your code here 
end 

Great ! ..

but i had a problem ..

--------------------- 
--Key to open panel 
--------------------- 
  
open = false 
bindKey ( key, "down", 
function ( ) 
if ( vehicle ) then 
    local allowedVehicles = { [ 599 ] = true }; 
    if ( allowedVehicles [ getElementModel ( vehicle ) ] ) then 
       if open == false then 
        add() 
        for k,v in ipairs(mywind) do 
         guiSetVisible(v,true) 
         guiSetAlpha(mywind[13],0.89999997615814) 
        end 
        showCursor(true) 
        open = true 
        else 
        close() 
        guiSetAlpha(mywind[13],0) 
        end 
    end 
end 
end 
) 

So when i bindkey , it does nothing and no error giving !

That's strange .. because it was working with the last example:

--------------------- 
--Key to open panel 
--------------------- 
  
open = false 
bindKey ( key, "down", 
function ( ) 
local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ); 
if ( vehicle ) then 
    if ( getElementModel ( vehicle ) == allowed_model ) then 
       if open == false then 
        add() 
    for k,v in ipairs(mywind) do 
     guiSetVisible(v,true) 
     guiSetAlpha(mywind[13],0.89999997615814) 
    end 
    showCursor(true) 
    open = true 
    else 
    close() 
    guiSetAlpha(mywind[13],0) 
        end 
        end 
    end 
  
end 
) 

Weird problem ..

Link to comment

An index is assigned with it's value after the = sign. You first index would've thrown an error since Lua is smart enough to find mistakes like that. If this wasn't the case, a model that equals to "490, 597, etc." would've triggered the function. Each model needs their own single index and value. (:

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