Jump to content

Need help vehicle spawn for team only !! URGENT


darhal

Recommended Posts

Posted

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 .

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

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 
    ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

ty castilo u are the best !!! it s work now but see this shown at debugscript 1

Error : Client (darhal) triggered serverside event cars , but event is not added serverside

help plz !

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

Nothing else?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

yes i thik there is a problem in server side line 2 or 13 mear end ...

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

I don't see any problem on the server side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

When the gui open , I select a vehicle THEN I CLICK SPAWN but the car dont spawn i dk why ???? and the ERROR appear

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

I guess the problem from the meta.

But anyway you will need to use table in server side if you want every police player able to get his own vehicle.

CiTLh.png
Posted

here is the meta file

  

    "darhal" name="police job" version="5.0" type="script"/> 
    "jail.map" /> 
    

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

the fllowing error appear in debugscript 1

WARNING:loading script failed: PD-s.lua:13:') expected (toclose '('atline 2) near 'end'

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

Post the content of that script.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

ty very much it s work now but the close button dont work ?? how to fix it ?

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

it spawn 3 vehicle now !!

Edited by Guest

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

What do you mean?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

it spawn 3 vehicle instead of 1

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

Make sure that no other script is using the same event "cars".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

oh ok ty very much castilo

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

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