-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Posts posted by IIYAMA
-
-
10 hours ago, Prever77 said:
i was thinking about mechanism that also stacks changed values to certain amount. Like old table and new table concept
For some changes it is a good way to save resource. Like for example statistics or car fuel.
But do not do it for critical data. When for example your power shuts down, it could create weir de-syncs. (Like if you were buying a house ingame: you do not receive the house [in buffer] but the money has already been withdrawn [not in buffer])
10 hours ago, Prever77 said:Isn't it better for me to just make mta module that handle this stuff with multi core rather than single threaded lua? TheoreticaIy it should save me cycles on lua. And let them to be used more productive on bare bone server mechanics and scripting. And if so. what are good sources to begin with mta modules.
You can use MySQL + dbConnect, instead of writing a custom module.
The current MySQL module available is blocking the CPU thread, so that is not really an option for 200 players in my opinion.
Also a way to save resources, is to enable multi_statements:
local connection = dbConnect("sqlite", "database/database.db", "", "", "multi_statements=1")
When for example if you want to remove data at multiple tables.
dbExec(connection, "DELETE FROM shared_memory_file WHERE clientId = ?;DELETE FROM shared_memory_frame WHERE clientId = ?;DELETE FROM shared_memory_frame_position WHERE clientId = ?", clientId, clientId, clientId)
Or get data from multiple tables:
dbQuery(processRequestSharedMemory, { player, clientId }, connection, [[ SELECT variantKey, item, fileData FROM shared_memory_file WHERE clientId = ?; SELECT x, y, item FROM shared_memory_frame WHERE clientId = ?; SELECT x, y, z FROM shared_memory_frame_position WHERE clientId = ? LIMIT 1 ]], clientId, clientId, clientId)
-
1
-
-
On 18/02/2026 at 22:59, NoNamik said:
server-side is better for things like this, but with client-side I definitely wouldn’t put as much load on the server.
Or use both.
Server for:- Security/permissions to visit it.
- Any persisting data
Client for:
- Every element you see ingame
- Move/animate
- Camera
- UI
-
17 hours ago, Prever77 said:
1.is it worth of effiord to make buffer if i plan 80-200 players on my server.
Buffers can be useful.
Because you can only pick a server with a good CPU once. Sometimes you can upgrade the CPU, but there is a limit.- While with ram, it is easier to upgrade.
- MTA Lua processes are afaik still is single threaded.
But you need to invest a lot of time.
17 hours ago, Prever77 said:2.is validating client data with buffer and database worth concept
I can be.
-
An example db resource I made a while a go, not very efficient storage (text/string based), but easy to use.
Not sure why I build the types text based, I would have build it differently now a days.- Also recommended to write automatic tests for your creation, like I did with mine in sub folder \dev\*.
-
You can storage md5 hash validation strings for validation, if you are interested in that.
Smaller hash storage [binary]: using the UNHEX(hash) function (convert back with HEX(binary).
Example resource that uses hash validation for client screenshots.
17 hours ago, Prever77 said:3.what are your coding advices for me?. Im Asking experienced ones that ruled servers with large player base.
I am not one of them. But I do work often met databases.
I have put my recommendation in a spoiler if you are still interested:
SpoilerWhile buffers can be useful.
- They can be also create bugs if not created correctly.
- Require lots of testing.
-
But they do in fact make it easier to handle Async requests. Keeping your db from blocking you Lua processes.
-> Using synced requests makes things easier, but could also create lag on your server.
There is 1 alternative to consider and that is to keep the active data in memory. While you do write to the db, you do not fetch data that you already know and keeping it around. This is a concept you could consider a buffer, the only difference is that you pre-load all the data you might need. And moving the 'truth' from the db to the memory when initialising.
So when a player joins. You get his health, armor, money, house name,
name etc. etc. And put it in a table that represents his exact model in the db.
When values change, you only write to the db.This keeps the data fast and persistent. But with the downside that if there is a bug in your code, your db becomes desynced with your memory. And when the player reconnects the 'truth' of the db leads again. It is important to mirror in Lua the database column limitations, which should solve most of those issues.
Last recommendation:
- Add rate limits for requests done by a client. Your db is one of your server it's weaknesses. (concept of a passive rate limit)
-
1
-
6 hours ago, EhsanFox said:
Or perhaps use the current account system of MTA as well since I can't edit to create my own
For a access scoped accounts.
Step 1.
Make a backup of your acl.xml file.
Step 2.
Create a new account with for example the name:
/register user_XTrqveZgi8 {password}Step 3.
Modify the acl.xml.
Add a group:
Used for defining who has access to what.The prefix user.{username} is used to define that it is a user account that is granted access.
<group name="webaccess"> <acl name="webaccess_acl"></acl> <object name="user.user_XTrqveZgi8"></object> </group>
And the access list:
Used to define the access rights.Replace resource.{resourcename}.http with the resource that is allowed to be accessed to.
You can also rename webaccess_acl, but you also have to update the same name in the acl tag located in the group: <acl name="{name}"></acl>)
<acl name="webaccess_acl"> <right name="resource.resourcename.http" access="true"></right> </acl>
This all will grand the user 'user_XTrqveZgi8' access to http requests to resource {X}.
Things to keep in mind:
- Never use an old ACL, because not yet created -> known accountnames can be recreated by a random player in your server.
- Always make a backup of your ACL file.
-
1
-
1 hour ago, EhsanFox said:
I see the server logs saying that I logged in, but the API asks again.
Not sure what kind of backend you use. But here is an npm packets that could be used for inspiration. Probably some dependencies are deprecated.
https://github.com/4O4/node-mtasa/tree/master
The authOptions:
Using it in request:
https://github.com/4O4/node-mtasa/blob/aeac8ab9417a7b6a65f117491d1e648a6ad62422/src/client.ts#L62
But under the hood (in JS) it is something like this:
const credentials = `${username}:${password}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); const result = "Authorization: Basic " + encodedCredentials
The header is: Authorization
The value is something like: Basic bWlqblVzZXI6Z2VoZWltV2FjaHR3b29yZA==
-
1
-
-
46 minutes ago, EhsanFox said:
So Idk, is this normal to not be able to trigger an event on a remote URL?
It should be for security concerns. You wouldn't want to visit a site that is designed to look for 'new functions' and starts call them.
46 minutes ago, EhsanFox said:But obviously, how? The MTA doesn't provide us with any resources to at least create an API server on a server-side resource
If you take a look at this page:
https://wiki.multitheftauto.com/wiki/Meta.xml
You can see that it is possible to call an export function over httpQuotehttp: Can the function be called via HTTP (true/false)
What syntax do you need for calling an export function?
http://<your IP>:<your port>/<resource_name>/call/<exported_function_name>
https://wiki.multitheftauto.com/wiki/Resource_Web_Access
How does authentication works?
https://en.wikipedia.org/wiki/Basic_access_authentication#Client_side
A 'basic' authentication should the way to go. It requires login credentials of an MTA user account with the correct permissions. This has to be passed every request.
When you connect through the browser:
http://127.0.0.1:22005/resourcebrowser/You more or less understand what to expect.
There is also a section about 'Router', which is new. Might be useful.
https://wiki.multitheftauto.com/wiki/Resource_Web_Access#Router
For inspiration https://community.multitheftauto.com/index.php?p=resources&s=details&id=18781
This resource is about fetching data from MTA to a (remote) host. This is the opposite of what you are trying to achieve, but probably still useful.- Fetching from MTA to remote host
- Creating a MTA user (installation_s.lua) that only has the correct permissions.
-
1
-
On 22/12/2025 at 10:35, ZeusDev said:
The idea is simple: when someone fires a weapon at a player, you know the expected damage. Then you check if their health actually dropped by that amount. If they keep taking hits but health never goes down, something's wrong.
Just to verify, does this actually work?
Because 'target' is afaik set by the player that fired the weapon and not by the player that got hit. And therefore there are a lot false positives, unless you let remote players decide the damage done to the localPlayer (which is not handy).
addEventHandler("onPlayerWeaponFire", root, function(weapon, _, _, _, _, _, target) -
On 31/08/2025 at 14:21, HunT said:
You're right!! Chatgpt isn't the best for creating complex scripts, but it's a great help for people just starting out with mtasa scripting. Personally, after 12 years, I've forgotten all about scripting
Chatgpt and other similar sites are a great help for beginners
I am working with Cursor. Which is a fork of Visual Studio Code modified with AI in mind. It is my daily driver.
The free version should give you enough monthly requests to finish your script.
An no this is not a stupid AI, it is a optimised version for coding after all. You can even choose which AI you want to use, but some advanced may be behind a paywall.
-
1
-
1
-
-
There is also a baked in option in the map editor (extension).
Make sure your editor is up to date and your map contains the latest extension file.

For manual upgrades:
- https://github.com/multitheftauto/mtasa-resources/blob/master/[editor]/editor_main/server/mapEditorScriptingExtension_s.lua
- https://github.com/multitheftauto/mtasa-resources/blob/master/[editor]/editor_main/client/mapEditorScriptingExtension_c.lua
Example map meta.xml with useLODS option enabled:
Spoiler<meta> <min_mta_version server="1.5.8-9.20957"></min_mta_version> <info type="map" version="1.0.0"></info> <map src="test-lod.map" dimension="0"></map> <settings> <setting name="#maxplayers" value="[ 128 ]"></setting> <setting name="#useLODs" value="[ true ]"></setting> <setting name="#gamespeed" value="[ 1 ]"></setting> <setting name="#minplayers" value="[ 0 ]"></setting> <setting name="#gravity" value="[ 0.0080000004 ]"></setting> <setting name="#waveheight" value="[ 0 ]"></setting> <setting name="#locked_time" value="[ false ]"></setting> <setting name="#weather" value="[ 0 ]"></setting> <setting name="#time" value="12:0"></setting> </settings> <script src="mapEditorScriptingExtension_s.lua" type="server"></script> <script src="mapEditorScriptingExtension_c.lua" type="client" validate="false"></script> </meta>
-
There is also this function
:
-
On 09/07/2025 at 15:36, Matevsz said:
but after a while the game starts to lag
Might be because the (player/server) network can't catchup.
-- (un)subscribe to the vehicle fuel element data of a specific vehicle addEventHandler("onVehicleEnter", getRootElement(), function(thePlayer, seat) if seat~=0 then return end -- Wiki Note: Before using addElementDataSubscriber you need to setup an initial value of element data in "subscribe" mode, otherwise the subscriber will not be added. if not getElementData(source, "plane:fuel") and getVehicleType(source) == "Plane" then setElementData(source, "plane:fuel", 0.18, "subscribe", "deny") end addElementDataSubscriber(source, "plane:fuel", thePlayer) end) addEventHandler("onVehicleExit", getRootElement(), function(thePlayer, seat) if seat~=0 then return end removeElementDataSubscriber(source, "plane:fuel", thePlayer) end) setTimer(function() -- Start with all players instead of all vehicles, because there are often more vehicles than players local players = getElementsByType("player") for i=1, #players do local player = players[i] local vehicle = getPedOccupiedVehicle(player) if vehicle and getVehicleType(vehicle) == "Plane" and getVehicleEngineState(vehicle) then local fuel = getElementData(vehicle, "plane:fuel") or 0.18 if fuel > 0 then -- do not update if fuel is 0 or lower, else you are wasting bandwidth by setting the data to the same value fuel = fuel - fuelUsePerSecond if fuel < 0 then fuel = 0 end setElementData(vehicle, "plane:fuel", fuel, "subscribe", "deny") end end end end, 1000, 0)
Please let me know if the addElementDataSubscriber function works as expected, haven't used it myself yet.
-
On 22/06/2025 at 12:58, MineX server said:
- Is there a reliable way to detect if the client-side damage event was cancelled?
You might be able to detect it using:
https://wiki.multitheftauto.com/wiki/WasEventCancelledThough I do not know if this functions works correctly for native events. Something you have to test yourself. Make sure to set the addEventHandler to low priority.
-
19 hours ago, eksorz said:
No, like this:
You have to put it at the location where you want to make your trace. If you do not put it inside of another function, it will return "in main chunk", because it is tracing function calls starting from the main chunk.
For example:
function test1() test2() -- call test2 end function test2() test3() -- call test3 end function test3() test4() -- call test4 end function test4() -- ENDS HERE print(debug.traceback()) end test1() -- STARTS HERE
Will return:
stack traceback: Main.lua:14: in function 'test4' Main.lua:10: in function 'test3' Main.lua:6: in function 'test2' Main.lua:2: in function 'test1' Main.lua:17: in main chunk [C]: in ?
It will show all functions that have been called.
And for your current code, it might give you the function(s) where, your onClick got lost.
-
1 hour ago, eksorz said:
I printed the traceback method you gave me right after creating the Button object. In the line I printed, it said "in main chunk", I don't know what it means.
Like this?
function createButton(config) local self = setmetatable({}, Button) iprint(debug.traceback()) self.x = config.x self.y = config.y self.width = config.width self.height = config.height self.text = config.text or "Button" self.color = config.color or "blue" self.fade = config.fade ~= false self.onClick = config.onClick or false -- // This always returns false, even if I added onClick function. self.alpha = self.fade and 0 or 255 self.fade_step = 15 self.visible = true self.currentColor = Theme.colors.button[self.color].background table.insert(activeButtons, self) return self end
-
Quote
I am sure that the problem is not in the injectModules() function. There is a prepared Window class next to the Button class, I can use it as Window({...}) by using the injectModules() function. Similarly, I can print the button and get the argument variables by using Button({...}). Only function operations return "nil" value.
Hmm.
Can you show a trackback from your button constructor?
iprint(debug.traceback())Just to get an idea trough how many other functions it's constructed. Not sure what the results are, but it might give you some other places to look at and find where your value gets lost.
Make sure to only construct one thing at the time, else it generates too much.
-
11 hours ago, eksorz said:
it always returns the value as "nil".
One of the common problems is that function values are not clone able. Functions rely on their context and can therefore not being copied to another context.
But not sure if that is the issue.
For the Button class I am missing some context. In the first file it is used as a metatable.
And in the second file it is used as a function. (which might also be a metatable, but I am unable to verify it because it is missing)
11 hours ago, eksorz said:loadstring(exports.ui:injectModules())()
Is this export importing Button.lua?
Other:
-
Watch out for
- setTimer parameters cloning
- Export cloning
- TriggerEvent cloning
- Original metatable data is modified by another button creation
- Might need to use raw(get/set) (context based):
-
Watch out for
-
2 hours ago, DonnySheffield said:
Any idea why this could happen?
It is on the top of the code, just running once at the beginning.
Could you explain why you put it there? Just so that I can understand the context of that variable placement, because normally you wouldn't put it there unless there is a specific reason.
-
21 hours ago, Bishop_G said:
Is this an attack? How can I prevent this?
It is indeed a kind of attack. It means that the player is able execute clientside-code on demand.
The attacker is triggering 'known generic events' which might be handled by the server. The ones that are unknown are in your logs, the ones that are known and trigger able are not.
But that does not mean that the ones that did trigger didn't cause unwanted results. You might want to consider to restart the resources, just to make sure there is no memory leak.
The event which AngelAlpha mentioned can indeed help with detecting that kind of attacks.
As an extend you can also add a honeypot, which in this case are 'unkown' events for your server but know for other servers. When a player uses this kind of attack again, you can ban them automatic. You might want take a closer look at your logs for candidates (for example money related).
There is also this event:
https://wiki.multitheftauto.com/wiki/OnPlayerTriggerEventThresholdBut be careful with automating things, always test these kind of stuff or you might accidentally nuke your own player base.
-
1
-
1
-
-
You can either download the newest here:
https://github.com/multitheftauto/mtasa-resources
Or go back to a specific commit:
https://github.com/multitheftauto/mtasa-resources/commits/master
Download button can be found under 'Code':
-
8 hours ago, DarkStalker30 said:
If character will be in water while player has black screen by fadeCamera() and HUD off, will it trigger breath bar?
It will probably be visible when the camera is fade out. So yes you need to add some more exceptions for unexpected situations.
This condition might catch some of the problems:
if getCameraTarget () ~= localPlayer then return end
-
I don't think there is a way to force it.
If it did, then it should be defined here:
- https://wiki.multitheftauto.com/wiki/HUD_Components#Properties
- https://wiki.multitheftauto.com/wiki/SetPlayerHudComponentProperty
But as alternative you can draw a bar under it with:
-
22 hours ago, J4cobLIVEmain said:
Do you guys have any suggestion, how it could be done?
Maybe move the checkpoint very high in the air (and replace it with a dummy).
When the rocks are cleared, move it back.
-
1
-
-
3 hours ago, Bishop_G said:
Please someone help me.I will be very appreciative of this.
It is a permission issue.
https://wiki.multitheftauto.com/wiki/Server_Commands#aclrequest
First verify if the meta.xml has any acl request listed in it's meta.xml
/aclrequest list <resourceName> all
And if loadstring is listed, grand permission.
/aclrequest allow <resourceName> all
If not listed, add it to the meta.xml of the resource:
<aclrequest> <right name="function.loadstring" access="true" /> </aclrequest>
See example: https://wiki.multitheftauto.com/wiki/Meta.xml
Run:
/refreshall
And try the aclrequest commands again.
-
1
-
-
40 minutes ago, King12 said:
Failed to accept map: Missing required fields: adminName, action, mapName
Are you sure your API is capable of accepting JSON?
fetchRemote(url, { method = "POST", formFields = { adminName = "", action = "", mapName = "" }, }, function(responseData, responseInfo)
If JSON is expected, see also this comment on the wiki page:
QuoteWarning: When using toJSON for submitting data, make sure to use string.sub(data, 2, -2) to remove the initial and final brackets, as many APIs will not understand the request
postData = string.sub(postData, 2, -2)


Help with data management
in Scripting
Posted
I have no experience with C++ myself nor with modules.
But I do know that Lua is fast enough for a basic gamemode. The moment C++ might become important is when you want to implement something like pathfinding.
There are other things that can save you more resources. For example using less timers. Most of the time getTickCount / getRealTime is more than enough.
Or use as less as possible element data.
Sort of
: https://wiki.multitheftauto.com/wiki/Modules_Introduction