Jump to content

Problem with isPedInVehicle


AlexWo

Recommended Posts

Hi I made some Vehicle Spawnmakers and now I have the problem that if a player is in a vehicle and hits the marker he get the VehicleSelect GUI.

I don't want that... I tried already with some If clauses but it didn't worked.

This is the part of my Client script where I placed the IF:

function PoliceGUI (hitPlayer, matchingDimension ) 
         
        if isPedInVehicle ( hitPlayer) then 
        outputChatBox ( getPlayerName(hitPlayer) .. ", you have to leave your vehicle!", 255, 255, 0 ) 
        else 
     
         
         
    --Message that you enered the Marker 
    outputChatBox ( getPlayerName(hitPlayer) .. ", you entered the Police-Job Marker", 255, 255, 0 ) 
    --Window/GUI 
    policeWindow = guiCreateWindow ( 0.25, 0.25, 0.4, 0.4, "Policejob", true ) 
    --Tap Panel 
    policePanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, policeWindow ) 
    --Tab's 
    policeMap = guiCreateTab( "Job Information", policePanel )   
    scriptinformation = guiCreateTab( "Script Information", policePanel )   
    --PoliceTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "Welcome to the Police Department", true, policeMap) 
    guiCreateLabel(0.02, 0.08, 0.94, 0.92, "Press 'Accept' to accept the Job and get your Equipment", true, policeMap) 
    guiCreateLabel(0.02, 0.12, 0.94, 0.92, "Press 'Exit' to close this gui and exit", true, policeMap) 
    guiCreateLabel(0.065, 0.5, 0.94, 0.92, "Please choose a Skin:", true, policeMap) 
    guiCreateStaticImage( 350, 75, 350, 175, "images/police-tape.png", false, policeMap ) 
    
    
    LS = guiCreateRadioButton(50,200,100,16,"LS Skin",false, policeMap) 
        guiRadioButtonSetSelected(LS,true) 
    SF = guiCreateRadioButton(50,220,100,16,"SF Skin",false, policeMap) 
    LV = guiCreateRadioButton(50,240,100,16,"LV Skin", false, policeMap) 
  
  
    exitbutton = guiCreateButton( 0.5, 0.85, 0.2, 0.1, "Exit", true, policeMap ) 
    acceptbutton = guiCreateButton( 0.1, 0.85, 0.2, 0.1, "Accept", true, policeMap ) 
    showCursor ( true ) 
    
    --ScriptInformationTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This script is made by Alexander Wolf©", true, scriptinformation) 
    guiCreateLabel(0.02, 0.08, 0.94, 0.2, "Do you like my script? Visit my Website alexwo.com/scripting for more!", true, scriptinformation) 
    end 
end 

Maybe you can help me :o

This is my whole Client Side Script:

markers = 
    { 
        createMarker( -1620, 685, 6, "cylinder", 1.5, 0, 0, 255, 100), 
        createMarker( 2242, 2450, 9.75, "cylinder", 1.5 , 0, 0, 255, 100), 
        createMarker( 1555, -1675.5, 15.2, "cylinder", 1.5, 0, 0, 255, 100) 
        
    } 
  
vehiclemarkers = 
    {   
        createMarker( 1556, -1612, 12.5, "cylinder", 1.5, 0, 0, 255, 100), 
        createMarker( 1566, -1612, 12.5, "cylinder", 1.5, 0, 0, 255, 100) 
    } 
  
