Jump to content

Search the Community

Showing results for tags 'table'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Multi Theft Auto: San Andreas 1.x
    • Support for MTA:SA 1.x
    • User Guides
    • Open Source Contributors
    • Suggestions
    • Ban appeals
  • General MTA
    • News
    • Media
    • Site/Forum/Discord/Mantis/Wiki related
    • MTA Chat
    • Other languages
  • MTA Community
    • Scripting
    • Maps
    • Resources
    • Other Creations & GTA modding
    • Competitive gameplay
    • Servers
  • Other
    • General
    • Multi Theft Auto 0.5r2
    • Third party GTA mods
  • Archive
    • Archived Items
    • Trash

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Gang


Location


Occupation


Interests

  1. Lua tables are a fundamental data structure that allows you to store key-value pairs and create complex data structures. Tables in Lua are versatile and can contain values of different types. Let's dive into a detailed explanation with examples : Table Creation: To create a table in Lua, you use curly braces { } and separate the elements with commas. Here's an example: local table = {1, 2, 3, 4, 5} -- table crt In the above example, we created a table named table and populated it with values 1, 2, 3, 4, and 5. Accessing Table Elements: You can access table elements by using square brackets [ ]. Indices in Lua start from 1. Here's an example: -- Accessing table elements print(table[1]) --output : 1 print(table[3]) --output : 3 In the above example, we access the value at the 1st index (1) and the 3rd index (3) of the table. Adding Elements to a Table: To add a new element to a table, you specify the index and the value. If the specified index already exists in the table, the value will be overwritten. Here's an example: -- Removing elements from a table table[3] = nil In the above example, we remove the element at the 3rd index of the table. Getting the Size of a Table: To get the size of a table (i.e., the number of elements), you can use the # operator. Here's an example: -- Getting the size of a table print(#table) -- 5 In the above example, we print the size of the table using the # operator. Table Iteration: You can iterate over the elements in a table using the ipairs or pairs functions. ipairs provides index-based iteration, while pairs provides key-based iteration. Here's an example: -- Table iteration for index, value in ipairs(table) do print(index, value) end In the above example, we iterate over the table using ipairs and print the index and value of each element. +---------------------------------------------------+ | Game Settings | +---------------------------------------------------+ | Difficulty: | Hard | | Sound Volume: | 80% | | Controls: | Keyboard & Mouse | | Graphics Quality: | High | +---------------------------------------------------+ In the above example, an ASCII art representation is used to display a Lua table representing game settings. The table consists of different elements representing various game settings. Here's the Lua code that represents the table: local gameSettings = { difficulty = "Hard", soundVolume = "80%", controls = "Keyboard & Mouse", graphicsQuality = "High" } In the Lua code, a table named "gameSettings" is created, and different elements representing game settings such as difficulty, sound volume, controls, and graphics quality are added to the table. local person = { name = "Eren", age = 20, occupation = "Software Engineer", country = "Germany" } local tableFormat = [[ +-----------------------+ | Person Info | +-----------------------+ | Name: %s | | Age: %d | | Occupation: %s | | Country: %s | +-----------------------+ ]] local formattedTable = string.format(tableFormat, person.name, person.age, person.occupation, person.country) print(formattedTable) In the example above, we create a Lua table named "person" and populate it with some sample information about a person. We then define a string format named "tableFormat" which represents an ASCII table structure. We use placeholders like %s and %d to indicate the places where the values from the "person" table will be inserted. Finally, we use the string.format function to fill in the format with the data from the "person" table and store it in the variable "formattedTable". We print the "formattedTable" to display the final result. I explained string methods in the previous tutorial, here is the link: string methods LINK Output : +-----------------------+ | Person Info | +-----------------------+ | Name: Eren | | Age: 20 | | Occupation: Software Engineer | | Country: Germany | +-----------------------+ Nested Tables: Tables can contain other tables, allowing you to create nested or multidimensional data structures. Here's an example: -- Nested tables local team = { name = "Team A", players = { { name = "Eren", age = 20 }, { name = "Emily", age = 27 }, { name = "Angela", age = 23 } } } print(team.name) -- Team A print(team.players[2].name) -- Emily In the above example, we created a table named team with two elements: name and players. The players element is a nested table that contains information about individual players. We access the name element of the team table and the name of the player at the 2nd index of the players table. Table Insertion and Removal: Lua provides various functions for inserting and removing elements from tables. Here's an example that demonstrates these operations: -- Table insertion and removal local fruits = {"apple", "banana"} table.insert(fruits, "orange") -- Insert an element at the end table.insert(fruits, 2, "grape") -- Insert an element at the 2nd index table.remove(fruits, 1) -- Remove the element at the 1st index for index, fruit in ipairs(fruits) do print(index, fruit) end In the above example, we start with a table named fruits containing two elements. Using table.insert, we add an element at the end and another element at the 2nd index. Then, using table.remove, we remove the element at the 1st index. Finally, we iterate over the modified fruits table and print the index and value of each element. Table Concatenation: Lua allows you to concatenate tables using the .. operator. Here's an example: -- Table concatenation local table1 = {1, 2, 3} local table2 = {4, 5, 6} local mergedTable = {} for _, value in ipairs(table1) do table.insert(mergedTable, value) end for _, value in ipairs(table2) do table.insert(mergedTable, value) end for index, value in ipairs(mergedTable) do print(index, value) end In the above example, we have two tables named table1 and table2. We create an empty table named mergedTable and use table.insert to concatenate the elements from table1 and table2 into mergedTable. Finally, we iterate over mergedTable and print the index and value of each element. for MTA:SA Player Information: Lua tables can be used to store player information in MTA:SA. Below is an example of a player table that contains details such as the player's name, level, and score: local player = { name = "Eren", level = 5, score = 1000 } In the above example, we create a table named "player" and populate it with the player's name, level, and score. Vehicle List: Lua tables can be utilized to store data related to vehicles in MTA:SA. Here's an example of a vehicle table that includes the model names and colors of the vehicles: local vehicles = { { model = "Infernus", color = {255, 0, 0} }, { model = "Bullet", color = {0, 0, 255} }, { model = "Sultan", color = {0, 255, 0} } } In the above example, we create a table named "vehicles" and store each vehicle as a separate table with its model name and color data. Colors are represented using RGB values. NPC (Non-Player Character) List: Lua tables can be used to store in-game NPCs in MTA:SA. Here's an example of an NPC list table that includes the model IDs and coordinates of the NPCs: local npcs = { { model = 23, x = 100, y = 200, z = 10 }, { model = 56, x = 150, y = 250, z = 15 }, { model = 89, x = 200, y = 300, z = 20 } } In the above example, we create a table named "npcs" and store each NPC as a separate table with their model ID and coordinates. I hope you will like it
  2. how to create any one vehicle that is listed in the table, with a delay per minute and a filter for re-creating the transport and the maximum number (car dealership)? server carTable = { -- id price x y z rz {475,5000,-2149,-775.5,32,-90}, {411,5000,-2149,-769.5,32,-90}, {416,5000,-2149,-763.5,32,-90}, {466,5000,-2149,-757.5,32,-90}, } icon = { {1239,3,-2137,-746,32} } function sveh (id) for k,v in pairs(carTable)do createVehicle(v[1],v[3],v[4],v[5],0,0,v[6]) end end addEventHandler('onResourceStart',resourceRoot,sveh) function pick () for k,v in pairs(icon) do local sicon = createPickup(v[3],v[4],v[5],v[2],v[1],0) end end addEventHandler('onResourceStart',resourceRoot,pick) addEventHandler('onPickupHit',resourceRoot, function(e) if isElement(e)then triggerClientEvent('visibleSalonWindow',e,e) end end) client carTable = { {475,5000,-2149,-775.5,32,-90}, {411,5000,-2149,-769.5,32,-90}, {416,5000,-2149,-763.5,32,-90}, {466,5000,-2149,-757.5,32,-90},} function drawTextOnPosition(x,y,z,price,id,number) if (getDistanceBetweenPoints3D(x,y,z,getElementPosition(localPlayer))) < 5 then local coords = {getScreenFromWorldPosition(x,y,z)} if coords[1] and coords[2] then dxDrawText("Транспорт продается",coords[1],coords[2],coords[1],coords[2], tocolor(0,0,0), 1.01, "default-bold", 'center', 'center') dxDrawText("Транспорт продается",coords[1],coords[2],coords[1],coords[2], tocolor(156,98,40), 1, "default-bold", 'center', 'center') dxDrawText("Модель: "..getVehicleNameFromModel( id )..'('..id..')',coords[1],coords[2]+20,coords[1],coords[2]+20, tocolor(0,0,0), 1.01, "default-bold", 'center', 'center') dxDrawText("Модель: "..getVehicleNameFromModel( id )..'('..id..')',coords[1],coords[2]+20,coords[1],coords[2]+20, tocolor(176,180,176), 1, "default-bold", 'center', 'center') dxDrawText("Стоимость "..price..'$.',coords[1],coords[2]+40,coords[1],coords[2]+40, tocolor(0,0,0), 1.01, "default-bold", 'center', 'center') dxDrawText("Стоимость "..price..'$.',coords[1],coords[2]+40,coords[1],coords[2]+40, tocolor(176,180,176), 1, "default-bold", 'center', 'center') end end end addEventHandler('onClientRender',root,function() for k,v in pairs(carTable) do drawTextOnPosition(v[3],v[4],v[5]+1,v[2],v[1]) end end) GUIEditor = { button = {}, window = {}, label = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(0.36, 0.18, 0.27, 0.64, "Атосалон Эконом-класса", true) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.button[1] = guiCreateButton(0.39, 0.93, 0.22, 0.05, "Закрыть", true, GUIEditor.window[1]) guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") GUIEditor.label[1] = guiCreateLabel(0.05, 0.03, 0.92, 0.03, "В данном автосалоне вы сможете купить ато Эконом класса :", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-bold-small") guiLabelSetHorizontalAlign(GUIEditor.label[1], "center", false) guiLabelSetVerticalAlign(GUIEditor.label[1], "center") GUIEditor.label[2] = guiCreateLabel(0.05, 0.10, 0.92, 0.14, "Infernus, Sabre, Glendale, Sabre Turbo", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[2], "default-bold-small") GUIEditor.label[3] = guiCreateLabel(0.05, 0.61, 0.92, 0.03, "Авто добовляется из-за рубежа каждые 2 часа", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[3], "default-bold-small") GUIEditor.label[4] = guiCreateLabel(0.05, 0.76, 0.92, 0.03, "На данный момент ожидаем поставку ", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[4], "default-bold-small") GUIEditor.label[5] = guiCreateLabel(0.05, 0.79, 0.92, 0.03, "До прибытя осталось: \"\"", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[5], "default-bold-small") GUIEditor.label[6] = guiCreateLabel(0.05, 0.83, 0.92, 0.03, "Стоимость: $\"\"", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[6], "default-bold-small") guiSetVisible(GUIEditor.window[1],false) end ) bindKey( "x", "down", function( ) local state = not guiGetVisible(GUIEditor.window[1] ) guiSetVisible(GUIEditor.window[1], state ) showCursor( state ) end ) function visible () if guiGetVisible(GUIEditor.window[1]) then guiSetVisible(GUIEditor.window[1],false) showCursor(false) else guiSetVisible(GUIEditor.window[1],true) showCursor(true) end end addEvent('visibleSalonWindow',true) addEventHandler('visibleSalonWindow',localPlayer,visible) addEventHandler('onClientGUIClick',resourceRoot,function(button,state) if button == "left" and state == "up" then if source == GUIEditor.button[1] then guiSetVisible(GUIEditor.window[1],false) showCursor(false) end end end)
  3. Hello everyone, I need your help with something please. I'm trying to create something like pick items and stuff like that, plants, mushrooms, etc etc. This creates a table with Objects and Collisions. I want to know how can I delete just the collision that I hit and the object in that position as well, not the other elements in the table just the elements that I hit. local sx,sy = guiGetScreenSize() local px,py = 1280,720 local x,y = (sx/px), (sy/py) playerSeta = getLocalPlayer() local Pos_Seta = { {323.9013671875, 2490.8134765625, 15.484375}, {335.341796875, 2486.669921875, 15.484375}, {330.0751953125, 2496.310546875, 15.484375}, {325, 2480.7265625, 15.484375} } for i,v in ipairs (Pos_Seta) do Obj_Seta = createObject(2427, v[1],v[2],v[3]) setObjectScale(Obj_Seta, 1.5) Col_Seta = createColSphere (v[1],v[2],v[3], 1.5) Blip_Seta = createBlip(v[1],v[2],v[3], 33, 2.5, 255, 0, 0, 255, 0, 100) addEventHandler( "onClientColShapeHit", Col_Seta, function(pSeta) if pSeta == playerSeta then addEventHandler('onClientRender', getRootElement(), Text_Seta) bindKey('F','down',StartSeta, playerSeta) end end) addEventHandler( "onClientColShapeLeave", Col_Seta, function(pSeta) if pSeta == playerSeta then removeEventHandler('onClientRender', getRootElement(), Text_Seta) unbindKey('F','down',StartSeta, playerSeta) end end) end function StartSeta () triggerServerEvent ( "StartSeta", localPlayer) unbindKey('F','down',StartSeta, playerSeta) end function Text_Seta () dxDrawText("Use (F) to pick this item", x*481, y*483, x*800, y*501, tocolor(255, 255, 255, 255), 1.35, "default-bold", "center", "top", false, false, false, false, false) end
  4. alguem consegue me ajudar, tentei fazer um codigo como se fosse um botão que iria aumentar a quantidade que você vai "comprar" mas ele só adicona o item 1 vez e eu queria que adicionasse 1 vez a cada click que o player fizer alguem tem alguma ideia de como me ajudar? Codigo: shop = { prodAtual = 0, adc = 1, novosProdutos = 0 } function compra(button, state) if shpPainel == true then if isMouseInPosition(screenW * 0.6453, screenH * 0.3516, screenW * 0.0445, screenH * 0.0645) then if (button == "left") then if (state == "down") then shop.novosProdutos = (shop.prodAtual + shop.adc) print(shop.novosProdutos) return (shop.novosProdutos) end end end end end addEventHandler("onClientClick", root, compra)
  5. table = {} function table.contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end function tablefind(tab,el) for index, value in pairs(tab) do if value == el then return index end end end function OnClientGuiButton() if not table.contains(BedwarsEQ, "P1") then table.insert(table, "P1") -- Insert to a table string "P1" (Player1) end if tablefind(table, "P1")==1 then -- check index, if is Item in index(1) then == true AdxItem1 = 255 -- dxDrawImage, drawing image to effect SLOT1 = SLOT1 + 1 -- type how many items is in P1 end if tablefind(table, "P1")==2 then -- if is Item in index(1) then check "if is Item in Index(2)" == true BdxItem1 = 255 --second dxDrawImage, drawing image to effect SLOT2 = SLOT2 + 1 --type how many items is in P1 end end addEvenetHandler("onClientGUIClick", button, OnClientGuiButton I will explain the problem. The problem is that when I press the button that gives me to the table "P1", it checks in which index it is. There is a problem that if I click on another button that gives me "P2", it doesn't prove that "P2" is in the table. Debugscript writes to me that the wrong first argument is given in the tableFind function, and that's strange because I checked twice and gave the right one. What's wrong with that?
  6. redditing

    Table

    I wanted to ask if there is a way to check what index the value in the table is for example, t = {} table.insert(t,"Hello") table.insert(t,"HELLO") table.insert(t,"HI") if index==1 and value=="HI" then -- false --do something elseif index==0 and value=="HELLO" then --false --do something elseif index==2 and value=="HI" then --true --do something else --etc. --do something end --If someone does not distinguish the index from the value then the index is for example [0,1,2,3 ...] and the value is an element for example print(t[1]) -------------> 'HELLO'
  7. I have this: -- 2 points on each city. local spawnCoords = { {1125, -2036, 69.89, -90}, {2504, -1686, 13.55, 45}, {-1972, 643, 46.57, -45}, {-2720, -317, 7.85, 45}, {2023, 1008, 10.83, -90}, {1298, 2084, 12.83, -90}, } -- all skins. local validSkins = {0, 1, 2, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312} function spawnPoints (player) local x,y,z,r = unpack(spawnCoords[math.random(1,#spawnCoords)]) spawnPlayer(source, x, y, z, r, validSkins[math.random(1,#validSkins)]) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerJoin", getRootElement(), spawnPoints) Althought it works, after giving it several tests, I realized the spawn locations where always in the same order, as well as the skins. Coincidentally, I've reached the tables subject in the MTA's tutorial, and I learned about <for key, value in pairs(table) do>. Contrary to "ipairs", "pairs" is supposed to give you a random reading throughout the table everytime the script is ran. I used 'broph.Lua' as a way to understand the process, and to make sure that if I do the same, it'll work. My small knowledge told me that, by adding <for key, value in pairs(spawnCoords) do> right after the beginning of the function, I would get the random effect of the table reading. However, the result is far from what I expected: it destroys the function, and the player doesn't spawn at all (black screen). I'm continuing the tutorial, but 'in pairs' is the last thing NanoBob mentions about the tables. This time, I'd like a bit of a challenge, so if you could give me the hints and point me in the right direction, I would appreciate that.
  8. Iae rapaziada, seguinte fiz um code simples só para aprender melhor tabela, até agora estava tudo normal criando as markers, a mensagem na tela e tudo mais.... porém agora estou com o seguinte problema: São 3 markers cada uma tem uma cadeira do lado. O que tenho em mente é que quando o player hitar uma das markers binde a tecla E, ao pressiona-la ele é colocado sobre a cadeira em que ele esta próximo. Mas no sistema atual o problema é que ele não reconhece qual cadeira é! Quero saber como eu posso fazer uma verificação para saber se a marker é da cadeira [1], [2] ou [3]. Code: local posChairs = { [1] = {1579.4000244141,-1675.8000488281 ,15.199999809265}, -- cadeira interrogado (suspeito) 1 [2] = {1580, -1677.5, 15.199999809265}, -- cadeira interrogado (suspeito) 2 [3] = {1582.0999755859, -1676.3000488281, 15.199999809265}, -- -- cadeira interrogador (policial) } local chairTable = {} function resStart() for i, chair in ipairs(posChairs) do chairTable[i] = createMarker(chair[1], chair[2], chair[3], "cylinder", 1.2, 255,0, 0, 100) outputChatBox(tostring(chairTable[i])) addEventHandler("onMarkerHit", chairTable[i], hittingMk) addEventHandler("onMarkerLeave", chairTable[i], leavingMk) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), resStart) function resStopCircle() if chairTable[i] then destroyElement(chairTable[i]) chairTable[i] = nil outputChatBox(tostring(chairTable[i])) end end addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), resStopCircle) function hittingMk (element, md) if (md) then if getElementType(element) == "player" then outputChatBox("hitou") exports.inMarkerMsg:create(element, "pressione E para sentar") end end end function leavingMk (element, md) if (md) then if getElementType(element) == "player" then outputChatBox("saiu") exports.inMarkerMsg:delete(element) end end end Obs: estou ciente que se eu criar 3 variáveis e 3 eventos uma para cada cadeira dará certo (já testei e consegui!), porém irei criar mais cadeiras além de utilizar esse sistema em outras coisas! fazendo um for com a tabela (chairTable), percebi que há uma edentação um "prefixo" e um "valor": for k,v in pairs(chairTable) do outputChatBox("chairTable "..tostring(k)..", "..tostring(v)) end Retorna: chairTable 1, userdata: 0x7289 chairTable 2, userdata: 0x728c chairTable 3, userdata: 0x728f Tentei fazer uma verificação com if dessa forma (porém sem exito) : if chairTable[1] then outputChatBox("hitou1") elseif chairTable[2] then outputChatBox("hitou2") elseif chairTable[3] then outputChatBox("hitou3") end Será que tem como eu especificar a cadeira sem ter que criar para cada cadeira(marker), um evento e uma variável?
  9. local table = { {"1", "2", "3", "4"}, } function asdasdsdasdd() table.insert(table,"5","6","7","8") end What wrong? No errors and warnings in debugscript 3...
  10. Boa noite rapaziada, bom eu to fazendo um painel login e adicionei 3 musicas que tocam aleatoriamente em uma tabela nomeada (Tab_Musicas), no entanto ao player entrar na tela de login eu gostaria que aparecesse o nome da musica a qual esta tocando! E é ai que entra minha duvida. Como eu poderia estar especificando em um dxDrawText qual musica esta tocando no momento? Linhas de código abaixo: Tabela: local Tab_Musicas = {"musicas/musica1.mp3", "musicas/musica2.mp3", "musicas/musica3.mp3"} Momento em que a musica se inicia: function onClientResourceStart() fadeCamera(true, 5) setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316) sound = playSound(Tab_Musicas[math.random(1, #Tab_Musicas)], false) ... Print do P/Login, no estado atual (a musica se encontra no canto superior direito):
  11. I created a scoreboard system, but when i make a team, the team does not show in scoreboard.. how can i add this after playerlist?
  12. client: local Admins = {} addEvent("updateAdmins",true) addEventHandler("updateAdmins",root, function(t) Admins = t end) function isPlayerAdmin(player) if(Admins[player]) then return true end return false end function asdi() for k,v in ipairs(Admins) do outputChatBox(k) end end addCommandHandler("asd",asdi) server: local Admins = {} function isPlayerAdmin(player) if(Admins[player]) then return true end return false end addEventHandler("onPlayerLogin",root, function() if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then if not(Admins[source])then Admins[source]= source triggerClientEvent("updateAdmins",source,Admins) end end end) addEventHandler("onPlayerQuit",root, function() if(Admins[source])then Admins[source]= nil triggerClientEvent("updateAdmins",source,Admins) end end) No errors, no warnings... What wrong?
  13. if i create a table, and i insert datas with table.insert, the datas are deleted when i reconnect.. why? how to save datas? sorry for my terrible english :ss
  14. local vehicles = {} addEventHandler("cmdHandler",getRootElement(), function(thePlayer, command) if(command == "/dveh") then for i, v in ipairs (vehicles) do local player, veh = unpack(v) if (player == thePlayer) then destroyElement (veh) table.remove (vehicles, i) return end end end end ) Hi, I want the script to delete all vehicles and rows, but it only deletes the last one, why ?
  15. Why the table disappears after the cycle? Never this was not. shel = {} local shelPlaces = { [1] = { [1] = {x=0,y=0,z=0}, [2] = {x=0,y=0,z=0}, [3] = {x=0,y=0,z=0}, }, } function createShelters(gameId, players) local gameId = tonumber(gameId) shel[gameId] = {} for i=1,#shelPlaces do --outputDebugString("table "..shel[gameId]) shel[gameId][i] = { ["places"] = { [1] = {x=shelPlaces[i][1].x,y=shelPlaces[i][1].y,z=shelPlaces[i][1].z,["object"]="craftTable"}, }, } outputChatBox(shel[1][1]["places"][1]["object"]) -- WORKING for pI=2,#shelPlaces[i] do shel[gameId][i]["places"] = { [pI] = {x=shelPlaces[i][pI].x,y=shelPlaces[i][pI].y,z=shelPlaces[i][pI].z,["object"]=false}, } end end createCraftsTable(gameId) end addEventHandler("onGameStarted", root, createShelters) function createCraftsTable() --for i=1,10 do --for name,object in pairs(shel[gameId][i]) end function tempSpawn() spawnPlayer(source, 0,0,5) setCameraTarget(source, source) end addEventHandler("onPlayerLogin", root, tempSpawn) function startTest(pSource, command, gameId) triggerEvent("onGameStarted", root, gameId) end addCommandHandler("gameTest", startTest) function getGameInfo() outputChatBox(shel[1][1]["places"][1]["object"]) -- NOT WORKING end addCommandHandler("gInfo", getGameInfo)
  16. Hello, I am scripting a new chat and the stuff I scripted is working. But now I have a problem. In my chat I am printing the first 13 messages in dxDraw. But now I want all indexes to +1, so if there come a 14th message it gets visible. local offset = 14 function drawChat() for i, v in ipairs (chatbox) do if (i < offset) then exports.login:dxDrawBorderedText(v, 36, (210 - ((offset-i)*15)), 411, 210, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) elseif (i == 14) then --what to add ? I want all index to +1, so the new message will get the first index end end end addEventHandler ("onClientRender", root, drawChat)
  17. Hello, I have been writing gamemode for a long time, everything that is important (information about the vehicle, player, object) is stored on the server side in the table. My question is: what is safer and more optimal? Variables saved on the server side in the table and called to the client by events or elementData?
  18. I want create a script, which create a marker with random position, from a table. How to make this?
  19. Hello. As you can see, in my script i attached 2 weapons to a vehicle. I set a bind for shooting one of the gun. My problem is that when i start the function called "fire_gun_c" then both of the weapons will be fired. So my question is how can i only shoot the weapon "gun1" by using getAttachedElements? client function attach() local gun1 = createWeapon(31, 0,0,0) local gun2 = createWeapon(31, 0,0,0) attachElements ( gun1, veh, 0, 1, 0) attachElements ( gun1, veh, 0, -1, 0) end function fire_gun_c(veh) local attachedElements = getAttachedElements(veh) for ElementKey, ElementValue in ipairs ( attachedElements ) do fireWeapon ( ElementValue ) -- it fires both of the guns because it gets all the data with getAttachedElements end end addEvent("fire_gun_c", true) addEventHandler ( "fire_gun_c", resourceRoot, fire_gun_c)
  20. Hey, I have a problem this code working player in server. But no working when player quit. exitLobby = function(self) local previousLobby = getElementData(localPlayer, "player:selectedLobby") if previousLobby then if self.lobbies[previousLobby] then for k,v in ipairs(self.lobbies[previousLobby].players) do if v == localPlayer then table.remove(self.lobbies[previousLobby].players, k) end end end end setElementData(resourceRoot, "root:lobbies", self.lobbies) setElementData(localPlayer, "player:selectedLobby", false) exports["br_notifications"]:addNotification(localization:getText(localPlayer, "lobby-leftInRoom"), "success") end
  21. Hello everyone! I am beginner in all of this. I am a hobby scripter, because I have interest in scripting. BUT I have problem. I want to make a skill system(like you shoot a leg you get 1points for that), and I found a free resource that varies your skill up to 999 in server side and I found another one that do this client side.(also I won't use it like my scripts in a server) OK I have problems with client AND server side too. I can't connect and update the variable. I created a table for the UZI skill (uzi_skill) to try it, but I can't get working. Original source: https://community.multitheftauto.com/index.php?p=resources&s=details&id=11129 This is just the Uzi skill section. The skill is tied to the character-system. (db: character-system -> table: uzi_skill [tinyint(4)] ) function uzi ( attacker, attackerweapon, bodypart, loss ) local statz = getPedStat(attacker, 75) local healthh = getElementHealth(source) local setstat = statz + (100.0 - healthh) * 0.05 local cteam = getPlayerTeam(attacker) local pteam = getPlayerTeam(source) --exports['skill']:changeProtectedElementDataEx(source, "uzi_skill", tonumber(setstat)) <--- I tried with this. Complete FAIL(I know why) if getTeamName(cteam) == getTeamName(pteam) then return false elseif attacker and getElementType(attacker) == "player" and (attackerweapon == 28 or attackerweapon == 32) and (statz < 999) then setPedStat(attacker, 75, setstat) end if (statz > 980) then setPedStat(attacker, 75, 999) end end addEventHandler("onPlayerDamage", getRootElement(), uzi) I want a bit help, just one example how to do this with this. (Please don't ask in fragments. Also I don't know where to put that script fragment). I'd be happy if someone could help me
  22. Hello, I am creating a PIN system on my server and wanted to ask you for help in my code. When I send the client to the server a trigger wanted to validate if the pin sent from the client to the server is an element of my table if yes setElementData will work and the Pin used will be unable to use again but in my script when it uses a pin all The others are disabled, can you help me? Note: I'm Brazilian, I'm sorry for English. local pins15k = {"UAIFKAJDKEFC15K", "KYJFKAJDEFKC15K", "BESFKSLLKEFC15K"} function PinEdit(Pin) if validatePin(Pin) then if getElementData(source, "Diamond") then setElementData(source, "Diamond", getElementData(source, "Diamond")+10000) else setElementData(source, "Diamond", 10000) end for k, v in ipairs(pins15k) do outputChatBox("["..k.."] = "..v) end else outputChatBox("Pin invalido", source) outputChatBox(tostring(pins15k)) end end addEvent("PinEdit", true) addEventHandler("PinEdit", getRootElement(), PinEdit) function validatePin(pin) local result = false for k, v in ipairs(pins15k) do if (pin == v) then pins15k[k] = nil result = true break end end return result end
  23. Hello again. I have problem with table.insert. I have vehicle shop that saves data to tables and tables to element data. Always when you buy new vehicle, it should add sub-table to main-table and fill sub-table with data that i want to save. I also have panel where you can control your vehicles. Instead of showing data, the gridlist shows only number 1 in first column. Part of my code: [Server] local data = getElementData(client, "wangcars.data") if not data then setElementData(client, "wangcars.data", {}) end local data = getElementData(client, "wangcars.data") local ids = #data + 1 local x, y, z = getElementPosition(wangvehicle[client]) local rx, ry, rz = getElementRotation(wangvehicle[client]) local t = {} table.insert(t, getVehicleName(wangvehicle[client])) table.insert(t, tonumber(id)) table.insert(t, tonumber(ids)) table.insert(t, tonumber(price)) table.insert(t, c1 .. ", " .. c2 .. ", " .. c3 .. ", " .. c4 .. ", " .. c5 .. ", " .. c6) table.insert(t, x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz) table.insert(t, "indrive") table.insert(data, t) setElementData(client, "wangcars.data", data) [Client] function refreshlist() guiGridListClear(vlist) guiGridListAddColumn(vlist, "Vehicle name", 0.3) guiGridListAddColumn(vlist, "Sell price", 0.3) guiGridListAddColumn(vlist, "ID", 0.3) local table = getElementData(localPlayer, "wangcars.data") if not table then setElementData(localPlayer, "wangcars.data", {}) end for i=1, #table do local row = guiGridListAddRow(vlist) guiGridListSetItemText(vlist, row, 1, table[i][1], false, false) guiGridListSetItemText(vlist, row, 1, table[i][4], false, false) guiGridListSetItemText(vlist, row, 1, table[i][3], false, false) end end The values are tested and they're working fine. No errors in debugscript.
  24. --[[ -- Resource Name: Information. -- Author: Om (RipeMangoes69) -- Date: 4/12/2016 -- File: client.lua ]]-- -- GUI GUIEditor = { window = {}, label = {}, memo = {} } function createInfoObjects() local markers = { {area = "Los Santos Airport", x = 1582.45, y = -2286.32, z = 12}, {area = "Las Vegas Airport", x = 1674.30859375, y = 1444.9501953125, z = 9.2} } for _, m in ipairs(markers) do local marker = createMarker(m.x, m.y, m.z, "cylinder", 1, 255, 255, 255, 100) GUIEditor.window[1] = guiCreateWindow(645, 250, 266, 378, "Information: " .. m.area, false) guiWindowSetSizable(GUIEditor.window[1], false) guiSetVisible(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(5, 353, 190, 15, "* Click anywhere on GUI Window to close it.", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-small") GUIEditor.memo[1] = guiCreateMemo(9, 24, 247, 324, "", false, GUIEditor.window[1]) guiMemoSetReadOnly(GUIEditor.memo[1], true) end end addEventHandler("onClientResourceStart", getRootElement(), createInfoObjects) function openGUI( hitElement, matchingDimension ) if getElementType( hitElement ) == "player" then if isPedInVehicle(hitElement) then outputChatBox("You cannot access GUI from vehicle!", 255, 0, 0) guiSetVisible(GUIEditor.window[1], false) showCursor(false) else guiSetVisible(GUIEditor.window[1], true) showCursor(true) end end end addEventHandler("onClientMarkerHit", resourceRoot, openGUI) function closeGUI() guiSetVisible(GUIEditor.window[1], false) showCursor(false) end addEventHandler("onClientGUIClick", resourceRoot, closeGUI) How am i suppose to "change" the GUI Title ? (area in the table). thanks.
  25. Buenas, estoy creando un sistema de nametags cliente y estoy usando tablas, para que así cuando se loguee/desloguee, se muestre o no el texto en cuestión (el nametag). Todo va correcto, el problema que tengo es a la hora de usar table.insert, que sigue renderizando el nombre local nametags = { } local font = dxCreateFont( "fuente.ttf" ) addEvent( "nmtgs:onPlayerLogin", true ) addEvent( "nmtgs:onPlayerQuit", true ) addEventHandler( "onClientRender", root, function( ) if #nametags > 0 then for i=1, #nametags do local player = nametags[i] local px, py, pz = getElementPosition( player ) local x, y, z = getElementPosition( getLocalPlayer( ) ) local name = getPlayerNametagText( nametags[i] ):gsub("_"," ") end end end ) function addPlayerToTable( player ) if player then table.insert( nametags, player ) end end addEventHandler( "nmtgs:onPlayerLogin", getRootElement( ), addPlayerToTable ) function removePlayerFromTable( player ) if player and nametags[ player ] then table.remove( nametags, player ) end end addEventHandler( "nmtgs:onPlayerQuit", getRootElement( ), removePlayerFromTable ) ¿Alguna idea? Gracias de antemano.
×
×
  • Create New...