Jump to content

IIYAMA

Moderators
  • Posts

    6,097
  • Joined

  • Last visited

  • Days Won

    218

Everything posted by IIYAMA

  1. You might be able to test that. Initial Put yourself or the vehicle you want to test in the air. Gravity to 0. Speed to 0. Start Write down the velocity for every frame. Set the default gravity and test how the speed is changing for the first few frames. Note: keep in mind that vehicles also have their own mass.
  2. Note: you can also apply the matrix of the ped to the projectile. It might not have the correct rotation in the beginning, but you can correct that. setElementMatrix
  3. Here some code snippets I ripped out of one of my scripts. The code was used to calculate the new projectile position based on frame time. This would terminate different projectile speeds based on FPS. -- add function findRotation local findRotation = function ( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end -- add function findPitch local findPitch = function (camerax,cameray,cameraz,pointx,pointy,pointz) local dX=camerax-pointx local dY=cameraz-pointz local dZ=cameray-pointy local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); return pitch end local xr, yr, zr = getElementRotation(source, "ZXY") -- source is projectile -- xr, yr, zr is saved inside of projectileData.rotation local targetX, targetY, targetZ = getElementPosition(target) -- target is projectile local rotZ = findRotation(newX, newY, targetX, targetY) + 180 local pitch = findPitch(newX, newY, newZ, targetX, targetY, targetZ) local rotX = pitch*(180/math.pi) local newRotX = projectileData.rotation.x local newRotZ = projectileData.rotation.z local rotationDistanceX = (projectileData.rotation.x - rotX + 360) % 360; if (rotationDistanceX > 180) then rotationDistanceX = 360 - rotationDistanceX newRotX = newRotX + math.min(rotationDistanceX, behaviourData.rotationSpeed * speedMultiplier) else newRotX = newRotX + -math.min(rotationDistanceX, behaviourData.rotationSpeed * speedMultiplier) end local rotationDistanceZ = (projectileData.rotation.z - rotZ + 360) % 360; if (rotationDistanceZ > 180) then rotationDistanceZ = 360 - rotationDistanceZ newRotZ = newRotZ + math.min(rotationDistanceZ, behaviourData.rotationSpeed * speedMultiplier) else newRotZ = newRotZ + -math.min(rotationDistanceZ, behaviourData.rotationSpeed * speedMultiplier) end projectileData.rotation.x = newRotX projectileData.rotation.z = newRotZ local rotationZ = -projectileData.rotation.z if creatorVehicle then -- if the projectile creator was a vehicle, then add 180 to invert the rotation. rotationZ = rotationZ + 180 end setElementRotation(element, projectileData.rotation.x, projectileData.rotation.y, rotationZ, "ZXY")
  4. A local function is just the function value saved inside of a local variable. Like this (a local available before the function is defined): local test function test () end or this (a global, as well as a local after the local keyword): function test () end local test = test or this: (a local variable, available after the function) local test = function () end or this: (a local variable, available in and after the function) local function test() end So when do you need to use it? The same way as just a regular local variable. Variables that are accessed a lot of time. (onClientRender) Variables that are only available within it's scope. Variables that are temporary required. etc.
  5. @VaporZ Stop moving, you can easily ask that question here. Now you are just pushing other people their topics down, that deserve the same attention as yours.
  6. Nope, there are other methods, like checking if rectangles are colliding. But if you use 2, it doesn't mean it is more difficult. Infact it is a lot easier to create a computed version of your grid. It tells you exactly which cells are being used and you can throw it away when you do not need it any more. An item ID, which is the one of the item you want to move. This value is an integer, the first column located in your db table.
  7. Double id's are not allowed. Your database will never generate the same ID, if the column is correct set-up. If you move the item on top of the same item, it should consider those cells as empty. isSlotFree(x, y, w, h [[, ignoreID int ]]) The checking box is the computed version of the grid, where each cell has data applied. (Unlike just the start position)
  8. I do not know the best algorithm. But what you can do for now: - First get all open spaces. - Get the size of the item you want to place. Example: 3x2 - Go through each open space - Make a checking box, starting from the left-top corner. Left-top corner: XOOOOOO OOOOOOO OOOOOOO Checking box: XXXOOOO XXXOOOO OOOOOOO Next item: 3x3 XXXXOOO XXXOOOO OOOOOOO --- XXXXXXO XXXXXXO OOOXXXO This is just a way. I am sure you can optimise it in a way. For example items that start at a position that is going to be out of the box because of the width and height. 3X3 Is never going to fit here: (start point) OOOOOOO OOOOOOO OOOOOOO
  9. I have done this before, but think I would go for 2 grids. Every item has a startX, startY, width and height. Grid 1: contains only the start position of the added items. (Which is saved) Grid 2: A computed version of grid 1, where it is for each cell know which item is placed on it. This makes it easier to see if there is space. (unsaved) local grid1 = { { -- column / X1 { -- cell / Y1 width = 2, height = 3, type = "drink", name = "bottle", id = 1 }, nil, -- cell / Y2 nil, -- cell / Y3 nil, -- cell / Y4 { -- cell / Y5 width = 4, height = 3, type = "ammo", name = "bullets ...", id = 2 } }, nil, -- column / X2 { -- column / X3 { -- cell / Y1 width = 1, height = 1, type = "matches", name = "matches", id = 3 } } } Don't program it like this, this is how the computed version would looks like. (With only the bottle) local grid2 = { { -- column grid1[1][1], grid1[1][1], grid1[1][1] }, { -- column grid1[1][1], grid1[1][1], grid1[1][1] } } So if you want to place an item at: X2, Y3 print(grid2[2][3]) You would find the the bottle table. Therefore there is no space. Demo: https://www.Lua.org/cgi-bin/demo
  10. Moved
  11. You are now loading the fish script 2x. 1 version serverside and 1 version clientside. That is not going to work. You need to separate those sides. So: 1 script/file serverside, with serverside code. (Running in the server application) 1 script/file clientside, with clientside code. (Running on each player his computer in the MTA game itself)
  12. Show me your meta.xml
  13. Yes, your script is passing over arguments that are used within the rgbOpenPicker as parameters. In: rgbOpenPicker("left", "up") Out: function rgbClosePicker(button, state) --[[ ... ]] iprint(button) -- outputs "left" iprint(state) -- outputs "up" --[[ ... ]] For you the definition of an effect is apparently: Everything works fine! Which is for me not really useful, if it is positive, it only means that I do not have to help you any more. The effects that are relevant for me are: Are there errors/warnings from this script? Is this, this, this and this code executed? Are the values of a variable correct? And how would I get that relevant information? That is where you come in! So please help me too. Debug the code for me!
  14. A lot of clean up has to be done. Oke the first thing I want to mention is this: <script src="testy-c.Lua" type="client"/> <script src="rgbpicker/gui.Lua" type="client"/> The test script is loaded first, therefore it is executed first. Which means that you are calling the function rgbOpenPicker, which has not been created yet. So you might want to switch that order or add the onClientResourceStart event, which will wait until all scripts have been loaded. Next: exports[getResourceName(getThisResource())]:rgbOpenPicker(true) or rgbOpenPicker() Please follow my instructions. This experiment was not included, please do reset that back before continuing and iterating. Next: rgbOpenPicker("left", "up") If you are using arguments, then make sure to fill them in. Last thing, add debug lines, just for me please?
  15. Show me your meta.xml (+ let me know which file contains which code)
  16. Export is used only when you have 2 (or more) separated resources. So for example: - admin (resource 1) - editor (resource 2) - freeroam (resource 3) If you have only 2 files within 1 resource, then yes that is the way to go from my previous post
  17. Just 2 files If it is 1 or 2 doesn't really matter when using the event onClientResourceStart.
  18. @VaporZ function rgbOpenPicker() --Do some GUI stuff end addEventHandler("onClientResourceStart", resourceRoot, function() -- We are loaded and now we open the color picker rgbOpenPicker() end)
  19. No, you are calling the function before it is created. Move the event stuff to clientside 2, so that you can delay the call and not the creation time.
  20. Just call it, you defined the variable/function as a global, therefore it is not bound to the file scope. rgbOpenPicker() After the onClientResource event has been triggered, you know for sure that all global variables are available everywhere. (All files have been loaded)
  21. You are exporting within the same resource. The resourceName has to be the name of the resource with the export function.
  22. 2 scripts, within the same resource You can either use globals: some_button_data = 5 addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() iprint(some_button_data) end) Or return values: local some_button_data = 5 function getData () return some_button_data end addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() local some_button_data = getData() end) And if you are dealing with multiple resources, you can use exports: Resource 1 <!-- meta.xml --> <export function="getData" type="client"/> local some_button_data = 5 function getData () return some_button_data end Resource 2 addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() local some_button_data = exports["resourceName"]:getData () end)
  23. From where are you returning that data?
  24. The problem has nothing to do with CSS, but with the configuration of the browser. See the 6e argument 'isTransparent', of the guiCreateBrowser function: https://wiki.multitheftauto.com/wiki/GuiCreateBrowser
×
×
  • Create New...