-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
This happens at the moment/distance that the lowLOD will swap with the default object. I set the opacity of the lowLOD to 0 and it was visible for a single frame during the swap, so I guess some of it's properties are re-applied at that moment. But it can also be something entirely different, except for the `moment` it occurs.
-
The base64 format can be used to neutralize characters that would break the code otherwise. Therefore it can be used inside of other languages, with as result the possibility of having `images` inside HTML or CSS. Just upload an image on that website and you will see.
-
We do not support leaked resources.
-
You can read xml from a string. So you got your xml tree scoped by your own script. https://wiki.multitheftauto.com/wiki/XmlLoadString But keep in mind that there is no MTA function yet to convert it back to a string. (unless you make one yourself)
-
Without library, you have to use triggerClientEvent to send a message back. You can't use the return keyword to send data back. "onClientGUIClick" > triggerServerEvent > isObjectInACLGroup... > triggerClientEvent > guiSetVisible...
- 1 reply
-
- 1
-
-
I haven't done/tested this before, but you can change the vehicle engine type. Not sure if that affects the audio as well. setVehicleHandling ( theVehicle, "engineType", "electric")
-
Maybe you could get the model from the database instead, since you already fetched the vehicle data. But that only works correctly if the database is up to date. It could become de-synced if: the vehicle model can be changed for the same ID AND the database does not receive an update after every elementdata change.
-
Just some format examples, the right format depends on how you work with them: itemProperties = { ["water"] = { ["friendlyName"] = "Water" }, ["sandwitch"] = { ["friendlyName"] = "Sandwitch" } } items = { ["water"] = {-- Item 1 ["amount"] = 2 }, ["sandwitch"] = {-- Item 2 ["amount"] = 1 }, } -- or items = { {-- Item 1 ["amount"] = 2, ["id"] = "water" }, {-- Item 2 ["amount"] = 1, ["id"] = "sandwitch" }, } combine_list = { { ["ingredients"] = { ["water"] = 2, -- 2x water ["sandwitch"] = 1, -- 1x sandwitch }, ["newItem"] = "water sandwitch" }--[[, { -- next combination ["ingredients"] = { ["water"] = 2, -- 2x water ["sandwitch"] = 1, -- 1x sandwitch }, ["newItem"] = "water sandwitch" }]] }
-
The checkPassiveTimer from the wiki page: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer do local passiveTimerGroups = {} local cleanUpInterval = 240000 local nextCleanUpCycle = getTickCount() + cleanUpInterval local onElementDestroyEventName = triggerServerEvent and "onClientElementDestroy" or "onElementDestroy" local function isEventHandlerAdded( eventName, elementAttachedTo, func ) -- https://wiki.multitheftauto.com/wiki/GetEventHandlers local attachedFunctions = getEventHandlers( eventName, elementAttachedTo ) if #attachedFunctions > 0 then for i=1, #attachedFunctions do if attachedFunctions[i] == func then return true end end end return false end --[[ Remove passive timers of elements that are destroyed ]] local function removeDeletedElementTimer () for timerName, passiveTimers in pairs(passiveTimerGroups) do if passiveTimers[this] then passiveTimers[this] = nil if not next(passiveTimers) then passiveTimerGroups[timerName] = nil end end end removeEventHandler(onElementDestroyEventName, this, removeDeletedElementTimer) end --[[ Make a clean up cycle to prevent a memory leak ]] local function checkCleanUpCycle (timeNow) if timeNow > nextCleanUpCycle then nextCleanUpCycle = timeNow + cleanUpInterval local maxExecutionTime = timeNow + 3 for timerName, passiveTimers in pairs(passiveTimerGroups) do for key, executionTime in pairs(passiveTimers) do if timeNow > executionTime then if isElement(key) and isEventHandlerAdded(onElementDestroyEventName, key, removeDeletedElementTimer) then removeEventHandler(onElementDestroyEventName, key, removeDeletedElementTimer) end passiveTimers[key] = nil end end if not next(passiveTimers) then passiveTimerGroups[timerName] = nil end --[[ Just making sure that during the clean-up cycle no lag spike occur. ]] if getTickCount() >= maxExecutionTime then break end end end end function checkPassiveTimer (timerName, key, timeInterval) if type(timerName) ~= "string" then error("bad argument @ 'checkPassiveTimer' [Expected string at argument 1, got " .. type(timerName) .. "]", 2) elseif key == nil then error("bad argument @ 'checkPassiveTimer' [Expected anything except for nil at argument 2, got nil]", 2) end local intervalType = type(timeInterval) if intervalType == "string" then timeInterval = tonumber(timeInterval) if not timeInterval then error("bad argument @ 'checkPassiveTimer' [Expected a convertible string at argument 3]", 2) end elseif intervalType ~= "number" then error("bad argument @ 'checkPassiveTimer' [Expected number at argument 3, got " .. type(timeInterval) .. "]", 2) end --[[ Set-up the timer ]] local passiveTimers = passiveTimerGroups[timerName] if not passiveTimers then passiveTimers = {} passiveTimerGroups[timerName] = passiveTimers end local timeNow = getTickCount() local executionTime = passiveTimers[key] if executionTime then if timeNow > executionTime then passiveTimers[key] = timeNow + timeInterval checkCleanUpCycle(timeNow) return true, 0 end checkCleanUpCycle(timeNow) return false, executionTime - timeNow end if isElement(key) and not isEventHandlerAdded(onElementDestroyEventName, key, removeDeletedElementTimer) then addEventHandler(onElementDestroyEventName, key, removeDeletedElementTimer, false, "high") end passiveTimers[key] = timeNow + timeInterval checkCleanUpCycle(timeNow) return true, 0 end end
-
The variable checkPassiveTimer? You have to add the function first before you can use it.
-
I recommend to check/remove the following: setTimer ( function(localPlayer) Overwriting the localPlayer with a nil value should cause problems. You could use the following useful function for blocking: elseif itemData["id"] == 34 then if checkPassiveTimer ( "limit-item-id-34", true, 10000 ) then -- this code can only run every 10 seconds end Get the function from here: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer
-
The syntax is incorrect, this code shouldn't be able to run. Missing: = Set the model serverside, else other players will not be able to see it.
-
I assume you filled in the last part? (where my comment is) Please show me what you cooked from it.
-
We can only see that you create infinity timers, which is even a much bigger problem since Lua can't put that to an hold.
-
@SoManyTears Is your problem resolved?
-
You could apply the effect only when the elements are streamed in, that would be an enormous improved in terms of performance. -- already streamed in elements for i,peds in ipairs (getElementsByType ("ped", root, true)) do for i,players in ipairs (getElementsByType ("player", root, true)) do setElementCollidableWith (peds,players,false) end for i,vehicles in ipairs (getElementsByType ("vehicle", root, true)) do setElementCollidableWith (peds,vehicles,false) end for i,objects in ipairs (getElementsByType ("object", root, true)) do setElementCollidableWith (peds,objects,false) end end -- -- new streamed in elements local acceptedElementTypes = {player = true, vehicle = true, object = true} addEventHandler( "onClientElementStreamIn", root, function ( ) local elementType = getElementType( source ) if acceptedElementTypes[elementType] then local peds = getElementsByType ("ped", root, true) for i=1, #peds do local ped = peds[i] setElementCollidableWith (ped,source,false) end elseif elementType == "ped" then -- what if it is a new ped? You can program this step yourself. end end )
-
Use the browser In combination with D3. https://d3js.org/ And pick for example this chart: https://observablehq.com/@d3/area-chart Or any of these: https://observablehq.com/@d3/gallery That is what I would do, if I do not want to spend too many hours in building a visualisation.
-
That is correct, because you can't do anything with resources that are not initialized. Except maybe for the name. (for new resources: onClientResourceStart) If you only need the resourceNames: You could save elementdata on the resourceRoot containing all resourceNames. Or (more secure/controllable) triggerServerEvent > triggerClientEvent to send over all the resourceNames. But think twice about which resourceNames you send over. Since it might be a little privacy sensitive for you...
-
That is probably because the following function is serverside only: https://wiki.multitheftauto.com/wiki/GetResources See here a workaround for clientside: local resourceRoots = getElementsByType("resource") for i=1, #resourceRoots do local thisResourceRoot = resourceRoots[i] local resourceName = getElementID ( thisResourceRoot ) if resourceName then local res = getResourceFromName(resourceName) if res and res ~= resource and getResourceState(res) == "running" then end end end Source resource: draw-distance https://gitlab.com/IIYAMA12/draw-distance/-/blob/master/scripts/main_c.lua#L248
-
How is that even possible, when you can't script and never ask pure scripting related questions nor showing a bit of interest? Doesn't that mean that the only thing the helper can do, is doing it for you? Think about it. Read it again, since you clearly mist something. You can request here for fixing resources, which is in your case the right match, don't you think?
-
You are correct in general, but not this time since the following unwillingness applies to Pedro001 for all scripting posts that I have seen until this far: Therefore it is considered as a scripting request. Please prove me otherwise if I made the wrong decision. Feel free to help him with his request, it is not as if the topic is locked.
-
Scripting/resource requests should be posted in resources. You should know that by now...
-
A database would use more CPU than just a plain file. When using a timeout (as Addlibs said), you can separate the database thread from the MTA thread. When having multiple CPU cores in your VPS server. Your CPU can automatic assign both threads to different cores, which leads to a very low impact on the performance. As for the file, MTA doesn't write directly to the hard drive, there is a buffer in between. Read more about flushing the buffer here. (Note: You shouldn't flush log files without reason) There is no big penalty here either. Very simple writing to a log file: local hFile = fileOpen("test.txt") -- attempt to open the file (read and write mode) if hFile then -- check if it was successfully opened fileSetPos( hFile, fileGetSize( hFile ) ) -- move position to the end of the file fileWrite(hFile, "hello" ) -- append data fileFlush(hFile) -- Flush the appended data into the file. fileClose(hFile) -- close the file once we're done with it else outputConsole("Unable to open test.txt") end -- https://wiki.multitheftauto.com/wiki/FileOpen And the downside of plain file has explained Addlibs already: Accessibility. XML? That is not a good idea for infinity data. XML uses a node system, each node representing a data-location in the XML tree, when you load the file, you load also all the nodes in to the memory. Loading the file should take longer based on the amount of nodes.
-
You can for example create an object (server), use projectile model: https://wiki.multitheftauto.com/wiki/CreateObject Move the object (server): https://wiki.multitheftauto.com/wiki/MoveObject And when it hits something (client), checking with this function every frame: https://wiki.multitheftauto.com/wiki/IsLineOfSightClear https://wiki.multitheftauto.com/wiki/OnClientRender Than you trigger to serverside and make an explosion: https://wiki.multitheftauto.com/wiki/CreateExplosion And yes it is not easy. If not an overwrite: The player that creates the projectile: projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, element target = nil, float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] ) https://wiki.multitheftauto.com/wiki/CreateProjectile If the vehicle creates it, the owner should be either the vehicle controller or the syncer.
