Jump to content

Help creating GUI


Recommended Posts

Hi all.

I'm trying to make my own vehicle spawn system for my server but i dont know some things...

I created the Gui one little window with one grid with 2 columns: one for the key that player have to press to spawn the vehicle (1,2,3,4...) and other to the name of vehicle corresponding to the key)

I want u to explain me too how can i create a marker and when the player hit the marker show the GUI

And i want to do some code to define the ''spawn car action'' when the player press the key.

Can help me please? here is the script Client Side (server side not done yet...)

jWin = guiCreateWindow(550,560,200,200,"Sistema de Veículos",false) 
----- Center Window ----- 
guiSetVisible(jWin,true) 
guiWindowSetSizable(jWin,false) 
tGrid = guiCreateGridList(0,20,190,170,false,jWin) 
guiGridListAddColumn(tGrid, "Tecla", 0.20) 
guiGridListAddColumn(tGrid, "Nome", 0.65) 
  

Realy thanks to who can help me

Bye!

Link to comment

First, you would need to create a marker, for that, you use:

createMarker 

Then, you can either make it server side or client side, if you use server-side markers, you must use the event:

onMarkerHit

but, if you use it client side, then the event would be:

onClientMarkerHit

And for the car spawning action, well, you could either use the event onClientKey ( could be the best choice ), or you could use bindKey.

Link to comment

onMarkerHit server side has an hitElement as first argument, the hitElement is the element who hit's the marker, most likely a player or a vehicle with a player in it. You can check it with

getElementType 

The function would look something like this:

function markerHit(hitElement, matchingDimension)  
end 
addEventHandler("onMarkerHit",markerHit) 

Where source is the marker, hitElement is the element hitting it and matchingDimension a bool determine if the player are in the same dimension as the marker.

Link to comment

Yea ty all i made my own script and it looks like this:

Server-side:

sp1 = createMarker(1920.96960, -1791.41931, 12.25451, "cylinder", 1.5, 0, 255, 0, 150) 
sp2 = createMarker(1372.22998, -1600.58765, 12.55247, "cylinder", 1.5, 0, 255, 0, 150) 
sp3 = createMarker(1149.63818, -1429.25403, 14.79688, "cylinder", 1.5, 0, 255, 0, 150) 
sp4 = createMarker(1204.98145, -1070.53796, 28.24623, "cylinder", 1.5, 0, 255, 0, 150) 
sp5 = createMarker(652.31482, -1767.81738, 12.55009, "cylinder", 1.5, 0, 255, 0, 150) 
sp6 = createMarker(2455.93091, -1787.65576, 12.54688, "cylinder", 1.5, 0, 255, 0, 150) 
sp7 = createMarker(2154.16821, -1167.59106, 22.82215, "cylinder", 1.5, 0, 255, 0, 150) 
sp8 = createMarker(-20.03092, -278.19138, 4.42969, "cylinder", 1.5, 0, 255, 0, 150) 
sp9 = createMarker(1736.50134, 1877.01477, 9.82031, "cylinder", 1.5, 0, 255, 0, 150) 
sp10 = createMarker(2377.19727, 2019.28247, 9.82031, "cylinder", 1.5, 0, 255, 0, 150) 
sp11 = createMarker(2898.70703, 2454.66870, 9.82031, "cylinder", 1.5, 0, 255, 0, 150) 
sp12 = createMarker(-1454.17456, 1870.05615, 31.63281, "cylinder", 1.5, 0, 255, 0, 150) 
sp13 = createMarker(-2251.42944, 2329.95679, 3.81250, "cylinder", 1.5, 0, 255, 0, 150) 
sp14 = createMarker(-2242.80200, 537.43109, 34.12649, "cylinder", 1.5, 0, 255, 0, 150) 
sp15 = createMarker(-1985.65979, 269.49936, 34.17936, "cylinder", 1.5, 0, 255, 0, 150) 
sp16 = createMarker(-1498.97607, 849.02643, 6.18750, "cylinder", 1.5, 0, 255, 0, 150) 
sp17 = createMarker(-2142.76392, -2447.32666, 29.63276, "cylinder", 1.5, 0, 255, 0, 150) 
  
