Jump to content

how can i make this?


abdalbaset

Recommended Posts

i have this gui panel but how i can make it spawn cars whene i choose car from the panel and preess spawn car

  
GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(498, 244, 362, 391, "car panel", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.gridlist[1] = guiCreateGridList(59, 26, 245, 242, false, GUIEditor.window[1]) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "cars", 0.9) 
        for i = 1, 4 do 
            guiGridListAddRow(GUIEditor.gridlist[1]) 
        end 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 1, "Infernus", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 1, "NRG-500", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 2, 1, "Sultan", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 3, 1, "Super GT", false, false) 
        GUIEditor.button[1] = guiCreateButton(59, 268, 245, 49, "spawn car", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") 
        GUIEditor.button[2] = guiCreateButton(60, 338, 248, 43, "close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")     
    end 
) 
  

Link to comment
 thePlayer = getLocalPlayer () 
 addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(498, 244, 362, 391, "car panel", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.gridlist[1] = guiCreateGridList(59, 26, 245, 242, false, GUIEditor.window[1]) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "cars", 0.9) 
        for i = 1, 4 do 
            guiGridListAddRow(GUIEditor.gridlist[1]) 
        end 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 1, "Infernus", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 1, "NRG-500", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 2, 1, "Sultan", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 3, 1, "Super GT", false, false) 
        GUIEditor.button[1] = guiCreateButton(59, 268, 245, 49, "spawn car", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") 
        GUIEditor.button[2] = guiCreateButton(60, 338, 248, 43, "close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")     
    end 
  
function createInfernus() 
       if (source==GUIEditor.button[1]) then 
       infernus = createVehicle(ID, x, y, z) 
       warpPedIntoVehicle(thePlayer, infernus, 0) 
       showCursor(false) 
       guiSetVisible(GUIEditor.window[1], false) 
       end 
end 
  
addEventHandler("onClientGUIClick", root, createInfernus) 
) 

The thing you missed is "onClientGUIClick" event handler

Do the same for other cars like createInfernus function :)

Did it So fast so if u have any errors then contact me :) I can help you

And can I script for your server

:lilangel:

thankyou

Link to comment
local spawnMarker = createMarker(1541, -1627.4000244141, 12.60000038147, "cylinder", 2, 225, 163, 25, 225) 
function carGui (hitPlayer, matchingDimension) 
   mainWindow = guiCreateWindow(266, 103, 277, 374, "Spawn Window for u", false) 
   carsG = guiCreateGridList(9, 28, 258, 284, false, mainWindow) 
   guiGridListAddColumn(carsG, "cars", 0.9) 
   for i = 1, 2 do 
    guiGridListAddRow(carsG) 
   end  
   guiGridListSetItemText(carsG, 0, 1, "sabre", false, false) 
   guiGridListSetItemText(carsG, 1, 1, "Nrg-500", false, false) 
   spawnButton = guiCreateButton(9, 320, 128, 44, "spawn", false, mainWindow) 
   guiSetFont(spawnButton, "sa-header") 
   cancelButton = guiCreateButton(144, 322, 123, 42, "cancel", false, mainWindow) 
   guiSetFont(cancelButton, "sa-header") 
   showCursor(true) 
   sabre = createVehicle(422, 1541, -1627.4000244141, 12.60000038147) 
   warpPedIntoVehicle(hitPlayer,sabre)  -- this function doesn't work in my MTA, so just check it in yours and if it doesn't work put it in server side  
end 
addEventHandler("onClientMarkerHit", spawnMarker, carGui) 
  
  
  
function spawnCar () 
   if (source==spawnButton) then 
   sabre = createVehicle(422, 1541, -1627.4000244141, 12.60000038147) 
   warpPedIntoVehicle(hitPlayer, sabre) 
   end 
end 
addEventHandler("onClientGUIClick", root, spawnCar) 

Hope you understood how u make it

also When I tested it [juz tested it once] the car spawns but I can't enter the car

I made it so fast cuz i had exams so if any errors contact me

Also If you have a RPG server, can I script for that server? possibly giving me admin rights? can you?

:diabloanifire::thin::whdat::big1:

Link to comment

sure but my server is not 24/7 open so connect with my skype abdalbaset.skoot

but the script just show the gui panel its didnt spawn any car

so i try and make this by my own self

  
local spawnMarker = createMarker(2851.282958,1291.65686,10.7697496, "cylinder", 2, 225, 163, 25, 225) 
  
GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(498, 244, 362, 391, "car panel", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.gridlist[1] = guiCreateGridList(59, 26, 245, 242, false, GUIEditor.window[1]) 
        guiGridListAddColumn(GUIEditor.gridlist[1], "cars", 0.9) 
        for i = 1, 4 do 
            guiGridListAddRow(GUIEditor.gridlist[1]) 
        end 
        guiGridListSetItemText(GUIEditor.gridlist[1], 0, 1, "Infernus", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 1, 1, "Flash", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 2, 1, "Sultan", false, false) 
        guiGridListSetItemText(GUIEditor.gridlist[1], 3, 1, "Super GT", false, false) 
        GUIEditor.button[1] = guiCreateButton(59, 268, 245, 49, "spawn car", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") 
        GUIEditor.button[2] = guiCreateButton(60, 338, 248, 43, "close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")     
    end 
) 
  
function markerHit (hitPlayer, matchingDimension) 
if isPedInVehicle (hitPlayer) then return end 
if getElementType(hitPlayer) == "player" then 
    triggerClientEvent ("openMean", hitPlayer) 
end 
end 
addEventHandler ("onMarkerHit",spawnMarker,player) 

marker made but whene ithe resours start the panel come up so i replace onClientResourceStart with onMarkerHit now its didnt come up (how i can make this panel close?)

Link to comment

Friend, I told you * Just put it in the Server sided lua thingy and then use this in client one =======

the server sided one :- name it server.lua

function carSpawn () 
                            sabre = createVehicle(422, 1541, -1627.4000244141, 12.60000038147) 
                            warpPedIntoVehicle(thePlayer, sabre) 
                            addEvent("onSpawnVehicle", true) 
                            addEventHandler("onSpawnVehicle", getRootElement(), carSpawn) 
                         end 

now this is the client sided one:- client.lua

local spawnMarker = createMarker(1541, -1627.4000244141, 12.60000038147, "cylinder", 2, 225, 163, 25, 225) 
function carGui (hitPlayer, matchingDimension) 
   mainWindow = guiCreateWindow(266, 103, 277, 374, "Spawn Window for u", false) 
   carsG = guiCreateGridList(9, 28, 258, 284, false, mainWindow) 
   guiGridListAddColumn(carsG, "cars", 0.9) 
   for i = 1, 2 do 
    guiGridListAddRow(carsG) 
   end 
   guiGridListSetItemText(carsG, 0, 1, "sabre", false, false) 
   guiGridListSetItemText(carsG, 1, 1, "Nrg-500", false, false) 
   spawnButton = guiCreateButton(9, 320, 128, 44, "spawn", false, mainWindow) 
   guiSetFont(spawnButton, "sa-header") 
   cancelButton = guiCreateButton(144, 322, 123, 42, "cancel", false, mainWindow) 
   guiSetFont(cancelButton, "sa-header") 
   showCursor(true) 
   sabre = createVehicle(422, 1541, -1627.4000244141, 12.60000038147) 
   warpPedIntoVehicle(hitPlayer,sabre)  -- this function doesn't work in my MTA, so just check it in yours and if it doesn't work put it in server side  
end 
addEventHandler("onClientMarkerHit", spawnMarker, carGui) 
  
  
  
function spawnCar () 
   if (source==spawnButton) then 
   triggerServerEvent("onSpawnVehicle", sabre) 
addEventHandler("onClientGUIClick", root, spawnCar) 
   end 
end 

try this if any more errors then call me :)

PS I was Busy so dint come online :P

Link to comment

Try this:

Client:

local spawnMarker = createMarker(1541, -1627.4000244141, 12.60000038147, "cylinder", 2, 225, 163, 25, 225) 
  
function carGui () 
   mainWindow = guiCreateWindow(266, 103, 277, 374, "Spawn Window for u", false) 
   guiSetVisible(mainWindow, false) 
   carsG = guiCreateGridList(9, 28, 258, 284, false, mainWindow) 
   guiGridListAddColumn(carsG, "cars", 0.9) 
   for i = 1, 2 do 
    guiGridListAddRow(carsG) 
   end 
   guiGridListSetItemText(carsG, 0, 1, "sabre", false, false) 
   guiGridListSetItemText(carsG, 1, 1, "Nrg-500", false, false) 
   spawnButton = guiCreateButton(9, 320, 128, 44, "spawn", false, mainWindow) 
   guiSetFont(spawnButton, "sa-header") 
   cancelButton = guiCreateButton(144, 322, 123, 42, "cancel", false, mainWindow) 
   guiSetFont(cancelButton, "sa-header") 
