Jump to content

GUI


StefanAlmighty

Recommended Posts

Posted

So I'm making a teleport system GUI. I've made the GUI, but now I want to create an array and I want it to loop through my array and fill the gridlist with all the teleporter locations in the array? How would I go about doing this?

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Posted

Create a table and loop the data from this table and send it to client side by trigger ,in case you created the table in client just loop it

Use

ipairs 
pairs 

to loop a table

Posted
How would I create the table? I want it to store an ID, name and description.

You can create a table like that

local aTable = {} --i created my table i named it aTable it's empty 

local aTable = { --after creating the table i filled it with IDs. 
{"id1"}, 
{"id2"}, 
{"id3"}, 
} 

There're alot of ways to do that ,it was just a simple example to understand, You can loop like this table by using ipairs or pairs no matter in this situation

Posted

My gridlist has three columns, so I made a table:

  
local data = { 
{"1", "Los Santos", "Pershing Square, the heart of Los Santos."} 
{"2", "DMV", "Department of Motor Vehicles."} 
} 
  

But now it wont work at all, not even the GUI.

Posted

Good job, but It's wrong must be like that

local data = { 
{"1", "Los Santos", "Pershing Square, the heart of Los Santos."}, 
{"2", "DMV", "Department of Motor Vehicles."}, 
} 

If you stuck on something post the code,

~Good luck

Posted

I modified it a bit so it contains the coordinates, interior, dimension etc. Here:

  
local data = {                                                              -- X                Y               Z        Int  Dim  Rot 
ls = {"1", "Los Santos", "Teleports you to Pershing Square, Los Santos.", 1479.9873046875, -1710.9453125, 13.36874961853,   0,  0,  0}, 
sf = {"2", "San Fierro", "Teleports you to Doherty, San Fierro.", -1988.5693359375, 507.0029296875, 35.171875,  0,  0,  90}, 
lv = {"3", "Las Venturas", "Teleports you to The Strip, Las Venturas", 1691.6801757813,     1449.1293945313,    10.765375,  0,  0,  268}, 
} 
  

I tried looping through them and adding them to my gridlist but it doesn't work, here's the code:

  
for v, k in pairs(data) do 
        gui.row = guiGridListAddRow(gui.grid) 
        local a, b = gui.grid, gui.row 
        guiGridListSetItemText(a, b, gui.colID, data[k][1], false, true) 
        guiGridListSetItemText(a, b, gui.colValue, data[k][2], false, false) 
        guiGridListSetItemText(a, b, gui.colDesc, data[k][3], false, false) 
end 
  

Posted

Make sure gui.grid is defined as guiCreateGridList function and gui.colID ,gui.colValue, gui.colDesc are the columns

local data = {                                                              -- X                Y               Z        Int  Dim  Rot 
[1] = {"1", "Los Santos", "Teleports you to Pershing Square, Los Santos.", 1479.9873046875, -1710.9453125, 13.36874961853,   0,  0,  0}, 
[2] = {"2", "San Fierro", "Teleports you to Doherty, San Fierro.", -1988.5693359375, 507.0029296875, 35.171875,  0,  0,  90}, 
[3] = {"3", "Las Venturas", "Teleports you to The Strip, Las Venturas", 1691.6801757813,     1449.1293945313,    10.765375,  0,  0,  268}, 
} 
  
for index, v in pairs(data) do 
        local row = guiGridListAddRow(gui.grid) 
        guiGridListSetItemText(gui.grid, row, gui.colID, v[1], false, true) 
        guiGridListSetItemText(gui.grid, row, gui.colValue, v[2], false, false) 
        guiGridListSetItemText(gui.grid, row, gui.colDesc, v[3], false, false) 
end 

Posted

Okay all good, it's working perfectly. When the player has a row selected and they click "Go" I want it to teleport them to the location. Here's a picture of my GUI:

2a949ab3606f8d67167caccf1afcc178.png

