Jump to content

botder

MTA Team
  • Posts

    524
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by botder

  1. Do you want to add a column to your first table or SELECT information from 2 tables in one query?
  2. botder

    HUD 3D

    You have to draw the HUD into a render target, pass that render target through a shader, transform that shader and finally draw it. DxSetShaderTransform
  3. Didn't see something through. Try that: function getAspectRatio(width, height) return (width / height) end function getHeightAfterResize(new_width, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_width, new_width / ratio end -- Size of the image display local displayWidth, displayHeight = 0, 0 function click() if source == grid then local imagepath = guiGridListGetItemText(grid,guiGridListGetSelectedItem(grid),1) if imagedisplay then guiStaticImageLoadImage(imagedisplay, "images/".. imagepath) else imagedisplay = guiCreateStaticImage(0.36, 0.12, 0.47, 0.86, "images/".. imagepath, true, window) displayWidth, displayHeight = guiGetSize(imagedisplay, false) end -- Get the size of the new image local width, height = guiStaticImageGetNativeSize(imagedisplay) --[ Equal lengths ] if (width == height) then -- In this case we can directly scale the size width = displayWidth height = displayHeight --[ Resize ] else height = getHeightAfterResize(displayWidth, width, height) width = displayWidth end guiSetSize(imagedisplay, width, height, false) end end addEventHandler("onClientGUIClick", grid, click, false)
  4. Do you mean something like toJSON?
  5. Ok, try that this one: function getAspectRatio(width, height) return (width / height) end function getHeightAfterResize(new_width, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_width, new_width / ratio end function click() if source == grid then local imagepath = guiGridListGetItemText(grid,guiGridListGetSelectedItem(grid),1) if imagedisplay then guiStaticImageLoadImage(imagedisplay, "images/".. imagepath) else imagedisplay = guiCreateStaticImage(0.36, 0.12, 0.47, 0.86, "images/".. imagepath, true, window) end -- Size of the image display local displayWidth, displayHeight = guiGetSize(imagedisplay, false) -- Get the size of the new image local width, height = guiStaticImageGetNativeSize(imagedisplay) --[ Equal lengths ] if (width == height) then -- In this case we can directly scale the size width = displayWidth height = displayHeight --[ Resize ] else height = getHeightAfterResize(displayWidth, width, height) width = displayWidth end guiSetSize(imagedisplay, width, height, false) end end addEventHandler("onClientGUIClick", grid, click, false) @Saml1er: Might work for positioning, but not in scaling of images.
  6. Your window is 300 long and 445 tall? Edit, try this one (untested): function getAspectRatio(width, height) return (width / height) end function getHeightAfterResize(new_width, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_width, new_width / ratio end function getWidthAfterResize(new_height, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_height * ratio, new_width end function click() if source == grid then local imagepath = guiGridListGetItemText(grid,guiGridListGetSelectedItem(grid),1) if imagedisplay then guiStaticImageLoadImage(imagedisplay, "images/".. imagepath) else imagedisplay = guiCreateStaticImage(0.36, 0.12, 0.47, 0.86, "images/".. imagepath, true, window) end -- Size of the image display local maxWidth, maxHeight = 300, 445 -- Get the size of the new image local width, height = guiStaticImageGetNativeSize(imagedisplay) --[ Equal lengths ] if (width == height) then -- In this case we can directly scale the size width = maxWidth height = maxHeight --[ Width is bigger ] elseif (width > height) then height = getHeightAfterResize(maxWidth, width, height) width = maxWidth --[ Height is bigger ] else width = getWidthAfterResize(maxWidth, width, height) height = maxWidth end guiSetSize(imagedisplay, width, height, false) end end addEventHandler("onClientGUIClick", grid, click, false)
  7. Explanation 0.36, 0.12, 0.47, 0.86 Those are relative sizes (x position, y position, width, height) of the image field. How to use them function getAspectRatio(width, height) return (width / height) end function getHeightAfterResize(new_width, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_width, new_width / ratio end function getWidthAfterResize(new_height, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_height * ratio, new_width end -- Convert relative values to absolute values local screenWidth, screenHeight = guiGetScreenSize() local absoluteWidth, absoluteHeight = screenWidth * 0.47, screenHeight * 0.86 -- Get the size of the new image local width, height = guiStaticImageGetNativeSize(imagedisplay) -- Problem: Check if we have to scale the width or height (which one is bigger) --[ Equal lengths ] if (width == height) then -- In this case we can directly scale the size width = absoluteWidth height = absoluteHeight --[ Width is bigger ] elseif (width > height) then height = getHeightAfterResize(absoluteWidth, width, height) width = absoluteWidth --[ Height is bigger ] else width = getWidthAfterResize(absoluteWidth, width, height) height = absoluteWidth end guiSetSize(imagedisplay, width, height, false)
  8. Do you mean something like this? function getAspectRatio(width, height) return (width / height) end function getHeightAfterResize(new_width, original_width, original_height) local ratio = getAspectRatio(original_width, original_height) return new_width, new_width / ratio end P.S. Greet Grace from me
  9. Use the event onClientVehicleDamage and the function setVehicleWheelStates
  10. Do you mean a tab with every message? Use /debugscript 3.
  11. botder

    Line chart

    Well, I already made a chart script in the past and I still could recall how to calculate the values + how to script in MTA. Back then I thought how to calculate the height and other values (that's really basic percentage maths).
  12. botder

    Line chart

    I took the time and made a small script with render targets. Preview: (http://i.imgur.com/XYxLk4g.png) Code: Pastebin: Link -- Warning, render targets require you to write into the meta.xml a min. version -- or -- Get the screen size local screenWidth, screenHeight = guiGetScreenSize() -- Resolution independet solution for width & height of the chart box local box_width = (screenWidth * 0.75) local box_height = (screenHeight * 0.50) -- Number of rows local chart_rows = 10 -- Colors in the chart local colors = { background = tocolor(255, 255, 255, 255), coordline = tocolor(0, 0, 0, 255), titlecolor = tocolor(0, 0, 0, 255), gridline = tocolor(0, 0, 0, 5), valueline = tocolor(255, 0, 0, 255), rowvalue = tocolor(0, 0, 0, 255), } -- Cache variables local lowest_value = false local highest_value = false local chart_title = false local chart_columns = false local chart_data = false local title_height = false local rendertarget = false -- Cache a table with raw number values function cacheChartData(title, data) -- Reset cache lowest_value = false highest_value = false -- Find highest and lowest values for i = 1, #data do if (not lowest_value or data[i] < lowest_value) then lowest_value = data[i] end if (not highest_value or data[i] > highest_value) then highest_value = data[i] end end -- Apply the data chart_data = data -- Calculate the number of columns chart_columns = #data - 1 -- Apply the chart title chart_title = title -- Calculate the chart title height title_height = dxGetFontHeight(3, "default-bold") -- Draw the chart into a rendertarget cacheChartDrawing() end -- Render the chart into a render target function cacheChartDrawing(cleared) -- Event call detection if (type(cleared) == "boolean") then -- Do nothing if the render target is still intact if (not cleared) then return end -- Change the value so we know we don't have to re-create the r. t. cleared = true end -- Destroy the old version (if neccessary) if (not cleared) then if (isElement(rendertarget)) then destroyElement(rendertarget) end -- Create a new rendertarget rendertarget = dxCreateRenderTarget(box_width, box_height, true) end -- Abort if the render target is invalid if (not rendertarget) then return -- Else switch to the render target else dxSetRenderTarget(rendertarget) end -- Draw the background dxDrawRectangle(0, 0, box_width, box_height, colors.background) -- Define a general padding to the content local padding = 0.10 * box_height -- Calculate the width of the highest number local left_width = dxGetTextWidth(tostring(highest_value), 1, "default") -- Calculate the height of the chart and the 0 coordinate position local chart_height = (box_height - (padding * 2) - title_height) local chart_y = (box_height - padding) -- Calculate the width of the chart and the 0 coordinate position local chart_width = (box_width - (padding * 2) - left_width) local chart_x = (padding + left_width) -- Draw the chart title dxDrawText(chart_title, 0, (padding / 2), box_width, (padding / 2) + title_height, colors.titlecolor, 3, "default-bold", "center", "center", false, false, false, true) -- Draw the x and y lines dxDrawLine(chart_x, chart_y, chart_x + chart_width, chart_y, colors.coordline, 2) dxDrawLine(chart_x, chart_y - chart_height, chart_x, chart_y, colors.coordline, 2) -- Calculate the width and height for each cell local column_width = (chart_width / chart_columns) local column_height = (chart_height / chart_rows) -- Draw the grid for i = 0, chart_columns do for j = 0, chart_rows do -- Draw the column line dxDrawLine(chart_x + (i * column_width), chart_y - chart_height, chart_x + (i * column_width), chart_y, colors.gridline) -- Draw the row line dxDrawLine(chart_x, chart_y - (j * column_height), chart_x + chart_width, chart_y - (j * column_height), colors.gridline) end end -- Draw the highest value dxDrawText(tostring(highest_value), padding, chart_y - chart_height, padding / 2 + left_width, chart_y - chart_height, colors.rowvalue, 1, "default", "center", "center", false, false, false, true) -- Draw the values for the other rows for i = 0, (chart_rows - 1) do dxDrawText(("%.2f"):format((i / chart_rows) * highest_value), padding, chart_y - (column_height * i), padding / 2 + left_width, chart_y - (column_height * i), colors.rowvalue, 1, "default", "center", "center", false, false, false, true) end -- Cache for the last height local last_height = false -- Draw the value line for i = 0, chart_columns do -- Calculate the height local height = (chart_data[i + 1] / highest_value) * chart_height -- Draw a line if we have a last height if (last_height) then dxDrawLine(chart_x + ((i - 1) * column_width), chart_y - last_height, chart_x + (i * column_width), chart_y - height, colors.valueline, 2) end -- Save the height for the next value last_height = height end -- Reset the render target dxSetRenderTarget() end function renderChart() -- Nothing cached if (not rendertarget) then return end -- Calculate the position (not efficient to do here, but fuck that) local x = (screenWidth - box_width) / 2 local y = (screenHeight - box_height) / 2 -- Draw the render target dxDrawImage(x, y, box_width, box_height, rendertarget) end addEventHandler("onClientResourceStart", resourceRoot, function () -- Example cacheChartData("Fancy Chart Title", { 5, 10, 20, 6, 1, 19, 30, 15, 120, 59, 12, 22, 125, 12 }) -- Events addEventHandler("onClientRender", root, renderChart) addEventHandler("onClientRestore", root, cacheChartDrawing) end )
  13. Because you should update the onlineplayers table when you call checkall() function checkall() onlineplayers = getElementsByType("player") -- .. rest of your code end
  14. 1. Force the player to quit the game will be never packed into a function (would be annoying) 2. The only possible way is to crash the game
  15. The player would only reconnect (see wiki).
  16. botder

    outputChatBox

    See here: Lua Performance Test Results: pairs: 3.078 (217%) ipairs: 3.344 (236%) for i=1,x do: 1.422 (100%) for i=1,#atable do 1.422 (100%) for i=1,atable_length do: 1.562 (110%)
  17. botder

    Line chart

    Pick a width and a height. Find the lowest and highest values in the range. Divide the width by the amount of values you have for that range to get the width per column. Divide the the height by some random number you pick and to get a height per row. Then iterate through your values. Calculate the height for your chartvalue by doing chart_height * (row_value / highest_row_value). You can also save the last height to connect the last point with the next point. Need more?
  18. botder

    outputChatBox

    Even faster: local players = getElementsByType("player") for i=1, #players do outputChatBox("Hello", players[i]) end
  19. botder

    Line chart

    You have to use DirectX functions. First draw all the background and then draw all the values into that chart. I am not going into the maths, because that's your job (you can still ask for small help on the calculation).
  20. for index, value in pairs(mytable) do if (value == 996) then return index end end You can move that to a function and replace mytable and 996 with function parameters.
  21. Here: -- How Lua will see the table hellList = { [1] = { [1] = "***569FE453BD4260ECAB1BA18F382A2" }, [2] = { [1] = "***C4B55138CDE1251CC684759FB23F2" }, [3] = { [1] = "***0FD3104DD5F1768A20CA2E6C8AEA3" }, [4] = { [1] = "***DEF127AD04771C1CB847F0B480BE3" }, [5] = { [1] = "***E4510F78C3E0AB1474292DACAADC4" }, [6] = { [1] = "***24608511608C41E9D94A3D4E7F742" }, [7] = { [1] = "***02F041B50CC509B1CC9EEA81F6EA2" }, [8] = { [1] = "***96EEFFA5FE6B5E9A826ABF4A25584" }, [9] = { [1] = "***790600040ABF44115F80E117841E4" }, [10] = { [1] = "***49AD57FD37519BBA9A1DADD168D12" } } -- How to access the main table local first = hellList[1] --// = { [1] = "***569FE453BD4260ECAB1BA18F382A2" } -- How to access the second table local serial = first[1] --// = "***569FE453BD4260ECAB1BA18F382A2" -- How to loop through the table for i = 1, #hellList do local serial = hellList[i][1] if (serial == "***E4510F78C3E0AB1474292DACAADC4") then break end end for index, subtable in pairs(hellList) do local serial = subtable[1] if (serial == "***E4510F78C3E0AB1474292DACAADC4") then break end end How you might have done it: bannedSerials = { ["***569FE453BD4260ECAB1BA18F382A2"] = true, ["***C4B55138CDE1251CC684759FB23F2"] = true, ["***0FD3104DD5F1768A20CA2E6C8AEA3"] = true, --// ... } function hasPlayerBannedSerial(player) if (isElement(player) and getElementType(player) == "player") then return bannedSerials[ getPlayerSerial(player) ] or false else return false end end
  22. mod = getPlayerName(v):gsub("#%x%x%x%x%x%x", "").." - Moderator\n" You are replacing the variable with a fresh content. You have to append the content to the variable: mod = mod .. getPlayerName(v):gsub("#%x%x%x%x%x%x", "").." - Moderator\n" You have to do it for SMod and Admin too.
  23. addEventHandler, see optional arguments.
  24. You could remove the calculation from the "Select" command handler or call the function updateObjectLocation_Handler(). You could also add some other handy functionality for the height (optional, the object should stick to the ground all the time): function updateObjectLocation_Handler() if(selectedObject ~= nil) then local pX, pY, pZ = getElementPosition(localPlayer); local pRX, pRY, pRZ = getElementRotation(localPlayer); local pD = getElementDistanceFromCentreOfMassToBaseOfModel(localPlayer); local oX, oY = (pX+4*math.cos(math.rad(pRZ+90))), (pY+4*math.sin(math.rad(pRZ+90))); local oZ = (pZ - pD + getElementDistanceFromCentreOfMassToBaseOfModel(selectedObject)); setElementPosition(selectedObject, oX, oY, oZ); end end Edit: I am not sure if the - pD is neccessary
  25. Show us the line where you trigger that event.
×
×
  • Create New...