LSPoliceBlip = createBlip( 1554, -1675, 15, 30, 2) 
SFPoliceBlip = createBlip( -1620, 685, 8, 30, 2) 
LVPoliceBlip = createBlip( 2242, 2450, 11, 30, 2) 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        for _, marker in ipairs ( markers ) do 
        addEventHandler ( "onClientMarkerHit", marker, PoliceGUI ) 
        end 
    end 
) 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        for _, marker in ipairs ( vehiclemarkers ) do 
            addEventHandler ( "onClientMarkerHit", marker, vehiclegui ) 
        end 
    end 
) 
  
  
function PoliceGUI (hitPlayer, matchingDimension ) 
        PolicePlayer = getLocalPlayer() 
        if isPedInVehicle ( PolicePlayer) then 
        outputChatBox ( getPlayerName(PolicePlayer) .. ", you entered the Police-Job Marker", 255, 255, 0 ) 
        else 
     
         
         
    --Message that you enered the Marker 
    outputChatBox ( getPlayerName(hitPlayer) .. ", you entered the Police-Job Marker", 255, 255, 0 ) 
    --Window/GUI 
    policeWindow = guiCreateWindow ( 0.25, 0.25, 0.4, 0.4, "Policejob", true ) 
    --Tap Panel 
    policePanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, policeWindow ) 
    --Tab's 
    policeMap = guiCreateTab( "Job Information", policePanel )   
    scriptinformation = guiCreateTab( "Script Information", policePanel )   
    --PoliceTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "Welcome to the Police Department", true, policeMap) 
    guiCreateLabel(0.02, 0.08, 0.94, 0.92, "Press 'Accept' to accept the Job and get your Equipment", true, policeMap) 
    guiCreateLabel(0.02, 0.12, 0.94, 0.92, "Press 'Exit' to close this gui and exit", true, policeMap) 
    guiCreateLabel(0.065, 0.5, 0.94, 0.92, "Please choose a Skin:", true, policeMap) 
    guiCreateStaticImage( 350, 75, 350, 175, "images/police-tape.png", false, policeMap ) 
    
    
    LS = guiCreateRadioButton(50,200,100,16,"LS Skin",false, policeMap) 
        guiRadioButtonSetSelected(LS,true) 
    SF = guiCreateRadioButton(50,220,100,16,"SF Skin",false, policeMap) 
    LV = guiCreateRadioButton(50,240,100,16,"LV Skin", false, policeMap) 
  
  
    exitbutton = guiCreateButton( 0.5, 0.85, 0.2, 0.1, "Exit", true, policeMap ) 
    acceptbutton = guiCreateButton( 0.1, 0.85, 0.2, 0.1, "Accept", true, policeMap ) 
    showCursor ( true ) 
    
    --ScriptInformationTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This script is made by Alexander Wolf©", true, scriptinformation) 
    guiCreateLabel(0.02, 0.08, 0.94, 0.2, "Do you like my script? Visit my Website alexwo.com/scripting for more!", true, scriptinformation) 
    end 
end 
  
  
function wclose (state) 
 if state == "left" then 
  if source == exitbutton then 
    guiSetVisible(policeWindow, false) 
    showCursor(false) 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), wclose) 
  
function acceptjob (state) 
 if state == "left" then 
  if source == acceptbutton then 
    if(guiRadioButtonGetSelected(LS))then 
        triggerServerEvent("giveEquipmentLS", getLocalPlayer(), thePlayer) 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(SF))then 
        triggerServerEvent("giveEquipmentSF", getLocalPlayer(), thePlayer) 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
    elseif(guiRadioButtonGetSelected(LV))then 
        triggerServerEvent("giveEquipmentLV", getLocalPlayer(), thePlayer) 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    end 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), acceptjob) 
  
function vehiclegui (hitPlayer, matchingDimension ) 
PoliceVehicleWindow = guiCreateWindow ( 0.25, 0.25, 0.4, 0.4, "Police Vehicles", true ) 
    --Tap Panel 
    PoliceVehiclePanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, PoliceVehicleWindow ) 
    --Tab's 
    PoliceVehicleMap = guiCreateTab( "Vehicle List", PoliceVehiclePanel )     
    --PoliceTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "Please choose a vehicle you want to spawn!", true, PoliceVehicleMap) 
    --RadioButtons 
    policecarls = guiCreateRadioButton(20,40,100,16,"Police Car LS",false, PoliceVehicleMap) 
        guiRadioButtonSetSelected(policecarls,true) 
    policecarsf = guiCreateRadioButton(20,60,100,16,"Police Car SF",false, PoliceVehicleMap) 
    policecarlv = guiCreateRadioButton(20,80,100,16,"Police Car LV", false, PoliceVehicleMap) 
    policeranger = guiCreateRadioButton(20,100,100,16,"Police Ranger", false, PoliceVehicleMap) 
    hpv1000 = guiCreateRadioButton(20,120,100,16,"HPV1000", false, PoliceVehicleMap) 
     
    --Buttons 
    policevehicleexitbutton = guiCreateButton( 0.5, 0.85, 0.2, 0.1, "Exit", true, PoliceVehicleMap ) 
    spawnbutton = guiCreateButton( 0.1, 0.85, 0.2, 0.1, "Spawn", true, PoliceVehicleMap ) 
     
    --showCursor 
    showCursor ( true ) 
