Jump to content

Need help vehicle spawn for team only !! URGENT


darhal

Recommended Posts

hi i make a vehicle spawner for police team only but it's dont work the gui open to evry one and the gridlist , the label aand the buttons don t shown i know that the problem is in the Client side :

Code client side

GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    button = {}, 
    label = {} 
    } 
          
    car = { 
            {569}, 
            {597}, 
            {598}, 
            {599} 
       
    }   
    local teamName = "police" 
    local marker = createMarker( -1604, 650, 7, "cylinder", 1.5, 0, 0, 255, 150 )       
    local marker2 = createMarker( -1629, 651, 7, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker3 = createMarker( -1600, 752, -5, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker4 = createMarker( 1598, -1609, 13, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker5 = createMarker( 1604, -1688, 5, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker6 = createMarker( 1583, -1410, 5, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker7 = createMarker( 2274, 2242, 10, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker8 = createMarker( 2272, 2478, 10, "cylinder", 1.5, 0, 0, 255, 150 ) 
     
      
      
    GUIEditor_Window[1] = guiCreateWindow(251,166,290,342,"Job vehicle", false) 
    guiSetVisible(GUIEditor_Window[1],false) 
    GUIEditor_label[1] = guiCreateLabel(10,23,262,26,"Choose a car then click Spawn vehicle .", false, GUIEditor.window[1]) 
    GUIEditor_Grid[1] = guiCreateGridList(9,49,263,227, false, GUIEditor.window[1]) 
    guiGridListSetSelectionMode(GUIEditor_Grid[1],2) 
    guiGridListAddColumn(GUIEditor_Grid[1],"vehicle name",60) 
    GUIEditor_Button[1] = guiCreateButton(9,296,69,34,"Spawn Vehicle",false,GUIEditor_Window[1]) 
    GUIEditor_Button[2] = guiCreateButton(152,291,129,41,"Close",false,GUIEditor_Window[1]) 
      
    for i,v in ipairs (car) do 
            local carName = getVehicleNameFromModel (v[1]) 
            local row = guiGridListAddRow (GUIEditor_Grid[1]) 
                guiGridListSetItemText (GUIEditor_Grid[1], row, 1, carName, false, true) 
    end 
      
    function onClientClick (button, state, absoluteX, absoluteYe) 
            if (source == GUIEditor_Button[1]) then 
                    if (guiGridListGetSelectedItem (GUIEditor_Grid[1])) then 
                      local cars = guiGridListGetItemText (GUIEditor_Grid[1], guiGridListGetSelectedItem (GUIEditor_Grid[1]), 1) 
                      triggerServerEvent ("cars", getLocalPlayer(), cars) 
                    end 
            end 
    end 
    addEventHandler ("onClientGUIClick", GUIEditor_Button[1], onClientClick) 
      
    function onClientClick (button, state, absoluteX, absoluteYe) 
            if (source == GUIEditor_Button[2]) then 
                    guiSetVisible(GUIEditor_Window[1],true) 
                    showCursor(false) 
            end 
    end 
    addEventHandler ("onClientGUIClick", GUIEditor_Button[2], onClientClick) 
      
    addEventHandler("onClientMarkerHit", marker, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
      
    addEventHandler("onClientMarkerHit", marker2, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker2) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
     
    addEventHandler("onClientMarkerHit", marker3, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker3) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
     
    addEventHandler("onClientMarkerHit", marker4, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker4) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
    addEventHandler("onClientMarkerHit", marker5, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker5) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            warnText("You are not police to have vehicle !!!",source,0,255,0) 
                            end 
                    end 
            end 
    ) 
  
    addEventHandler("onClientMarkerHit", marker6, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker6) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
     
    addEventHandler("onClientMarkerHit", marker7, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker7) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
     
    addEventHandler("onClientMarkerHit", marker8, 
            function ( hitPlayer, matchingDimension ) 
                    if ( isElementWithinMarker(hitPlayer, marker8) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor_Window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 

server side

addEvent ("cars", true) 
addEventHandler ("cars", getRootElement(), 
    function(cars) 
                if isElement( veh ) then destroyElement( veh ) end 
                        local cn = getVehicleModelFromName (cars) 
                        local x,y,z = getElementPosition(source) 
                        local cn2 = getVehicleNameFromModel (cn) 
                        veh = createVehicle(cn, x,y,z) 
                        setVehicleColor(veh, 23, 75, 4) 
                        warpPedIntoVehicle(source, veh) 
                        outputChatBox ( "* "..cn2.."  was created!" ) 
    end 
    ) 

plz help me to fix it and ty

here what debugscript 1 say : ERROR : PD-c.lua:27: attempt to index global 'GUIEditor_Window' a nil value .

Link to comment

The problem is that you should check if the hit player is the local player.

And the problem with the buttons not showing is that you are using the wrong tables.

GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    button = {}, 
    label = {} 
    } 
          
    car = { 
            {569}, 
            {597}, 
            {598}, 
            {599} 
      
    }   
    local teamName = "police" 
    local marker = createMarker( -1604, 650, 7, "cylinder", 1.5, 0, 0, 255, 150 )       
    local marker2 = createMarker( -1629, 651, 7, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker3 = createMarker( -1600, 752, -5, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker4 = createMarker( 1598, -1609, 13, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker5 = createMarker( 1604, -1688, 5, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker6 = createMarker( 1583, -1410, 5, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker7 = createMarker( 2274, 2242, 10, "cylinder", 1.5, 0, 0, 255, 150 ) 
    local marker8 = createMarker( 2272, 2478, 10, "cylinder", 1.5, 0, 0, 255, 150 ) 
    
      
      
    GUIEditor.window[1] = guiCreateWindow(251,166,290,342,"Job vehicle", false) 
    guiSetVisible(GUIEditor.window[1],false) 
    GUIEditor.label[1] = guiCreateLabel(10,23,262,26,"Choose a car then click Spawn vehicle .", false, GUIEditor.window[1]) 
    GUIEditor.gridlist[1] = guiCreateGridList(9,49,263,227, false, GUIEditor.window[1]) 
    guiGridListSetSelectionMode(GUIEditor.gridlist[1],2) 
    guiGridListAddColumn(GUIEditor.gridlist[1],"vehicle name",60) 
    GUIEditor.button[1] = guiCreateButton(9,296,69,34,"Spawn Vehicle",false,GUIEditor.window[1]) 
    GUIEditor.button[2] = guiCreateButton(152,291,129,41,"Close",false,GUIEditor.window[1]) 
      
    for i,v in ipairs (car) do 
            local carName = getVehicleNameFromModel (v[1]) 
            local row = guiGridListAddRow (GUIEditor.gridlist[1]) 
                guiGridListSetItemText (GUIEditor.gridlist[1], row, 1, carName, false, true) 
    end 
      
    function onClientClick (button, state, absoluteX, absoluteYe) 
            if (source == GUIEditor.button[1]) then 
                    if (guiGridListGetSelectedItem (GUIEditor.gridlist[1])) then 
                      local cars = guiGridListGetItemText (GUIEditor.gridlist[1], guiGridListGetSelectedItem (GUIEditor.gridlist[1]), 1) 
                      triggerServerEvent ("cars", getLocalPlayer(), cars) 
                    end 
            end 
    end 
    addEventHandler ("onClientGUIClick", GUIEditor.button[1], onClientClick) 
      
    function onClientClick (button, state, absoluteX, absoluteYe) 
            if (source == GUIEditor.button[2]) then 
                    guiSetVisible(GUIEditor.window[1],true) 
                    showCursor(false) 
            end 
    end 
    addEventHandler ("onClientGUIClick", GUIEditor.button[2], onClientClick) 
      
    addEventHandler("onClientMarkerHit", marker, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
      
    addEventHandler("onClientMarkerHit", marker2, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker2) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
    
    addEventHandler("onClientMarkerHit", marker3, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker3) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
    
    addEventHandler("onClientMarkerHit", marker4, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker4) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
    addEventHandler("onClientMarkerHit", marker5, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker5) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            warnText("You are not police to have vehicle !!!",source,0,255,0) 
                            end 
                    end 
            end 
    ) 
  
    addEventHandler("onClientMarkerHit", marker6, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker6) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
    
    addEventHandler("onClientMarkerHit", marker7, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker7) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 
    
    addEventHandler("onClientMarkerHit", marker8, 
            function ( hitPlayer, matchingDimension ) 
                    if ( hitPlayer == localPlayer and isElementWithinMarker(hitPlayer, marker8) ) then 
                            if ( getTeamName( getPlayerTeam( hitPlayer ) ) == teamName ) then 
                                    if getElementType(hitPlayer) == "player" then 
                                            guiSetVisible ( GUIEditor.window[1], true ) 
                                            showCursor(false) 
                                    end 
                            else 
                            outputChatBox ( "you are not in the team", player, 255, 0, 0, true ) 
                            end 
                    end 
            end 
    ) 

Link to comment
addEvent ( "cars", true ) 
addEventHandler ( "cars", getRootElement(), 
    function ( cars ) 
        if isElement ( veh ) then 
            destroyElement ( veh ) 
        end 
        local cn = getVehicleModelFromName ( cars ) 
        local x,y,z = getElementPosition ( source ) 
        local cn2 = getVehicleNameFromModel ( cn ) 
        veh = createVehicle ( cn, x, y, z ) 
        setVehicleColor ( veh, 238, 180, 34 ) 
        warpPedIntoVehicle ( source, veh ) 
        outputChatBox ( "* "..cn2.."  was created!" ) 
    end 
) 

Link to comment

That's because is set to show it.

function onClientClick (button, state, absoluteX, absoluteYe) 
            if (source == GUIEditor.button[2]) then 
                    guiSetVisible(GUIEditor.window[1],true) 
                    showCursor(false) 
            end 
    end 
    addEventHandler ("onClientGUIClick", GUIEditor.button[2], onClientClick) 

guiSetVisible(GUIEditor.window[1],true) 

Change that true to false.

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