end 
addEventHandler("onClientResourceStart", resourceRoot, carGui) 
  
addEventHandler("onClientGUIClick", root,  
function () 
    if (source == spawnButton) then 
        local row,col = guiGridListGetSelectedItem(carsG) 
        if (row and col and row ~= -1 and col ~= -1) then 
            local vehicleName = guiGridListGetItemText(carsG, row, 1) 
            if vehicleName == "sabre" then 
                triggerServerEvent("onSpawnVehicle", localPlayer, 475) 
                showWindow(false) 
            elseif vehicleName == "Nrg-500" then 
                triggerServerEvent("onSpawnVehicle", localPlayer, 522) 
                showWindow(false) 
            end 
        else 
            outputChatBox("Select a vehicle from the list.") 
        end 
    elseif (source == cancelButton) then 
        showWindow(false) 
    end 
end) 
  
addEventHandler("onClientMarkerHit", spawnMarker,  
function (hitPlayer) 
    if (hitPlayer == localPlayer) then 
        showWindow(true) 
    end 
end) 
  
function showWindow(bool) 
    guiSetVisible(mainWindow, bool) 
    showCursor(bool) 
end 

Server:

local vehicles = { } 
  
addEvent("onSpawnVehicle", true) 
addEventHandler("onSpawnVehicle", root, 
function (vehID) 
    if ( isElement(vehicles[source]) ) then 
        destroyElement(vehicles[source]) 
    end 
    vehicles[source] = createVehicle(vehID, getElementPosition(source)) 
    warpPedIntoVehicle(source, vehicles[source]) 
end) 

I haven't tested it.

Link to comment
local spawnMarker = createMarker(1541, -1627.4000244141, 12.60000038147, "cylinder", 2, 225, 163, 25, 225) 
  
function carGui () 
   mainWindow = guiCreateWindow(266, 103, 277, 374, "Spawn Window for u", false) 
   guiSetVisible(mainWindow, false) 
   carsG = guiCreateGridList(9, 28, 258, 284, false, mainWindow) 
   guiGridListAddColumn(carsG, "cars", 0.9) 
   for i = 1, 2 do 
    guiGridListAddRow(carsG) 
   end 
   guiGridListSetItemText(carsG, 0, 1, "sabre", false, false) 
   guiGridListSetItemText(carsG, 1, 1, "Nrg-500", false, false) 
   spawnButton = guiCreateButton(9, 320, 128, 44, "spawn", false, mainWindow) 
   guiSetFont(spawnButton, "sa-header") 
   cancelButton = guiCreateButton(144, 322, 123, 42, "cancel", false, mainWindow) 
   guiSetFont(cancelButton, "sa-header") 
end 
addEventHandler("onClientResourceStart", resourceRoot, carGui) 
  
addEventHandler("onClientGUIClick", root, 
function () 
    if (source == spawnButton) then 
        if (not getTeamName(getPlayerTeam(localPlayer)) == "teamName") then return end 
         
        local row,col = guiGridListGetSelectedItem(carsG) 
        if (row and col and row ~= -1 and col ~= -1) then 
            local vehicleName = guiGridListGetItemText(carsG, row, 1) 
            if vehicleName == "sabre" then 
                triggerServerEvent("onSpawnVehicle", localPlayer, 475) 
                showWindow(false) 
            elseif vehicleName == "Nrg-500" then 
                triggerServerEvent("onSpawnVehicle", localPlayer, 522) 
                showWindow(false) 
            end 
        else 
            outputChatBox("Select a vehicle from the list.") 
        end 
    elseif (source == cancelButton) then 
        showWindow(false) 
    end 
end) 
  
addEventHandler("onClientMarkerHit", spawnMarker, 
function (hitPlayer) 
    if (hitPlayer == localPlayer) then 
        showWindow(true) 
    end 
end) 
  
function showWindow(bool) 
    guiSetVisible(mainWindow, bool) 
    showCursor(bool) 
end 

Link to comment
local spawnMarker = createMarker(1541, -1627.4000244141, 12.60000038147, "cylinder", 2, 225, 163, 25, 225) 
  