end 
  
function PoliceVehicleGUIclose (state) 
 if state == "left" then 
  if source == policevehicleexitbutton then 
    guiSetVisible(PoliceVehicleWindow, false) 
    showCursor(false) 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), PoliceVehicleGUIclose) 
  
  
function spawnpolicevehicle (state) 
 if state == "left" then 
  if source == spawnbutton then 
    if(guiRadioButtonGetSelected(policecarls))then 
        triggerServerEvent("spawnpolicecarls", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(policecarsf))then 
        triggerServerEvent("spawnpolicecarsf", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
    elseif(guiRadioButtonGetSelected(policecarlv))then 
        triggerServerEvent("spawnpolicecarlv", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(policeranger))then 
        triggerServerEvent("spawnpoliceranger", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(hpv1000))then 
        triggerServerEvent("spawnhpv1000", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    end 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), spawnpolicevehicle) 
  

Link to comment
markers = 
    { 
        createMarker( -1620, 685, 6, "cylinder", 1.5, 0, 0, 255, 100), 
        createMarker( 2242, 2450, 9.75, "cylinder", 1.5 , 0, 0, 255, 100), 
        createMarker( 1555, -1675.5, 15.2, "cylinder", 1.5, 0, 0, 255, 100) 
        
    } 
  
vehiclemarkers = 
    {   
        createMarker( 1556, -1612, 12.5, "cylinder", 1.5, 0, 0, 255, 100), 
        createMarker( 1566, -1612, 12.5, "cylinder", 1.5, 0, 0, 255, 100) 
    } 
  
LSPoliceBlip = createBlip( 1554, -1675, 15, 30, 2) 
SFPoliceBlip = createBlip( -1620, 685, 8, 30, 2) 
LVPoliceBlip = createBlip( 2242, 2450, 11, 30, 2) 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        for _, marker in ipairs ( markers ) do 
            addEventHandler ( "onClientMarkerHit", marker, PoliceGUI ) 
        end 
  
        for _, marker in ipairs ( vehiclemarkers ) do 
            addEventHandler ( "onClientMarkerHit", marker, vehiclegui ) 
        end 
    end 
) 
  
function PoliceGUI (hitPlayer, matchingDimension ) 
    if ( hitPlayer ~= localPlayer ) then 
        return 
    end 
  
    if isPedInVehicle ( localPlayer ) then 
        outputChatBox ( getPlayerName ( localPlayer ) .. ", you entered the Police-Job Marker", 255, 255, 0 ) 
    else 
    
        
        
    --Message that you enered the Marker 
    outputChatBox ( getPlayerName(hitPlayer) .. ", you entered the Police-Job Marker", 255, 255, 0 ) 
    --Window/GUI 
    policeWindow = guiCreateWindow ( 0.25, 0.25, 0.4, 0.4, "Policejob", true ) 
    --Tap Panel 
    policePanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, policeWindow ) 
    --Tab's 
    policeMap = guiCreateTab( "Job Information", policePanel )   
    scriptinformation = guiCreateTab( "Script Information", policePanel )   
    --PoliceTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "Welcome to the Police Department", true, policeMap) 
    guiCreateLabel(0.02, 0.08, 0.94, 0.92, "Press 'Accept' to accept the Job and get your Equipment", true, policeMap) 
    guiCreateLabel(0.02, 0.12, 0.94, 0.92, "Press 'Exit' to close this gui and exit", true, policeMap) 
    guiCreateLabel(0.065, 0.5, 0.94, 0.92, "Please choose a Skin:", true, policeMap) 
    guiCreateStaticImage( 350, 75, 350, 175, "images/police-tape.png", false, policeMap ) 
    
    
    LS = guiCreateRadioButton(50,200,100,16,"LS Skin",false, policeMap) 
        guiRadioButtonSetSelected(LS,true) 
    SF = guiCreateRadioButton(50,220,100,16,"SF Skin",false, policeMap) 
    LV = guiCreateRadioButton(50,240,100,16,"LV Skin", false, policeMap) 
  
  
    exitbutton = guiCreateButton( 0.5, 0.85, 0.2, 0.1, "Exit", true, policeMap ) 
    acceptbutton = guiCreateButton( 0.1, 0.85, 0.2, 0.1, "Accept", true, policeMap ) 
    showCursor ( true ) 
    
    --ScriptInformationTab 
    guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This script is made by Alexander Wolf©", true, scriptinformation) 
    guiCreateLabel(0.02, 0.08, 0.94, 0.2, "Do you like my script? Visit my Website alexwo.com/scripting for more!", true, scriptinformation) 
    end 