createBlipAttachedTo(sp1, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp2, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp3, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp4, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp5, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp6, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp7, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp8, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp9, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp10, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp11, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp12, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp13, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp14, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp15, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp16, 0, 2, 0, 255, 0, 255, 0, 500) 
createBlipAttachedTo(sp17, 0, 2, 0, 255, 0, 255, 0, 500) 
  
addEventHandler("onMarkerHit", sp1, 
function(hitElement) 
    if(getElementType(hitElement) == "player") then 
        triggerClientEvent(hitElement, "markerHitted", getRootElement()) 
    end 
end 
) 
  
addEventHandler("onMarkerLeave", sp1, 
function(leftElement) 
    if(getElementType(leftElement) == "player") then 
        triggerClientEvent(leftElement, "markerLeaved", getRootElement()) 
    end 
end 
) 

(i will add the trigger to other markers later, i added only to sp1 to test)

Client-side:

jWin = guiCreateWindow(550,560,200,200,"Sistema de Veículos",false) 
guiSetVisible(jWin,false) 
function openGui() 
guiSetVisible(jWin,true) 
        function spawnveh(button, press) 
            if(press) then 
                if(button == "1") then 
                    x, y, z = getElementPosition(localPlayer) 
                    san = createVehicle(468, x, y, z + 5) 
                    warpPedIntoVehicle(localPlayer, san) 
                end 
                if(button == "2") then 
                    x, y, z = getElementPosition(localPlayer) 
                    cad = createVehicle(457, x, y, z + 5) 
                    warpPedIntoVehicle(localPlayer, cad) 
                end 
                if(button == "3") then 
                    x, y, z = getElementPosition(localPlayer) 
                    voo = createVehicle(412, x, y, z + 5) 
                    warpPedIntoVehicle(localPlayer, voo) 
                end 
            end 
        end 
    addEventHandler("onClientKey", getRootElement(), spawnveh) 
    guiWindowSetSizable(jWin,false) 
    tGrid = guiCreateGridList(0,20,190,170,false,jWin) 
    guiGridListAddColumn(tGrid, "Tecla", 0.20) 
    guiGridListAddColumn(tGrid, "Nome", 0.65) 
    row1 = guiGridListAddRow(tGrid) 
    row2 = guiGridListAddRow(tGrid) 
    row3 = guiGridListAddRow(tGrid) 
    guiGridListSetItemText(tGrid, row1, 1, tostring(row1+1), false, false) 
    guiGridListSetItemText(tGrid, row1, 2, "Sanchez", false, false) 
    guiGridListSetItemText(tGrid, row2, 1, tostring(row2+1), false, false) 
    guiGridListSetItemText(tGrid, row2, 2, "Caddy", false, false) 
    guiGridListSetItemText(tGrid, row3, 1, tostring(row3+1), false, false) 
    guiGridListSetItemText(tGrid, row3, 2, "Voodoo", false, false)  
  
end 
addEvent("markerHitted", true) 
addEventHandler("markerHitted", getRootElement(), openGui) 
  
function hideGui() 
    guiSetVisible(jWin,false) 
    removeEventHandler("onClientKey", getRootElement(), spawnveh) 
end 
  
addEvent("markerLeaved", true) 
addEventHandler("markerLeaved", getRootElement(), hideGui) 

And it is working great btu has a little problem... when the vehicle is spawned the player dont gets warped into it and i cant enter the spawned vehicle neither using ''Enter'' or ''F''

Link to comment

From the mta wiki:

  
Note: Vehicles (and other elements) created client-side are only seen by the client that created them, [b]aren't synced and players cannot enter them[/b]. They are essentially for display only. 
  

You have to trigger a server event to create the vehicles server-sided.

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