Jump to content

Shady1

Members
  • Posts

    765
  • Joined

  • Last visited

  • Days Won

    47

Everything posted by Shady1

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

    uncommon crash

    It might be related to the graphics driver, try updating your driver.
  3. function insideCar(source) local thePlayer = source local vehicle = getPedOccupiedVehicle(thePlayer) if vehicle then outputChatBox("You're in a car", thePlayer) else outputChatBox("You're on foot", thePlayer) end end addCommandHandler("check", insideCar)
  4. https://wiki.multitheftauto.com/wiki/SetElementVisibleTo Can you explain exactly what you want?
  5. local hidemark -- define hidemark as a global variable function createMarkers() hidemark = createMarker(10, 50, 5, "cylinder", 1, 0, 255, 0) end addEventHandler("onResourceStart", resourceRoot, createMarkers) function mark(thePlayer, matchingDimension) if matchingDimension and isElement(thePlayer) and getElementType(thePlayer) == "player" then local markerveh = createMarker(0, 0, 5, "cylinder", 1, 0, 255, 0) -- Do something with markerveh end end addEventHandler("onMarkerHit", hidemark, mark) function job1(thePlayer) setElementVisibleTo(hidemark, root, false) end addCommandHandler("hidemark", job1) this test code, i hope helps to you
  6. local screenW, screenH = guiGetScreenSize() addEvent("alarmSound", true) addEventHandler("alarmSound", localPlayer, function() sound = playSound3D("assets/sounds/alarm.mp3", 2310.35425, -7.48090, 26.74219, true) setSoundMaxDistance(sound, 150) end) addEvent("pBar", true) addEventHandler("pBar", localPlayer, function() function renderText() dxDrawText("Bomb Planting", screenW * 0.14, screenH * 0.48, screenW * 0.22, screenH * 0.51, tocolor(5, 229, 194, 255), 0.60, "bankgothic", "left", "top", false, false, false, false, false) end addEventHandler("onClientRender", root, renderText) local progressWidth = screenW * 0.2 local progressHeight = screenH * 0.03 local progressX = (screenW - progressWidth) / 2 local progressY = (screenH - progressHeight) / 2 progBar = guiCreateProgressBar(progressX, progressY, progressWidth, progressHeight, false) timeBar = 100 setTimer(function() timeBar = timeBar - 6.66666666667 lastTime = timeBar guiProgressBarSetProgress(progBar, lastTime) if lastTime <= 0 then guiSetVisible(progBar, false) removeEventHandler("onClientRender", root, renderText) end end, 1000, 15) end) I didn't test it, but I edited the visible parts, if there are any other problems, let me know.
  7. function clicks(button, state, _, _) if button == "left" and state == "up" then if source == closebutton then guiSetVisible(window, false) showCursor(false) elseif source == button then guiSetVisible(window, false) showCursor(false) triggerServerEvent("StartTreeJob", resourceRoot, localPlayer) end end end
  8. jobPed = createPed(230, 870.47406, -24.95437, 63.97986, 160) setPedFrozen(jobPed, true) jobMarker = createMarker(870.02686, -25.90853, 62.90933, "cylinder", 1.5) createBlipAttachedTo(jobMarker, 22) function job(thePlayer, matchingDimension) if thePlayer and thePlayer == localPlayer and matchingDimension then window = guiCreateWindow(500, 200, 250, 250, "*Tree JoB*", false) memo = guiCreateMemo(20, 20, 210, 140, "Unicos RP Tree Job. You can make easy money with this one. Happy happy happy.", false, window) button = guiCreateButton(30, 180, 80, 40, "Accept", false, window) closebutton = guiCreateButton(140, 180, 80, 40, "Close", false, window) showCursor(true) end end addEventHandler("onClientMarkerHit", jobMarker, job) function clicks(button, state) if button == "left" and state == "up" then if source == closebutton then guiSetVisible(window, false) showCursor(false) elseif source == button then guiSetVisible(window, false) showCursor(false) triggerServerEvent("StartTreeJob", resourceRoot, localPlayer) end end end addEventHandler("onClientGUIClick", root, clicks) I hope this helps!
  9. you're welcome,If you have a new question, please open a new topic and tag me.
  10. Using these parameters totally depends on your needs and game scripts. If you do not need this additional information, you can omit or pass these parameters. I added these parameters to trigger onVehicleCollision hitElement: Collision object. In this case, it will be the object or element the vehicle collides with. force: The force of collision. This is a numeric value representing the severity of the collision. bodyPart: The part of the body where the collision occurred. For example, vehicle hood, windshield, rear bumper. collisionX, collisionY, collisionZ: Coordinates of the point where the collision occurred. normalX, normalY, normalZ: The normal of the collision surface. This is a vector that indicates which direction the collision surface is in. material1, material2: Strings representing the material types of the colliding objects.
  11. local marker = -- The marker element you want to prevent the player from hitting function onVehicleCollision(hitElement, force, bodyPart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, material1, material2) if getElementType(hitElement) == "vehicle" then -- Check if the player is in a vehicle local player = getVehicleOccupant(hitElement) if player and getElementType(player) == "player" then -- Player is in a vehicle and colliding with the marker if isElementWithinMarker(hitElement, marker) then -- Do something here (e.g., cancel the collision, display a message, etc.) cancelEvent() end end end end addEventHandler("onVehicleCollision", root, onVehicleCollision)
  12. local marker = -- The marker element you want to prevent the player from hitting function onVehicleCollision(hitElement) if hitElement == localPlayer and getElementType(hitElement) == "vehicle" then -- Check if the player is in a vehicle if isElementWithinMarker(hitElement, marker) then -- Player is in a vehicle and colliding with the marker -- Do something here (e.g., display a message, play a sound, etc.) -- To prevent the collision, you can remove the vehicle's speed local vehicle = getPedOccupiedVehicle(hitElement) setElementVelocity(vehicle, 0, 0, 0) end end end addEventHandler("onClientVehicleCollision", root, onVehicleCollision) https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision
  13. timeBar = 100 progBar = guiCreateProgressBar(321, 533, 159, 34, false) setTimer(function() timeBar = timeBar - 6.66666666667 lastTime = timeBar guiProgressBarSetProgress(progBar, lastTime) if lastTime <= 0 then guiSetVisible(progBar, false) end end, 1000, 15) I didn't understand, but one detail caught my attention and I wanted to edit it.
  14. GTA:SA Download original version and reinstall MTA:SA https://www.g2a.com/grand-theft-auto-san-andreas-steam-key-global-i10000004439009
  15. You have multiple errors, I can say that you are having these problems because GTA:SA and MTA:SA are not properly installed and you are installing a modded game, delete the MTA:SA and GTA:SA files and install them again without mods.
  16. Shady1

    Voice chat bug

    update your sound drivers
  17. Another player like you asked this question and I gave him an answer, please read my answer.
  18. Hi @scolen , I will send you a link with a good explanation for making inventory system, I think you can do it by trying it,check the link I sent you and start creating the codes, if you have a problem and have problems in progress please continue with this topic and tell us more clearly what you couldn't do so we can give you good support
  19. Shady1

    BAN

    hello welcome to the forum, I already gave you an answer about this topic on the MTA Discord server, you should read it again.
  20. GPU driver issue, try updating them or rolling back / reinstalling
  21. Hello @Phoenix78 welcome to the Forum... I saw that you have used GTA:SA crack and I suggest you to download GTA:SA legit version as soon as possible and I suggest you to check your drivers.
  22. The answer to your question will depend on you, for example, the more you practice and you tend to learn, the faster you can learn, you should read many tutorial videos and documents. I will send you a few tutorials, I made some of them, you can browse, don't forget to practice more and if you have a problem with Lua script, open a topic in this forum and tell your question, knowledgeable people will help you and I can help. Tutorials: https://forum.multitheftauto.com/forum/123-tutorials/
  23. Take a look at the site I sent you and you can do whatever it takes. https://wiki.multitheftauto.com/wiki/Call
  24. https://nightly.multitheftauto.com/ https://forum.multitheftauto.com/topic/80449-verdanatff-problem/
×
×
  • Create New...