• Content Count

  • Joined

  • Last visited

  • Days Won


The_GTA last won the day on February 24

The_GTA had the most liked content!

Community Reputation

22 Decent


About The_GTA

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. The_GTA


    Line 10: * replace playerID with targetPlayer * replace PlayerSource with playerSource
  2. Dear Moony, here is a script that fixes both overlaid sounds and the volume of distant sounds: function Sound3D(shooterPed, sound3d) local wX, wY, wZ = getPedWeaponMuzzlePosition ( shooterPed ) local sound = playSound3D (sound3d,wX, wY, wZ, false ) attachElements (sound ,shooterPed , 0, 0, 2 ) setSoundMaxDistance(sound, 50) setElementDimension(sound,getElementDimension ( shooterPed )) setElementInterior(sound,getElementInterior( shooterPed )) return sound end local weapons = { [22] = "sounds/Colt45.wav", --[id] = "sound name", } local pedSounds = {}; setWorldSoundEnabled(5,false) function onClientPlayerWeaponFire ( weapon ) if weapons[weapon] then if isElement(pedSounds[source] ) then destroyElement(pedSounds[source] ) end pedSounds[source] = Sound3D(source, weapons[weapon] ) end end addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFire ) Sounds are not deleted if players leave the server. Implementing this is an exercise left for OP. P.S. Please understand that scripting is an effort that you can train. If you are having trouble with parameters like "source" or don't know about the function calls, it can be a good idea to script some random resources (exploding bottle attachment to players, weapon attachment to vehicles, etc).
  3. You are creating all sounds from the gun muzzle position of the localPlayer. No wonder you hear all weapons equally as loud. I recommend you to use the source element in the onClientPlayerWeaponFire event to create the sound at. Also make sure to properly destroyElement sounds (not sure if required but just to be sure?).
  4. You have misspelled detachElements, you typed detachElement without s. Does this solve your problem?
  5. The_GTA


    Dear murilo2929, 1) either "fix" the code by using the following function: function formatNumber(amount, spacer) if not spacer then spacer = "," end if not amount then amount = 0 end amount = math.floor(amount) local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$") return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right end 2) or post your entire code as attachment so we can search for the formatNumber error. - Martin
  6. Dear Hazardinho, please read the top Notes of this MTA wiki article: So there are some limitations on implementing your own chat window. But I hope that provided with MTA's function set you will be able to achieve your dream project!
  7. Dear xMoDy, do you know what the scripting language called "Lua" is? We use it in MTA to create server mods. You don't seem to have posted any scripting progress so I am curious. We could help you get started with Lua! Yours, - Martin
  8. The_GTA


    I don't want to be the guy to spot the obvious, but: in Lua, loopTable is a different variable than looptable because variable names are case-sensitive. Could you make sure you spelled "looptable" correctly in your code? --- About the second error, I cannot decipher the cause because you are not showing the code that called the function "formatNumber".
  9. Let me throw in an idea. To avoid any kind of flickering (rapid presses of the fire button, players shooting single shots, etc) you should implement a "heated area" timer. If there was shooting at for example Groove street, then your script should remember that for 5 seconds and update the timer when new shooting happens. This way your alert GUI will stay visible. Good luck with your idea!
  10. How about looking into the game's info.zon file? You find the entries... zone (...) BONE, 0, -480.539, 596.349, -242.99, 869.461, 2993.87, 900.0, 1, BONE ROBAD, 0, -2997.47, 1659.68, -242.99, -480.539, 2993.87, 900.0, 1, ROBAD (...) end zonename, interior, start_x, start_y, start_z, end_x, end_y, end_z, levelNumber, gxtName You can use colshape createColRectangle ( float fX, float fY, float fWidth, float fHeight ) and then use addEventHandler with "onClientElementColShapeHit" and "onClientElementColShapeLeave" to detect player position, playSound if inside colshape, then stopSound if leaving colshape. Hopefully this helps!
  11. Hello gubi, I have tried your resource, but it always complains that it has no access to "fetchRemote". Changing line 32 to if not hasObjectPermissionTo(getThisResource(), "fetchRemote", true) then has fixed the issue. Now I see naughty work of art on Grove Street I think this is a good use of the new xmlLoadString function call. But you could still add more features to this script, to make it better.
  12. Hello Haxardous! Thank you for complimenting me. I spent a lot of work into it and just want people to have a good starting foundation. Later the performance of the implementation will be improved by choosing better data structures as well as faster algorithms (already have plans). As a side note, I was heavily inspired by Direct3D 9's frustum definition when setting out my math formulas. So if you read their documentation you will find many parallels. Pretty sure this definition is industry standard.
  13. Thanks! <3 I like hearing about your appreciation. About the possibility of a Doom port, this could take a lot of work ;) But not impossible because Doom is a retro game.
  14. Dear MTA community, I have been spending my last 8 weeks on mathematical problems. One of them is the 3D Frustum-Plane intersection that is used by GPUs to draw triangles onto your screen. If you want to learn more about this please consider reading this thread. Promotional Video: Prerequisites This tutorial is aimed at people who are capable of scientific thinking and are willing to playfully learn with Lua code. To execute steps in this tutorial minimal knowledge of Linear Algebra and Lua is required. Required MTA Resource: Description of the math Imagine that we have got a frustum and a plane in a 3D room described by coordinates plus their boundaries. By intersecting both you obtain all coordinates on a screen along with their depth values. Now think about how your vision works. You see distant objects smaller than closer ones. You rotate your eyes to angles of vision. If we were to put this concept into terms of math we could say: the plane of vision is bigger in the distance than in close proximity. The frustum is a seamless row of vision planes starting from the pyramid tip to the bottom. How to use the MTA Resource Just download the GitHub repository into a folder of your MTA Resources, name it "math_3d_nonlin" and start it. You can execute the following commands for quick testing: send_bbuf: draws a simple depth test draw_model: draws the DFF file "gfriend.dff" Now we have got the basics out of the way. Time to start coding. Please create a new "_math_test.Lua" script file in the resource and include it server-side at the bottom of meta.xml. Tutorial: software rendering a plane on screen Open your _math_test.Lua and include the following code: local viewFrustum = createViewFrustum( createVector(0, 0, 0), -- position createVector(10, 0, 0), -- right createVector(0, 0, 10), -- up createVector(0, 20, 0) -- front ); local plane = createPlane( createVector(-3, 10, -3), createVector(6, 0, 0), createVector(0, 0, 6) ); local function task_draw_scene(thread) local bbuf = create_backbuffer(640, 480, 255, 255, 0, 50); local dbuf = createDepthBuffer(640, 480, 1); local time_start = getTickCount(); do local gotToDraw, numDrawn, numSkipped = draw_plane_on_bbuf(viewFrustum, bbuf, dbuf, plane, true); if ( gotToDraw ) then outputDebugString( "drawn " .. numDrawn .. " pixels (skipped " .. numSkipped .. ")" ); end end local time_end = getTickCount(); local ms_diff = ( time_end - time_start ); outputDebugString( "render time: " .. ms_diff .. "ms" ); taskUpdate( 1, "creating backbuffer color composition string" ); local bbuf_width_ushort = num_to_ushort_bytes( bbuf.width ); local bbuf_height_ushort = num_to_ushort_bytes( bbuf.height ); local pixels_str = table.concat(bbuf.items); local bbuf_string = pixels_str .. ( bbuf_width_ushort .. bbuf_height_ushort ); taskUpdate( false, "sending backbuffer to clients (render time: " .. ms_diff .. "ms)" ); local players = getElementsByType("player"); for m,n in ipairs(players) do triggerClientEvent(n, "onServerTransmitImage", root, bbuf_string); end outputDebugString("sent backbuffer to clients"); end addCommandHandler( "testdraw", function(player) spawnTask(task_draw_scene); end ); Result: Try executing the "testdraw" command. At the top of file you see the definition of our frustum cone as well as a plane. By calling the function "draw_plane_on_bbuf" we put color information into bbuf for exactly the pixels that make up the rectangle. If you change the plane definition to... local plane = createPlane( createVector(-2, 10, -4), createVector(6, 0, 3), createVector(-2, 0, 6) ); you instead get this image: Try changing around the coordinates of frustum and plane to obtain different pictures! Tutorial: software rendering a triangle on screen Take the same code as in the tutorial above but change line 19 to: local gotToDraw, numDrawn, numSkipped = draw_plane_on_bbuf(viewFrustum, bbuf, dbuf, plane, true, "tri"); This way we have changed the primitive type to triangle (rectangle is the default). Try executing the "testdraw" command again to inspect the new result! Tutorial: drawing a DFF file onto screen Instead of writing triangle definitions by hand we can take them from a DFF file instead. DFF files are storage of triangle and vertex information along with 3D rotation and translation information. By extacting the triangles from the DFF file we can put them into our algorithm to software-render them! Here is a related excerpt from math_server.Lua: local modelToDraw = false; do local modelFile = fileOpen("gfriend.dff"); if (modelFile) then modelToDraw = rwReadClump(modelFile); fileClose(modelFile); end end local function task_draw_model(thread) local bbuf = create_backbuffer(640, 480, 255, 255, 0, 50); local dbuf = createDepthBuffer(640, 480, 1); local time_start = getTickCount(); local num_triangles_drawn = 0; if (modelToDraw) then -- Setup the camera. local geom = modelToDraw.geomlist[1]; local mt = geom.morphTargets[1]; local centerSphere = mt.sphere; local camPos = viewFrustum.getPos(); camPos.setX(centerSphere.x); camPos.setY(centerSphere.y - 3.8); camPos.setZ(centerSphere.z); local camFront = viewFrustum.getFront(); camFront.setX(0); camFront.setY(5 + centerSphere.r * 2); camFront.setZ(0); local camRight = viewFrustum.getRight(); camRight.setX(centerSphere.r * 2); camRight.setY(0); camRight.getZ(0); local camUp = viewFrustum.getUp(); camUp.setX(0); camUp.setY(0); camUp.setZ(centerSphere.r * 2); local triPlane = createPlane( createVector(0, 0, 0), createVector(0, 0, 0), createVector(0, 0, 0) ); local vertices = modelToDraw.geomlist[1].morphTargets[1].vertices; local triangles = modelToDraw.geomlist[1].triangles; local tpos = triPlane.getPos(); local tu = triPlane.getU(); local tv = triPlane.getV(); for m,n in ipairs(triangles) do taskUpdate( m / #triangles, "drawing triangle #" .. m ); local vert1 = vertices[n.vertex1 + 1]; local vert2 = vertices[n.vertex2 + 1]; local vert3 = vertices[n.vertex3 + 1]; tpos.setX(vert1.x); tpos.setY(vert1.y); tpos.setZ(vert1.z); tu.setX(vert2.x - vert1.x); tu.setY(vert2.y - vert1.y); tu.setZ(vert2.z - vert1.z); tv.setX(vert3.x - vert1.x); tv.setY(vert3.y - vert1.y); tv.setZ(vert3.z - vert1.z); local gotToDraw, numDrawn, numSkipped = draw_plane_on_bbuf(viewFrustum, bbuf, dbuf, triPlane, false, "tri"); if (gotToDraw) and (numDrawn >= 1) then num_triangles_drawn = num_triangles_drawn + 1; end end end local time_end = getTickCount(); local ms_diff = ( time_end - time_start ); (...) end The code first loads a DFF file called "gfriend.dff" and stores it inside the "modelToDraw" variable. Once you execute the "draw_model" command the code looks up the first geometry in the DFF file and fetches all triangles associated with it. The rendering camera is set up to point at the middle of the model. Then all triangles are drawn one-by-one. Try swapping the DFF file for another one, like biker.dff, and examine the results! Maybe extract a different DFF file from GTA:SA and replace gfriend.dff with that one. External references: math calculation on paper example: German thread on Do you have any questions related to the math or the implementation? Do not shy away from asking! I want to provide you with as much insight as I can.
  15. Linux support! Recent changes to Scene2Res and dependencies have added Linux compilation support. Thus I want to share it with you guys. Linux only download: Windows only download: Some people have noticed me that they could not download from, thus here is a mirror: How to compile on Linux First execute the following commands in your terminal: sudo apt-get install g++-7 sudo apt-get install codeblocks sudo apt-get install subversion cd ~ subversion checkout scene2res Then go here to setup your Code::Blocks for compilation. Now continue with the commands... codeblocks --build --target=Release build/scene2res.workspace mv obin/linux/Release/scene2res bin/scene2res cd bin Now you should have a terminal with Scene2Res set-up in the common run location (contents of a downloaded zip archive). Have fun! You can execute scene2res using... ./scene2res Of course, you can simply use the Code::Blocks GUI interface to build Scene2Res. But that ain't the fun, rite? What is new? Nothing really noteworthy. The whole implementation of my modules has received a huge facelift over time. Yours, - Martin