function carGui () 
   mainWindow = guiCreateWindow(266, 103, 277, 374, "Spawn Window for u", false) 
   guiSetVisible(mainWindow, false) 
   carsG = guiCreateGridList(9, 28, 258, 284, false, mainWindow) 
   guiGridListAddColumn(carsG, "cars", 0.9) 
   for i = 1, 2 do 
    guiGridListAddRow(carsG) 
   end 
   guiGridListSetItemText(carsG, 0, 1, "sabre", false, false) 
   guiGridListSetItemText(carsG, 1, 1, "Nrg-500", false, false) 
   spawnButton = guiCreateButton(9, 320, 128, 44, "spawn", false, mainWindow) 
   guiSetFont(spawnButton, "sa-header") 
   cancelButton = guiCreateButton(144, 322, 123, 42, "cancel", false, mainWindow) 
   guiSetFont(cancelButton, "sa-header") 
end 
addEventHandler("onClientResourceStart", resourceRoot, carGui) 
  
addEventHandler("onClientGUIClick", root, 
function () 
    if (source == spawnButton) then 
        if not (getTeamName(getPlayerTeam(localPlayer)) == "teamName") then return end 
        
        local row,col = guiGridListGetSelectedItem(carsG) 
        if (row and col and row ~= -1 and col ~= -1) then 
            local vehicleName = guiGridListGetItemText(carsG, row, 1) 
            if vehicleName == "sabre" then 
                triggerServerEvent("onSpawnVehicle", localPlayer, 475) 
                showWindow(false) 
            elseif vehicleName == "Nrg-500" then 
                triggerServerEvent("onSpawnVehicle", localPlayer, 522) 
                showWindow(false) 
            end 
        else 
            outputChatBox("Select a vehicle from the list.") 
        end 
    elseif (source == cancelButton) then 
        showWindow(false) 
    end 
end) 
  
addEventHandler("onClientMarkerHit", spawnMarker, 
function (hitPlayer, dim) 
    if (hitPlayer == localPlayer) and dim then 
        showWindow(true) 
    end 
end) 
  
function showWindow(bool) 
    guiSetVisible(mainWindow, bool) 
    showCursor(bool) 
end 

I tested and it works fine for me.

Link to comment

Add the vehicle name and the ID of that vehicle in vehicles table (line 3).

local spawnMarker = createMarker(1541, -1627.4000244141, 12.60000038147, "cylinder", 2, 225, 163, 25, 225) 
  
local vehicles = { ["sabre"] = 475, ["Nrg-500"] = 522, ["carName"] = ID } 
function carGui () 
    mainWindow = guiCreateWindow(266, 103, 277, 374, "Spawn Window for u", false) 
    guiSetVisible(mainWindow, false) 
    carsG = guiCreateGridList(9, 28, 258, 284, false, mainWindow) 
    guiGridListAddColumn(carsG, "cars", 0.9) 
  
    for k,_ in pairs(vehicles) do 
        guiGridListAddRow(carsG) 
        guiGridListSetItemText(carsG, guiGridListGetRowCount(carsG)-1, 1, k, false, false) 
    end 
  
    spawnButton = guiCreateButton(9, 320, 128, 44, "spawn", false, mainWindow) 
    guiSetFont(spawnButton, "sa-header") 
    cancelButton = guiCreateButton(144, 322, 123, 42, "cancel", false, mainWindow) 
    guiSetFont(cancelButton, "sa-header") 
end 
addEventHandler("onClientResourceStart", resourceRoot, carGui) 
  
addEventHandler("onClientGUIClick", root, 
function () 
    if (source == spawnButton) then 
        if not (getTeamName(getPlayerTeam(localPlayer)) == "teamName") then return end 
        
        local row,col = guiGridListGetSelectedItem(carsG) 
        if (row and col and row ~= -1 and col ~= -1) then 
            local vehicleName = guiGridListGetItemText(carsG, row, 1) 
            if triggerServerEvent("onSpawnVehicle", localPlayer, vehicles[vehicleName]) then 
                showWindow(false) 
            end 
        else 
            outputChatBox("Select a vehicle from the list.") 
        end 
    elseif (source == cancelButton) then 
        showWindow(false) 
    end 
end) 
  
addEventHandler("onClientMarkerHit", spawnMarker, 
function (hitPlayer) 
    if (hitPlayer == localPlayer) then 
        showWindow(true) 
    end 
end) 
  
function showWindow(bool) 
    guiSetVisible(mainWindow, bool) 
    showCursor(bool) 
end 

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