Jump to content

IIYAMA

Moderators
  • Posts

    6,097
  • Joined

  • Last visited

  • Days Won

    218

Everything posted by IIYAMA

  1. IIYAMA

    Performance

    @mehmet tickCount shows execution timing. local timeNow = getTickCount() for i=1, 1000 do local newFunction = function () end end outputChatBox("It took: " .. (getTickCount() - timeNow) .. " ms, to execute this code.") 2.5% CPU is high, but not critical. You should be more worried about resources that show ~10%+. The gamemode `tactics` is a bad example of that.
  2. function openGUI ( player ) local updates = getUpdates ( ) triggerClientEvent ( player, 'Updates:onPanelChangeState', player, 'main', updates ) end addCommandHandler ( "news", function (player) openGUI(player) end) addEventHandler("onPlayerLogin", root, function () openGUI(source) end) Read the docs: https://wiki.multitheftauto.com/wiki/AddCommandHandler https://wiki.multitheftauto.com/wiki/OnPlayerLogin Keep in mind that players can login before they have loaded their scripts, unless the login command is blocked. (the panel will not open in that case)
  3. If you do that every 5 seconds forever, then ask the question: "is your network activity not in progress forever?" Make sure to check that! /shownetstat
  4. Hmmmm ? Why not? The circle is perfect rounded. While making my svg version a while ago, I checked that fact.
  5. arg1, arg2, ...: Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain nil. You can deal with a variable number of arguments using the vararg expression, as shown in Server Example 2 below. https://wiki.multitheftauto.com/wiki/AddCommandHandler if argument then -- check end @Hugo_Almeidowski
  6. There are already 4 ways to do this, is that not enough? ? A 5e way. Calculate the distance from the center of the image. A 6e way. Compromise, use a different design that is easier to calculate the button detection.
  7. IIYAMA

    All about peds

    @Peti 1. + 3. To answer this, you need to understand the difference between client and serverside: The server is a computer. Which RUNS serverside. The Clients are multiple computer connected to the server. Which RUNS clientside. The internet and the network is in between. (ping is the delay which separates those two types of computers) In case of a local-server the ping 0, but both sides are still separated. And that will give the result as @Patrick2562 said. 2. You make peds created by clientside/serverside shoot at clientside. The reason why it can't be done serverside is because MTA doesn't support it yet.
  8. IIYAMA

    Why?

    See also this tutorial, it explains how the addEventHandler works in your code. ??
  9. IIYAMA

    Why?

    It means that the sound has been created successfully. (Are you sure that you are in the same dimension as the ped?)
  10. IIYAMA

    Why?

    @Hugo_Almeidowski hmm, just to be sure debug the sound element. local soundREEE = playSound3D("reeet.mp3", pX, pY, pZ, true) outputChatBox(inspect(soundREEE))
  11. IIYAMA

    Why?

    @Hugo_Almeidowski Did you check the debug console? I didn't change anything before the audio started to play, so either it was already broken or there is an error/warning.
  12. yea that can work. I recommend to open the design in Photoshop/something-similar and get all the positions from there. (you might need to do a little bit of maths afterwards to adjust it to the (possible) responsive layout in game)
  13. It doesn't tell you which field you selected. dxGetTexturePixels is a very slow process.(unless it is only done once at the start) But feel free to try it your way. I am interested in what you discover on the way.
  14. IIYAMA

    Why?

    ID elements have to be unique. There shouldn't be two elements with the same ID. local pedContainer = createElement("pedContainer") function TocarSomPed(ped) local pX, pY, pZ = getElementPosition(ped) local dimensaoP = getElementDimension(ped) local IDPed = getElementID(ped) outputChatBox("O nome deste ped é " ..IDPed) local soundREEE = playSound3D("reeet.mp3", pX, pY, pZ, true) setElementDimension(soundREEE, dimensaoP) attachElements(soundREEE, ped) setElementParent(soundREEE, ped) -- the SOUND is now a child of the PED. setElementParent(ped, pedContainer) -- PED is now a child of pedContainer, which has an addEventHandler attached to it. See line 1 and line 31. end addEvent("onPedCriado", true) addEventHandler("onPedCriado", root, TocarSomPed) -- function pedMorreuClient() local setarIDSom = source -- source is the ped. See page: https://wiki.multitheftauto.com/wiki/OnClientPedWasted local soundREEE = getElementChild ( setarIDSom, 0 ) -- get the first child of this PED, which is the SOUND. See line 12. if soundREEE then destroyElement(soundREEE) end end addEventHandler("onClientPedWasted", pedContainer, pedMorreuClient) https://wiki.multitheftauto.com/wiki/GetElementChild https://wiki.multitheftauto.com/wiki/SetElementParent This is information about how children and parents work in MTA: https://wiki.multitheftauto.com/wiki/Element_tree#Example
  15. @mehmet You can use something like this: https://wiki.multitheftauto.com/wiki/Math.isPointInPolygon Or calculate the angle + distance from the centre. (this one will give the best result without relying on the browser) https://wiki.multitheftauto.com/wiki/FindRotation https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints2D Or use the browser + svg.(HTML + SVG knowledge required) <svg id="Laag_1" data-name="Laag 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"><defs><style>.cls-1{opacity:0.53;}</style></defs><title>Tekengebied 2</title><path class="cls-1" d="M104.52,305.93a155.81,155.81,0,0,1,.31-114.35L18.44,155.8A249.16,249.16,0,0,0,17.55,342Z"/><path class="cls-1" d="M187.74,392.47a155.86,155.86,0,0,1-80.93-81l-87,36A249.16,249.16,0,0,0,151.57,479.79Z"/><path class="cls-1" d="M107.13,186.05a155.82,155.82,0,0,1,80.92-80.38L152.49,19.82A249.13,249.13,0,0,0,20.77,150.27Z"/><path class="cls-1" d="M158,17.55l35.56,85.84a155.77,155.77,0,0,1,113.78.24l35.51-85.71A249.12,249.12,0,0,0,158,17.55Z"/><path class="cls-1" d="M312.92,105.93a155.78,155.78,0,0,1,80.43,80.36l86-35.64a249.15,249.15,0,0,0-131-130.44Z"/><path class="cls-1" d="M395.65,191.83A155.82,155.82,0,0,1,396,305.68l86.65,35.89a249.08,249.08,0,0,0-.9-185.38Z"/><path class="cls-1" d="M307.69,394.51a155.75,155.75,0,0,1-114.4.25l-36.18,87.32a249.11,249.11,0,0,0,186.7-.37Z"/><path class="cls-1" d="M393.67,311.23a155.82,155.82,0,0,1-80.44,81l36.12,87.18a249.18,249.18,0,0,0,131-132.26Z"/><path d="M28.16,153.33A240.89,240.89,0,0,1,155.55,27.21l-3.06-7.39A249.13,249.13,0,0,0,20.77,150.27Z"/><path d="M158,17.55l3.06,7.39a240.85,240.85,0,0,1,178.72.37l3.07-7.39A249.12,249.12,0,0,0,158,17.55Z"/><path d="M154.63,472.4A240.9,240.9,0,0,1,27.21,344.45l-7.39,3.06A249.16,249.16,0,0,0,151.57,479.79Z"/><path d="M24.94,338.9a240.95,240.95,0,0,1,.89-180l-7.39-3.06A249.16,249.16,0,0,0,17.55,342Z"/><path d="M474.32,159.25a240.93,240.93,0,0,1,.9,179.26l7.39,3.06a249.08,249.08,0,0,0-.9-185.38Z"/><path d="M345.37,27.6A240.87,240.87,0,0,1,472,153.71l7.39-3.06a249.15,249.15,0,0,0-131-130.44Z"/><path d="M340.75,474.32a240.88,240.88,0,0,1-180.57.37l-3.07,7.39a249.11,249.11,0,0,0,186.7-.37Z"/><path d="M473,344.07A240.87,240.87,0,0,1,346.29,472l3.06,7.39a249.18,249.18,0,0,0,131-132.26Z"/></svg>
  16. Notes: The car explosion might not look the same, even though it is the same type. (to be honest it looks nicer) You might want to only apply it to the types you want to replace. Damage is disabled for all elements, which includes peds, objects and vehicles. You might need to write the same damage method for those.
  17. explosions can't be detected with onClientPlayerWeaponFire My first first step gives you everything you need know for the second step. addEventHandler("onClientExplosion", root, function (x,y,z,theType) createExplosion (x, y, z, theType, true, -1.0, false ) local creator = source -- the one that created the explosion, this doesn't have to be a player. local playerX, playerY, playerZ = getElementPosition(localPlayer) local distance = getDistanceBetweenPoints3D(x, y, z, playerX, playerY, playerZ) end)
  18. @majqq The first step would be cancelling this event: https://wiki.multitheftauto.com/wiki/OnClientExplosion x: the X Coordinate of where the explosion was created y: the Y Coordinate of where the explosion was created z: the z Coordinate of where the explosion was created theType: the type of explosion created, Values are: 0: Grenade 1: Molotov 2: Rocket 3: Rocket Weak 4: Car 5: Car Quick 6: Boat 7: Heli 8: Mine 9: Object 10: Tank Grenade 11: Small 12: Tiny The second step, recreating the explosion and disable the damage: https://wiki.multitheftauto.com/wiki/CreateExplosion Optional Arguments makeSound: a boolean specifying whether the explosion should be heard or not. camShake: a float specifying the camera shake's intensity. damaging: a boolean specifying whether the explosion should cause damage or not. And the last step is indeed:https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D For your first iteration you can work with rings. So if distance is closer than: damage = 0 if distance is closer than 30 units damage = damage + 10 if distance is closer than 15 units damage = damage + 30 if distance is closer than 5 units damage = damage + 50 iprint(damage) Later you can do some more advanced math stuff which gives you something similar to GTA.
  19. triggerClientEvent ("onPedCriado", thePlayer, ped) function TocarSomPed (ped) Serverside elements are available on clientside. But clientside created elements are not available serverside.
  20. You can use a GUI element: https://wiki.multitheftauto.com/wiki/Client_Scripting_Functions#Static_Images But the quality will not be the same. Check also rendering with textures, you can boost the performance considerably: https://wiki.multitheftauto.com/wiki/DxCreateTexture
  21. First make it, then optimise it. ipairs, pairs (and next) loops are function based loops. They process tables with their own rules. ipairs loops through numbers starting from 1. It will stop looping when there is no value at the next index. {1, 2, nil, 4} With this table it will loop only 2 items. It has as benefit to loop through error sensitive tables, which can skip the damaged data. (Not that I ever had to deal with a damaged table in my life...) pairs loops through all indexes. It doesn't matter if it is a number, string, userdata, table or even a function. The only thing it can't do is looping it in order. But do you really think that there are no other, not function based loops? Here is a list of loops that do not make use of lua functions: https://www.tutorialspoint.com/lua/lua_loops.htm
  22. Functions are slower. But you are at a point where you shouldn't worrying about optimizing to the bone. But if you really want to know about speed: Functions are one of the slowest type of operations in Lua. A loop can be faster than an if statement. But not with the ipairs loop. ipairs() = function Why use these `slow` functions? Your brain is also a kind of computer and it's performance can also be decreased. This happens very quickly when you do not use enough functions. Functions are used to name/identify the operations in your code.
  23. Sometimes by just adding a random debug line in your code, it can reveal not updated code.
  24. iprint(source) Did you debug it?
  25. As it is now, the code triggers immediately while loading the resource and source is not defined.
×
×
  • Create New...