-
Posts
6,058 -
Joined
-
Last visited
-
Days Won
208
Everything posted by IIYAMA
-
@VazErn As long as it works, people are always happy. A few tips: A loop for this is not required, unless there are multiple similar database items. for i, id in pairs(queryTable) do setElementData(source, "ID", id["id"]) end setElementData(source, "ID", queryTable[1]["id"]) (untested, but should be working) ------------------------------------------------------------------------------------------------ The sky is the LIMIT If the database has already found what it is looking for, then why not stop looking for more? LIMIT 1 Read more / how to use: https://blog.udemy.com/sql-limit/ ------------------------------------------------------------------------------------------------ Timers are working asynchronous What would happen if a player leaves during those 3 or 14 seconds when the timers are still running? setTimer(setCameraTarget, 3000, 1, source, source) setTimer(triggerClientEvent, 14000, 1, source, "renderRoyalID", source) Just think about it. setTimer(function (element) if isElement(element) then -- do your thing end end, 3000, 1, source)
-
If streamed in objects aren't a solution, then fixing the problem by the source might be a solution. Preparing: -- instead of setElementData local munkakuka = createElement("munkakuka") setElementParent(munkakuka, object) https://wiki.multitheftauto.com/wiki/CreateElement Creates the element munkakuka Sets the munkakuka element as child of the object. Using a map file instead of a script? (also possible) Looping: local munkakuka = getElementsByType( 'munkakuka') for k=1, #munkakuka do local v = getElementParent(munkakuka[k]) It gets all custom elements `munkakuka`. Get the parent of it. (which is the object) This should reduce the amount of loops of the code. You can also set the object as child of the munkakuka element + it can make the code faster if you limit the note scope. (requires to change the code a little bit)
-
You are making me shy
-
Looping through an object structure instead of an array structure is slower, even though you do not have to recreate the table. -- Object structure { [value1] = true, [value2] = true } -- Array structure { [1] = value1, [2] = value2 } -- Same as: {value1, value2}
-
Too many objects? Optimizations you can do: Limit the amount of objects and faster looping for k, v in ipairs ( getElementsByType( 'object' )) do local objects = getElementsByType( 'object', root, true ) -- only streamed in objects! for k=1, #objects do -- A `for loop` is faster local v = objects[k] https://wiki.multitheftauto.com/wiki/GetElementsByType syntax: (client) getElementsByType ( string theType, [ element startat=getRootElement(), bool streamedIn=false ] ) Texture ftw! (argb texture) -- on top of your script! local objectBlipTexture = dxCreateTexture( "blips/1125.png") ---------------------------------------------------------------- -- now draw! dxDrawImage(blipX - blipSize/2, blipY - blipSize/2, blipSize, blipSize, objectBlipTexture, 0, 0, 0, tocolor(255,255,255,255)) This is a texture speed test on wiki. You are currently rendering from a path. Which is according to this test ~6,75x slower than just a pre created texture (argb). https://wiki.multitheftauto.com/wiki/DxCreateTexture
-
Yea, I believe that describes the resource the best. And yet, it surprised me how many conditions (for critical gamemode scenario's) it required to work properly. ?
-
Regeneration (health) This resource lets you regenerate player and vehicle* health. It is not an unique idea, I know... but there weren't good implementations for it at the community resource list. So that's why I share this with YOU. * Vehicle regeneration for the driver only. Version 1.0.0 Not compiled! Smooth health regeneration No UI, just the manager Settings (Admin panel) Settings Regeneration [on/off] (player/vehicle) Regeneration value (player/vehicle) Regeneration delay (player/vehicle) Regeneration [on/off] while the vehicle is burning Download link: https://community.multitheftauto.com/?p=resources&s=details&id=15757 Take a quick look into the source code (v1.0.0) Client Server Meta
-
That are murderous tests :(, I wish you good luck!
-
@koragg The resource type isn't synced in the first place.(afaik) All below is just a guess: If you are not going to use a resource to sync that information, then there is a possible way to figure out if that resource is using map files. Technically it should be possible with this function: https://wiki.multitheftauto.com/wiki/GetElementChildren https://wiki.multitheftauto.com/wiki/Element_tree The element tree is attaching map elements on the mapRoot. The mapRoot should be attached to the resourceRoot. If this mapRoot is synced + synced before the resource starts clientside, then yes you might figure out if this resource can be considered a map. The only problem is that every resource can serve map files. Next to that, you can maybe find some element data leftovers from those (sub)root elements: https://wiki.multitheftauto.com/wiki/GetAllElementData https://wiki.multitheftauto.com/wiki/GetElementID Let me know if you find something interesting!
-
Why would I code something that is already there? People these days....
-
nope, not an example. But there are of course examples on wiki: https://wiki.multitheftauto.com/wiki/EngineApplyShaderToWorldTexture https://wiki.multitheftauto.com/wiki/DxCreateRenderTarget If you merge those wiki codes, you probably get some results. If you want to have some specific information about these functions, feel free to ask. But make sure to check wiki first X 10. ( one uncertainty ) If render target textures can't be used for shaders directly, then you can also copy them to another texture. https://wiki.multitheftauto.com/wiki/DxGetTexturePixels https://wiki.multitheftauto.com/wiki/DxCreateTexture All required wiki examples: addEventHandler("onClientResourceStart", resourceRoot, function() myRenderTarget = dxCreateRenderTarget( 80, 100 ) -- Create a render target texture which is 80 x 100 pixels end ) addEventHandler( "onClientRender", root, function() if myRenderTarget then dxSetRenderTarget( myRenderTarget ) -- Start drawing on myRenderTarget dxDrawText ( "Hello", 10, 20 ) -- Draw a message dxSetRenderTarget() -- Stop drawing on myRenderTarget dxDrawImage( 50, 50, 100, 100, myRenderTarget ) -- Now use myRenderTarget as a material and draw it lots of times dxDrawImage( 150, 350, 150, 100, myRenderTarget ) dxDrawImage( 250, 250, 100, 150, myRenderTarget ) dxDrawImage( 350, 30, 150, 150, myRenderTarget ) end end ) local myRenderTarget = dxCreateRenderTarget(500, 500, true) -- -- Function to draw text to our render target with '''modulate_add''' blend mode when the 'r' key is pressed -- function updateRenderTarget() dxSetRenderTarget(myRenderTarget, true) dxSetBlendMode("modulate_add") -- Set 'modulate_add' when drawing stuff on the render target dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "clear") dxSetBlendMode("blend") -- Restore default blending dxSetRenderTarget() -- Restore default render target end bindKey("r", "down", updateRenderTarget ) theTechnique = dxCreateShader("shader.fx") explosionTexture = dxCreateTexture( "tex/Explosion.png") function replaceEffect() engineApplyShaderToWorldTexture(theTechnique, "fireball6") dxSetShaderValue (theTechnique, "gTexture", explosionTexture) end addEventHandler("onClientResourceStart",resourceRoot,replaceEffect) Shader texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } }
-
Text on a texture? https://wiki.multitheftauto.com/wiki/DxCreateRenderTarget
-
No, I do not see the errors you have. (in console) https://wiki.multitheftauto.com/wiki/OnClientElementDestroy is not cancel able.
-
Image not working. @JeViCo
-
You can script C++ within modules. https://wiki.multitheftauto.com/wiki/Modules But there are not so much people that are making use of that, as lua is so much more flexible and in MTA resource based. With other words, do not expect much support in this matter. If you know C++ then I am very sure you will not have much trouble with lua.
-
If the break keyword is used directly inside the loop you want to stop, then yes. ---- -- works for ... do for ... do break end break end ---- ---- -- does not work for ... do for ... do break break end end ---- If your code works, then first run a speed test. (So you can actually see if your speed improves with every action you take. local timeNow = getTickCount() for speedTestIndex=1, 1000 do -- <<< put your code in here end local endTime = getTickCount() outputChatBox("code duration: " .. (endTime - timeNow)) Write down below your code how long this took. (It is best to run the test twice per code) Improvement your code: - use the basic for loop, instead of the ipairs loop and test again. (The same type as the one of the speed test) Note: this code does not test for double items, is that a must?
-
@Flower ☠ Power More RAM? I am not sure. ElementData has as nasty after effect that, the data remains in the memory (even the server) after it has been set. This has to be cleared manually. Stopping a resource doesn't clear it, unless it is applied to a >destroyed< element of that resource. But it might be true that the triggerEvent uses more RAM while being executed, as it is a more direct method. If you trigger from one side to another side (without latent events), you will notice that it is a high priority network request, while elementData is being send/received after a (few) frame(s). << not sure how elementData is prioritised. I haven't been in to the development of MTA, so keep in mind that there might be other explanations for these results, as everything that I am saying is based on my own experience.
-
Trigger events will use around 3 t/m 7 times more network(I do not know the exact multiplier) per player incompare to elementdata. * send tables over without much impact on the network. * can indeed be send to specific players. * do also have a latent variant which doesn't block the network. * require more code to sync. Elementdata * is a logic method to add properties to an element. (Which has more or less to do with the name of functions) * always synced with all players A single * execution of a single connection has relative low impact on the network. Player > server * each set counts as an update of the server and the other clients. (CPU) Both methods trigger the event system. Just specific trigger events should technically trigger specific clients only. (specific performance details of the cpu are not known by me) So pick which you think that is right. Thought, I wonder if using the UDP protocol through a browser might be using the lowest amount of data.
-
Tag can't start with a number. Rule nr.4: http://www.adobepress.com/articles/article.asp?p=1179145&seqNum=4 (There are all 9 rules on that page) Also a XML validator will tell you where an error might be located: https://www.xmlvalidation.com/index.php Last note: Try not to use custom tags based on your data. Pre-sets of tags like col, txd and database are fine. The methods you should use for custom data are: <tag>value</tag> and attributes="..."
-
Ever seen a meta table as they are created? A meta table is used to change the behaviour of a regular table. The main issue is with the fact that it uses functions to achieve this behaviour. And functions... Optional Arguments NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments. sendTo: The event will be sent to all players that are children of the specified element. By default this is the root element, and hence the event is sent to all players. If you specify a single player it will just be sent to that player. This argument can also be a table of player elements. arguments...: A list of arguments to trigger with the event. You can pass any lua data type (except functions). You can also pass elements. https://wiki.multitheftauto.com/wiki/TriggerClientEvent ...can't be send over according to wiki. But even if this is a meta table, you will have the same problem with a regular table. This has probably happend: all the functions that are inside of the table are deleted.
-
The most fast methods are very dirty. I will only explain those ones when I think you have learned enough from the clean ones. But make one first. Just two loops, one nested in to the other. And try to figure out what the most logic human method would be to achieve your goal. If it fails, don't worry, just post what you tried. But it has to be yours, only then I will help you.
-
Debug your code? https://wiki.multitheftauto.com/index.php?title=Debugging Learn the basics of lua? Write down what all functions do? (in order to understand what the code does) You could do that.
-
getAttachedElements (vehicle) This returns a table with attached elements. #table # gets the length of a table. value > 0 This returns true or false depending if the value is higher than 0. local serin = result This saves the result in to serin.
-
A very quick and basic solution, would be: local siren = #getAttachedElements (vehicle) > 0 Place it where you think it would make sense in your code. And if you do not know where to place it, you can always try it at all 24 lines till the code finally does what you want... ? @Ekko
-
I still have no clue which one of the two you mean. Heli rotors switch (90-degree) = model ( ask somebody who edits GTA models ) Heli rotors animation (360-degree propeller rotation) = texture + shader ( ask somebody who create shaders, they are easy to find if you search for shader resources )