Jump to content

Dealman

Members
  • Posts

    1,421
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Dealman

  1. In that case store a variable outside of the for loop which increases after every index. exampleIndex = 10 for k, v in ipairs() do exampleIndex = exampleIndex+10 -- 10 -> 20 -> 30 -> 40 etc... end
  2. Get all the players using getElementsByType. Then loop through the player and get their data using getElementData. If the data is true, you can either add them to a new table - or just add it directly to the gridlist.
  3. Can't you just insert linebreaks using "Message1\nMessage2"...?
  4. DX Drawings don't return any element. You'll have to use addEventHandler and removeEventHandler or if statements to decide when to draw the window.
  5. It's rather simple, you check if the cursor's position is within the rectangle. You take the starting X position of the rectangle and add the width of the rectangle to that. Repeat the process with the starting Y position, and then add the height of the rectangle. This way, you'll check if the cursor is within the rectangle, then you can use onClientClick to detect if the left-mouse button was clicked while inside the rectangle. Or you can use a utility function such as this one; function isCursorWithin(x, y, width, height) if(not isCursorShowing()) then return false; end local sx, sy = guiGetScreenSize(); local cx, cy = getCursorPosition(); local cx, cy = (cx*sx), (cy*sy); if(cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then return true; else return false; end end
  6. Depends on what you're trying to do, and how you've currently made it. Can't really help you optimize it without knowing what it is
  7. Yeah, better to run it 30-60 times per second than once every time he tries to fire.
  8. A good addition to this tutorial would be to teach people how to manipulate strings using regular expressions. For example, this can be used to find a URL. This is very useful in case you need to download XHTML files from a website and read through it in order to find a URL. local string1 = "https://forum.multitheftauto.com/posting.php?mode=reply&f=148&t=88427" local findURL = string.match(string1, "http?://[%w-_%.%?%.%+=&]+") print(findURL) -- Prints "https://forum.multitheftauto.com/posting.php?mode=reply&f=148&t=88427"
  9. This is all very simple math. Design your interface in absolute values, and then you divide those absolute values by the resolution you designed it in, for example local screenW, screenH = guiGetScreenSize() -- Absolute - created in 1920x1080 resolution dxDrawImage(30, 247, 357, 89, "", 0, 0, 0, tocolor(255, 255, 255, 255), false) -- Same, but Relative dxDrawImage((30/1920)*screenW, (247/1080)*screenH, (357/1920)*screenW, (89/1080)*screenH, "Textures/Button1_Active.dds", 0, 0, 0, tocolor(255, 255, 255, 255), false) Of course doing it like this means it would have to do that math every frame, so you could calculate it manually and just do it like this; dxDrawImage(0.015625*screenW, 0.2287037037037037*screenH, 0.1859375*screenW, 0.0824074074074074*screenH, "Textures/Button1_Active.dds", 0, 0, 0, tocolor(255, 255, 255, 255), false) You can use repl.it to quickly test Lua scripts. And you can then use this script on that website to quickly convert it so you can just copy and paste it. local sX, sY, wX, hY = 30, 247, 357, 89; -- Paste the absolute values here local sourceWidth = 1920; -- Change those to the source values. local sourceHeight = 1080; -- Change those to the source values. local nSX, nSY, nWX, nHY = (sX/sourceWidth), (sY/sourceHeight), (wX/sourceWidth), (hY/sourceHeight); print(tostring(nSX).."*screenW, "..tostring(nSY).."*screenH, "..tostring(nWX).."*screenW, "..tostring(nHY).."*screenH");
  10. Not sure what you mean, but if you're drawing text stored in a variable, that text will be updated as soon as you change the variable itself.
  11. DX Drawings only draw for one frame. So if you try to draw it at the start of the script, or on resource start - it will only draw once and you'll barely be able to notice it. onClientRender triggers whatever function it is attached to every frame, so whatever's in that function will be run 30-60 times a second.
  12. I'm sorry but I haven't got a clue what you just asked... Are you asking if onClientRender can only trigger drawing functions, or what?
  13. You can not use server-side functions and events in a client-side script.
  14. Tables are pretty efficient, for example I made a parser which reads a file that has thousands of lines of text. I then loop through this table, splitting each individual line into different parts to make it easier to use the data and store it in a new table. All in all, the whole process takes around 6ms for over 1500 lines. That includes the entire process. Read the file -> Store each line in a table -> Loop through the table, split the strings into parts -> Store into a new table
  15. Sure, go ahead, I'd rather see it being used than not Also, I'd rather bet the physics is due to some file like the vehicle handling. And not the collision itself. Edit: In Object.dat you have a list of dynamic map objects, beachball and all the barrels are listed in this file. I am assuming that this file would need to be edited in order for you to add custom dynamic map objects. Hopefully this is something they could implement. NameMassTurnMassAirResistanceElasticityPercSubmergedUprootCDMultCDEffSpCDRCamAvExplbeachball1000.050.00.990.000150.00.02.00010
  16. I remember having a similar issue, and I used the vehicle workaround. I spawned a vehicle and attached the object to it, applied velocity and then destroyed the vehicle. This worked for the orange mine ball thing, it enabled the physics. It didn't awkwardly fly in a straight line. I'd suggest you take a look at that model, maybe you can find something of value? I would assume regular objects have some kind of model flags sort of like vehicles do...? Or maybe you can just replace that model and it'll magically work, who knows Edit: You can download my map "Waterballs" here and check it out yourself how I did it.
  17. Dealman

    Create vehicle

    Once you learn how to properly navigate the MTA Wiki, you'll be able to solve simple issues like these all by yourself. What you're looking for is to take Tomas's example and modify it so you can give yourself a weapon instead, so, you'll want to look under weapon functions, wham, there you have getWeaponIDFromName.
  18. You can not use client-side only functions in a server-side script.
  19. Dealman

    Help!

    local randomModels = { [1] = 403, [2] = 514, [3] = 515 } local randInt = math.random(1, 3) -- Generate a random integer between 1 and 3 createVehicle(randomModels[randInt], x, y, z)
  20. That just gets the camera, you'll want to use setCameraMatrix for something like that. Do note that it'll probably take quite a bit of math to get it the way you want.
  21. Great stuff! Will see if I can modify this in order to use it on 2D textures for stuff like menus and the like.
  22. Well, because that value evidently doesn't exist. Hence, it returns nil. If you'd have done it like this instead; table[1][2] Then it would return 2. table[2][1] Would return the last value, 1.
  23. Well, if it doesn't exist - it should return nil.
  24. I'm assuming you want to use this table to create teams, right? If so, you can structure it like this instead; teams = { [1] = {"Team", 0, 255, 0}, [2] = {"Team2", 255, 0, 0}, [3] = {"Team3", 0, 0, 255}, [4] = {"Team4", 0, 255, 255} } createdTeams = {} for key, value in ipairs(teams) do -- Example on how you fetch a separate value from the multi-dimensional array outputChatBox("Team Name: "..tostring(teams[key][1])) outputChatBox("Red: "..tostring(teams[key][2])) outputChatBox("Green: "..tostring(teams[key][3])) outputChatBox("Blue: "..tostring(teams[key][4])) -- Create Teams (Server-Sided) local theTeam = createTeam(tostring(teams[key][1]), tonumber(teams[key][2]), tonumber(teams[key][3]), tonumber(teams[key][4])) table.insert(createdTeams, theTeam) -- You can save the team to a table so you can easily access it later on end
  25. Funny since you gladly made NBG's script public domain, well they will remain on github & torrent. It does not matter, you can't just waltz around and assume you're free to release other people's work without their consent. Who are you to deem whether they're not used anymore or not? Even if such were the case, that doesn't automatically give you the rights to release them. The author make the rules, not you. If the author wants it to be private, then so be it. They made it - their rules. You're not doing anyone a good deed by releasing their work publicly without permission. You're just making yourself look like a disrespectful knobhead.
×
×
  • Create New...