So if the player has Los Santos selected, I want it to teleport them to the LS coordinates in my table.

Posted
Okay all good, it's working perfectly. When the player has a row selected and they click "Go" I want it to teleport them to the location

So if the player has Los Santos selected, I want it to teleport them to the LS coordinates in my table.

You've to use

setElementPosition 

try by yourself if you stuck i will help you

Posted
  
gui.goWindow = guiCreateButton(5, 205, 91, 35, "Go", false, gui.manager) 
    addEventHandler("onClientGUIClick", gui.goWindow, function () 
            if source == gui.goWindow then 
                local selectedplace = guiGridListGetSelectedItem(gui.manager) 
                if selectedplace == 1 -- LS 
                    setElementPosition(getRootElement(), data[ls][4], data[ls][5], data[ls[6]) 
                    setElementRotation(getRootElement(), 0, 0, data[ls][9]) 
                    setElementInterior(getRootElement(), data[ls][7]) 
                    setElementDimension(getRootElement(), data[ls][8]) 
                end 
            end 
end, false) 
  

I've tried but I'm not sure how to find out if the player has selected LS, SF or LV.

This doesn't work btw.

Posted
  
function openTeleportMenu(locationData) 
    if locationData and type(locationData) == "table" then 
        data = locationData 
    end 
    terminateLocationManager() 
    showCursor(true) 
    local w, h = 400, 250 
    gui.manager = guiCreateWindow(0, 0, w, h, "Admin Teleporter © Almighty", false) 
    exports.global:centerWindow(gui.manager) 
    gui.grid = guiCreateGridList(10, 23, 380, 172, false, gui.manager) 
    gui.colID = guiGridListAddColumn(gui.grid, "ID", 0.1) 
    gui.colName = guiGridListAddColumn(gui.grid, "Name", 0.3) 
    gui.colDesc = guiGridListAddColumn(gui.grid, "Description", 0.5) 
    for v, k in pairs(data) do 
        gui.row = guiGridListAddRow(gui.grid) 
        local a, b = gui.grid, gui.row 
        guiGridListSetItemText(a, b, gui.colID, data[v][1], false, true) 
        guiGridListSetItemText(a, b, gui.colName, data[v][2], false, false) 
        guiGridListSetItemText(a, b, gui.colDesc, data[v][3], false, false) 
    end 
    gui.closeWindow = guiCreateButton(299, 205, 91, 35, "Close", false, gui.manager) 
    addEventHandler("onClientGUIClick", gui.closeWindow, function () 
            if source == gui.closeWindow then 
                terminateLocationManager() 
            end 
    end, false) 
    gui.goWindow = guiCreateButton(5, 205, 91, 35, "Go", false, gui.manager) 
    addEventHandler("onClientGUIClick", gui.goWindow, function () 
            if source == gui.goWindow then 
                local selectedplace = guiGridListGetSelectedItem(gui.manager) 
                if selectedplace == 1 -- LS 
                    setElementPosition(getRootElement(), data[ls][4], data[ls][5], data[ls[6]) 
                    setElementRotation(getRootElement(), 0, 0, data[ls][9]) 
                    setElementInterior(getRootElement(), data[ls][7]) 
                    setElementDimension(getRootElement(), data[ls][8]) 
                end 
            end 
    end, false) 
end 
addCommandHandler("tpmenu", openTeleportMenu, false, false) 
  

It's on line 28 - 39.

Posted
I want it so anybody can use it for now, and the code works fine. I'd just like to know how to find out which row is selected.

Yes, im making it now, 5mins and the code will be done with all features and clear !

Posted

I re-made the script from the Zero, it's without bugs and clear i just tested it , works perfectly there are two sides , server / client, copy them correctly and i hope that i helped you,

have fun scripting !

--client side

local w, h = 400, 250 
local window = guiCreateWindow(0, 0, w, h, "Admin Teleporter © Almighty", false) 
guiSetVisible (window, false)   
guiWindowSetSizable(window,false) 
local grid = guiCreateGridList(10, 23, 380, 172, false, window) 
local col1 = guiGridListAddColumn(grid,"ID",0.4) 
local col2 = guiGridListAddColumn(grid,"Name",0.37) 
local col3 = guiGridListAddColumn(grid,"Description",0.13) 
local transport = guiCreateButton(5, 205, 91, 35, "Go", false, window) 
local cancel = guiCreateButton(299, 205, 91, 35, "Close", false, window)  
   
function viewGUI (aTable) 
  if ( source == getLocalPlayer() ) then 
    guiSetVisible (window, true) 
    showCursor (true) 
    if guiGetVisible(window) then 
    guiGridListClear(grid) 
       for index ,val in ipairs (aTable) do 
       local row = guiGridListAddRow (grid) 
       guiGridListSetItemText (grid, row, col1, val[1], false, true) 
       guiGridListSetItemText (grid, row, col2, val[2], false, false) 
       guiGridListSetItemText (grid, row, col3, val[3], false, false) 
      end 
    end 
  end 
end 
addEvent ("showGui", true) 
addEventHandler ("showGui", root, viewGUI) 
  
addEventHandler ("onClientGUIClick", root, 
function () 
      if (source == cancel) then 
      if guiGetVisible(window) ~= nil then 
       guiSetVisible (window, false) 
       showCursor(false) 
       end 
     elseif (source == transport) then 
      local row = guiGridListGetSelectedItem(grid) 
      if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end 
      guiSetVisible(window,false) 
      showCursor(false)  
      triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1)   
   end 
end) 

--server side:

--X, Y, Z, Int, Dim, Rot; 
local data = {                                                              
[1] = {"1", "Los Santos", "Teleports you to Pershing Square, Los Santos.", 1479.9873046875, -1710.9453125, 13.36874961853,   0,  0,  0}, 
[2] = {"2", "San Fierro", "Teleports you to Doherty, San Fierro.", -1988.5693359375, 507.0029296875, 35.171875,  0,  0,  90}, 
[3] = {"3", "Las Venturas", "Teleports you to The Strip, Las Venturas", 1691.6801757813,     1449.1293945313,    10.765375,  0,  0,  268}, 
} 
  
addCommandHandler("tpmenu", 
function (player, commandName) 
    triggerClientEvent (player,"showGui", player, data) 
end) 
  
addEvent ("warp",true) 
addEventHandler ("warp",root, 
function (i) 
local data = data[i] 
local x, y, z = data[4], data[5], data[6] 
local int , dim = data[7], data[8] 
fadeCamera(source, false) 
setTimer(fadeCamera, 2200, 1, source, true) 
setTimer(setElementPosition,2000,1,source, x, y, z) 
setTimer(setElementDimension,2000,1,source, dim) 
setTimer(setElementInterior,2000,1,source, int) 
setCameraTarget(source, source) 
end)    

--meta.xml

    "KariM"  type="script" name="Transporter GUI" version="1.0" /> 
    

~Regards,

KariM

Posted

One more thing, I'm not sure if it's possible but I'll ask.

Is it possible to make a command (for example /addnewpos) which adds a new teleport location to the data table from in-game? I'm not sure if it's possible, but I'd like to make my teleport system completely dynamic.

Posted
One more thing, I'm not sure if it's possible but I'll ask.

Is it possible to make a command (for example /addnewpos) which adds a new teleport location to the data table from in-game? I'm not sure if it's possible, but I'd like to make my teleport system completely dynamic.

It's possible

Posted
How would I do that? Is there a function which will add a row to my data table?
table.insert 

Also you've to use this function to get the player's position when you type the cmd

getElementPosition 

Posted
table.insert 

This function is used to inserts element in table and in this situation you need to store player position what you typed in game

You can also use,

table.remove 

to remove what you stored in the table

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