Jump to content

IIYAMA

Moderators
  • Posts

    6,089
  • Joined

  • Last visited

  • Days Won

    216

Everything posted by IIYAMA

  1. local lastCheckTime -- function () -- ... if isVehicleOnGround(vehicle) then if getVehicleSpeed(vehicle) >= 10 then currentTime = lastCheckTime or getTickCount()-- if lastCheckTime is nil, then use the current tickCount if currentTime - lastTimeAdded[vehicle] >= 5000 then if someVariable < #someTable then someVariable = someVariable+1 lastTimeAdded[vehicle] = getTickCount() else someVariable = #someTable end end else lastCheckTime = getTickCount() end end -- ... -- end function
  2. It is duplicated because of double loops. Just use one. --for i,item in ipairs(itemList) do for ki = iCurrentCell, iVisibleRows+iCurrentCell-1 do local visibleI = ki - iCurrentCell dxDrawRectangle(x*050+x*350, y*090+y*640/iRows*iCurrentCell, 5, y*640/iRows*iVisibleRows) local index = ki + 1 -- ki starts at 0, in lua we start with 1. local item = itemList[index] if item then dxDrawRectangle(x*060, y*100+visibleI*31, x*200, y*30, tocolor(0, 0, 0, 200), false) -- NOT AN ELEMENT: itemBackground = dxDrawText(item[1],x*070, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) --Problem is here :C dxDrawRectangle(x*265, y*100+visibleI*31, x*60, y*30, tocolor(0, 0, 0, 200), false) -- NOT AN ELEMENT: useBackground = dxDrawText("Text",x*282, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) -- NOT AN ELEMENT: useText = dxDrawRectangle(x*330, y*100+visibleI*31, x*60, y*30, tocolor(0, 0, 0, 200), false) -- NOT AN ELEMENT: dropBackground = dxDrawText("Text",x*347, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) -- NOT AN ELEMENT: dropText = if isCursorOverRectangle(x*060, y*100+visibleI*31, x*200, y*30) or isCursorOverRectangle(x*265, y*100+visibleI*31, x*60, y*30) or isCursorOverRectangle(x*330, y*100+visibleI*31, x*60, y*30) then dxDrawRectangle(x*060, y*100+visibleI*31, x*200, y*30, tocolor(0, 77, 126,20)) dxDrawRectangle(x*265, y*100+visibleI*31, x*60, y*30, tocolor(0, 77, 126,20)) dxDrawRectangle(x*330, y*100+visibleI*31, x*60, y*30, tocolor(0, 77, 126,20)) end end end --end
  3. local maxAmmo = 300 math.min(AllAmmo, maxAmmo)/x*jx
  4. As I said in my previous post. You just asked the exact same question as in your first post.
  5. Please read the > Note < again. It clearly says two lights for everything(except objects). And you can't attach them with the attachElements function, only with setElementPosition.
  6. There is a light element, but will probably only give partly the results you want. Please read the notes: Note: The direction of the light only has any effect if the light type is spot light. One light will only apply illumination effects to peds, players, wheels and number plates (like a emergency vehicle siren light does). Two or more lights will apply illumination effects to everything (excluding objects) that is in range of, at least, two of them. https://wiki.multitheftauto.com/wiki/CreateLight <light posX="" posY="" posZ="" type="" radius="" color="" dirX="" dirY="" dirZ="" shadows="" />
  7. Line 4 moveObject(sbarra, 4000, -1526.4400439453, 481.39999389648, 6.905, 0, -90, 0, 'InOutQuad') Line 10 moveObject(sbarra, -1526.4400439453, 481.39999389648, 6.905, 0, 90, 0, 'InOutQuad') You forgot to fill in the time.
  8. You can run them normally. There is no other option. Compiled scripts require a decompiler (and a MTA decrypter) to read the file. LUA scripting been implemented at a level which is limited by a the security system which does not allow to access this. Please give up on trying to load MTA compiled scripts with LUA. (absolutely not going to working)
  9. Just after you created the function.
  10. load/loadstring can indeed not load compiled scripts. Only pure uncompiled lua strings.
  11. Not recommended, will also disable a lot of other effects.
  12. Add this to line 17(this code). crealanciatori()
  13. teaDecode will decode everything. Just it is looks like it is messed up if you changed it before decoding. The easiest way is to compare fileR with the original file. Or compare the file size.
  14. No example required. You have to start making your code visible in order to understand it. Just fill up your entire code with debug lines. Run the code View in which order the lines show up. View the values of the variables. And you got your answer.
  15. local's are faster, because they are only active inside of an area. Real world example: It is something similar as buying things online in your own country(can be done within 24-hour) or order them from another(takes more than a day). Note: default MTA default functions are as fast as if you declare them as a local. Thought I would only declare functions as local if they are ONLY used for the code below or in case of onClienRender. There are two variants and the main difference while using is this: iprint(type(exampleFunction)) -- nil local function exampleFunction () iprint(type(exampleFunction)) -- function end iprint(type(exampleFunction)) -- function iprint(type(exampleFunction)) -- nil local exampleFunction = function () iprint(type(exampleFunction)) -- nil end iprint(type(exampleFunction)) -- function Fix for this one: iprint(type(exampleFunction)) -- nil local exampleFunction iprint(type(exampleFunction)) -- nil exampleFunction = function () iprint(type(exampleFunction)) -- function end iprint(type(exampleFunction)) -- function For more information: https://www.lua.org/pil/6.2.html
  16. At the place of creation > GUI, not when you click the button.
  17. The second one is using the ipairs function: https://www.lua.org/pil/7.3.html Benefit of the ipairs: ipairs returns the value as wel as the index. (no need to index on the next line as with the normal for loop) ipairs stops if there is no item at a given index: (not always a benefit thought) table = { 1, nil, -- < stops here 3 } Benefits of the normal for loop: Faster because it isn't using a function to loop. (functions are relative slow in compare to the rest of the code.) Can loop through nil values if required. table = { 1, nil, -- < keeps going! 3 } Can loop with different steps: for i=2, 10, 2 do --[[ 2 4 6 8 10 ]] end Can loop invert: for i=10, 1, -1 do --[[ 10 9 8 7 6 5 4 3 2 1 ]] end With other words there is no reason to use ipairs in my opinion.
  18. Once you understand the basics of variables, functions, debugging, tables and loops, the only thing that is your way is your mental model and your creativity. Which is something that has to grow over time. The fastest way to get at an higher level is to know exactly what your code does, which is achieve able by debugging (or lots of reading). So for example this code looks complex: (useless code btw) thisTable = {"randomStuff", [20] = "randomStuff", "randomStuff", [30] = "randomStuff"} function functionName (parameter1, parameter2) local newTable = {} for i=1, 30 do newTable[#newTable + 1] = (parameter1[1] or "nothing here") .. " | " .. math.random(1000) .. " | " .. parameter2 end return newTable end local result = functionName (thisTable, "text") Adding debug lines: thisTable = {"randomStuff", [20] = "randomStuff", "randomStuff", [30] = "randomStuff"} iprint("thisTable:", thisTable) -- show table structure function functionName (parameter1, parameter2) iprint("parameter1:", parameter1, ",parameter2:", parameter2) local newTable = {} iprint("newTable:", newTable) local countLoops = 0 for i=1, 30 do iprint('What does >(parameter1[1] or "nothing here")< do? ', (parameter1[1] or "nothing here")) newTable[#newTable + 1] = (parameter1[1] or "nothing here") .. " | " .. math.random(1000) .. " | " .. parameter2 countLoops = countLoops + 1 end iprint("Loop has executed:", countLoops, "times.") return newTable end iprint("functionName:", functionName, ", type value:", type(functionName)) local result = functionName (thisTable, "text") iprint(result) -- show end result But after debugging: (You have to do that yourself, post result please. Which is automatic your motivation towards me.)
  19. I am sorry, I do not have time for personal / private coaching. If you start from bottom you have to start with LUA and not with MTA scripting. There are enough basic tutorials around.
  20. No it is not, we came one step closer to a fix, because it solved multiple issues. Did you debug the place of creation (of the data)? Please show me your debug skills.
  21. -- ... elseif source == preview then if guiGridListGetSelectedItem(carGridList) == -1 then outputChatBox("Select one vehicle!", 255, 0, 0) return end -- Retrieve data local modelID = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 1) local price = guiGridListGetItemData(carGridList, guiGridListGetSelectedItem(carGridList), 2) -- modelID = tonumber(modelID) if modelID then local x, y, z = getElementPosition(localPlayer) local vehicle = createVehicle(modelID, x, y, z - 10) local ptimer = setTimer(function(vehicle) if isElement(vehicle) then destroyElement(vehicle) end end, 45000, 1, vehicle) else iprint("modelID is a",modelID) end elseif source == cancel then -- ... You might want to receive the data at the right place.
  22. This might be a solution, yet maybe not what you want. https://wiki.multitheftauto.com/wiki/SetElementVisibleTo (serverside)
×
×
  • Create New...