end 
  
  
function wclose (state) 
 if state == "left" then 
  if source == exitbutton then 
    guiSetVisible(policeWindow, false) 
    showCursor(false) 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), wclose) 
  
function acceptjob (state) 
 if state == "left" then 
  if source == acceptbutton then 
    if(guiRadioButtonGetSelected(LS))then 
        triggerServerEvent("giveEquipmentLS", getLocalPlayer(), thePlayer) 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(SF))then 
        triggerServerEvent("giveEquipmentSF", getLocalPlayer(), thePlayer) 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
    elseif(guiRadioButtonGetSelected(LV))then 
        triggerServerEvent("giveEquipmentLV", getLocalPlayer(), thePlayer) 
        guiSetVisible(policeWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    end 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), acceptjob) 
  
function vehiclegui (hitPlayer, matchingDimension ) 
    if ( hitPlayer == localPlayer ) then -- This is required to make sure the player that hit the marker is the local player, because remote players also trigger this event. 
        if isPedInVehicle ( localPlayer ) then 
            outputChatBox ( getPlayerName ( localPlayer ) ..", you have to leave your vehicle!", 255, 255, 0 ) 
            return 
        end 
  
        PoliceVehicleWindow = guiCreateWindow ( 0.25, 0.25, 0.4, 0.4, "Police Vehicles", true ) 
        --Tap Panel 
        PoliceVehiclePanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, PoliceVehicleWindow ) 
        --Tab's 
        PoliceVehicleMap = guiCreateTab( "Vehicle List", PoliceVehiclePanel )     
        --PoliceTab 
        guiCreateLabel(0.02, 0.04, 0.94, 0.2, "Please choose a vehicle you want to spawn!", true, PoliceVehicleMap) 
        --RadioButtons 
        policecarls = guiCreateRadioButton(20,40,100,16,"Police Car LS",false, PoliceVehicleMap) 
        guiRadioButtonSetSelected(policecarls,true) 
        policecarsf = guiCreateRadioButton(20,60,100,16,"Police Car SF",false, PoliceVehicleMap) 
        policecarlv = guiCreateRadioButton(20,80,100,16,"Police Car LV", false, PoliceVehicleMap) 
        policeranger = guiCreateRadioButton(20,100,100,16,"Police Ranger", false, PoliceVehicleMap) 
        hpv1000 = guiCreateRadioButton(20,120,100,16,"HPV1000", false, PoliceVehicleMap) 
    
        --Buttons 
        policevehicleexitbutton = guiCreateButton( 0.5, 0.85, 0.2, 0.1, "Exit", true, PoliceVehicleMap ) 
        spawnbutton = guiCreateButton( 0.1, 0.85, 0.2, 0.1, "Spawn", true, PoliceVehicleMap ) 
    
        --showCursor 
        showCursor ( true ) 
    end 
end 
  
function PoliceVehicleGUIclose (state) 
 if state == "left" then 
  if source == policevehicleexitbutton then 
    guiSetVisible(PoliceVehicleWindow, false) 
    showCursor(false) 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), PoliceVehicleGUIclose) 
  
  
function spawnpolicevehicle (state) 
 if state == "left" then 
  if source == spawnbutton then 
    if(guiRadioButtonGetSelected(policecarls))then 
        triggerServerEvent("spawnpolicecarls", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(policecarsf))then 
        triggerServerEvent("spawnpolicecarsf", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
    elseif(guiRadioButtonGetSelected(policecarlv))then 
        triggerServerEvent("spawnpolicecarlv", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(policeranger))then 
        triggerServerEvent("spawnpoliceranger", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    elseif(guiRadioButtonGetSelected(hpv1000))then 
        triggerServerEvent("spawnhpv1000", getLocalPlayer(), thePlayer) 
        guiSetVisible(PoliceVehicleWindow, false) 
        showCursor(false) 
        local acceptsound = playSound("sounds/accept.mp3") 
    end 
  end 
 end 
end 
addEventHandler("onClientGUIClick", getRootElement(), spawnpolicevehicle) 

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