-
Posts
5,973 -
Joined
-
Last visited
-
Days Won
191
Posts posted by IIYAMA
-
-
On 11/03/2024 at 01:14, Snakegold said:
ERROR: Client "playername" triggered serverside event onPlayerDamage, but event is not marked as remotely triggerable
- Double check if the serverside file is running and init as serverside.
- Do not enable remote for native events. This is a security risk.
- Use the predefined client variable for remote triggers, else cheaters can kill a whole server instantly.
iprint(triggerClientEvent and "serverside" or "clientside") -- inspect if the file is running serverside addEvent("onPlayerDamage", false) -- disable remote function handlePlayerDamage(attacker, weapon, bodypart, loss) if client ~= source then return end local victim = client triggerEvent("onPlayerDamage", victim, attacker, weapon, bodypart, loss) -- emulate the (client) cancelled onPlayerDamage event if getElementHealth(victim) > 0 then setElementHealth(victim, getElementHealth(victim) - loss) if getElementHealth(victim) <= 0 then setElementData(victim, "isDead", true) killPed(victim) end end end addEvent("onCustomPlayerDamage", true) addEventHandler("onCustomPlayerDamage", root, handlePlayerDamage) function isPlayerDead(player) return getElementData(player, "isDead") or false end
function onClientPlayerDamage(attacker, weapon, bodypart, loss) if attacker and getElementType(attacker) == "player" then triggerServerEvent("onCustomPlayerDamage", localPlayer, attacker, weapon, bodypart, loss) cancelEvent() end end addEventHandler("onClientPlayerDamage", root, onClientPlayerDamage)
-
7 hours ago, Snakegold said:
I want to ensure that only one player dies in such situations.
Technically it is possible, but it will only work as intended when the latency is very low (< 60 ping) and stable internet (no packet loss).
How it technically works is that the server is used as mediator for all the damage. When a player it's health is 0, all future damage done by this player is ignored.
But keep in mind that this will look very weird when the latency is too high. (unplayable)
Some basics:
Clientside
Serverside
-
2 hours ago, Ryan167 said:
how could I make the marker only trigger on dimension 11?
If the parameter matchingDimension contains the value true, the marker is hit in the same dimension.
2 hours ago, Ryan167 said:What I'm trying to do is have a marker in dimension 11 and when the player joins the marker the player can't use a jetpack (it works but it stays working even outside the marker) and the weapons disabled, which works fine.
Instead of setting a timer. Which currently is being created infinity > crashing the server at a given point.
Do the following:
When giving a jetpack, check if the player is inside of the marker. Based on that, give the Jetpack yes / no.
-- Making the marker find able inside of another resource local antiJetpack = createElement ( "antiJetpackType", "antiJetpackID" ) local marker = createMarker ( 0, 0, 0, "cylinder", 1.5, 255, 255, 0, 170 ) setElementParent(marker, antiJetpack)
(Other resource)
local parent = getElementByID ("antiJetpackID") if not parent then return end local marker = getElementChildren ( parent )[1] local status = isElementWithinMarker ( thePlayer, marker )
https://wiki.multitheftauto.com/wiki/IsElementWithinMarker
-
23 hours ago, RandomRambo said:
and one more thing...where I can download mta 1.6n?Cus it says I need it to join the server on mta-1.6.0-unstable-7976-net41DA build on which it works...
Can't you just copy your Program Files (x86)\MTA San Andreas 1.6\server to the server? (maybe I am missing something, but a windows server should be able to start up windows stuff)
-
3 hours ago, pixel77 said:
data[1] and data[2] are numbers.
For example: inUseData[12][5] = true
The client is clicking on a dxDraw button, that is rendered on the 3D World.
Then the code looks fine. Unless the numbers are a mixture of numbers and strings. 123 vs "123"
16 hours ago, pixel77 said:So they can run the "--some more code here to do things" in the same time, and I don't want to allow this.
In theory it shouldn't be possible because this function is ran single threaded. There will always be one that is first. The whole function chain-call should have been ended before a new call can be made.
The following should be finished before the root function can be called again.
16 hours ago, pixel77 said:--some more code here to do things
- 1
-
3 hours ago, pixel77 said:
data[1]
What is inside of data[1] and data[2]? (to be more specific, what type is inside: table, string, number etc.)
And what are you clicking on?
-
5 hours ago, FernandoMTA said:
I opened a merge request to add two little client function defs that were missing
Merged!
- 1
-
-
3 hours ago, RandomRambo said:
Config changed after I installed latest build so config isn't the real problem.
It can be an issue if you used the config of an older build.
3 hours ago, RandomRambo said:It works perfectly on 1.5.9 builds,but on 1.6 it just restarts all time and no errors in console
You checked the logs as well? (sometimes not all errors are visible in the console)
And what kind of server are you running? Windows or linux?
If it is Windows, you should be able to copy over your local server and try that one.
If Linux, you might consider starting it up with sudo, so that it does not run in to any permission issues while creating/moving the initial files.
-
On 17/02/2024 at 21:20, RandomRambo said:
So,what is the problem that my server doesn't start on stable 1.6 build?:(
Is this server installed with MTA or did you download the stable version separately?
Things to check/do:- Check your virus scan, maybe some server files have been quarantined.
- Reset the config, maybe it is missing something: https://github.com/multitheftauto/mtasa-blue/blob/master/Server/mods/deathmatch/mtaserver.conf.template
- You might consider, just reinstall MTA competently.
-
5 hours ago, pixel77 said:
Any other methods?
A hard function skip maybe, just to figure out if it is actually the models.
addDebugHook( "preFunction", function ( ) return "skip" end, {"engineLoadCOL", "engineReplaceCOL", "engineLoadTXD", "engineImportTXD", "engineLoadDFF", "engineReplaceModel"})
(if possible run the hook on a resource with higher download priority)
If that is the issue, then rewrite the resources so that the models are loaded slower. For example load a model every X frame(s).
-
1 hour ago, pixel77 said:
Because it happens to more players, the problem comes from a resource on the host.
You could start with disabling all models, number 1 in causing cashes.
-
6 hours ago, FreezyMTA said:
When we log in manually using this URL, it gives a timed out error.
Is the web panel accessible? (and other resources)
-
12 hours ago, sirrjohn said:
if health >= loss then
Not sure but, would the > operator not make more sense?
if health > loss then --- ... else setElementExtraHealth(source, 0) -- clean dead status (not sure if this is a good idea) end
-
23 minutes ago, srslyyyy said:
I assume both annotations and go to definition (particularly variable, because you can already go to function definition) works for Sublime Text 4 as well?
Yes, that is indeed the case.
(Sublime)
- 1
-
1 hour ago, aRRRtem said:
So my question is how can I track other client`s software to block players with rippers?
I believe you should first understand the underlying problem.
1 hour ago, aRRRtem said:steal my game client files
They are not stealing your files. You are sending those files to them. When they host your files, this is where they are using your files without permission.
Quotewhere they use your files without permission
This is where I recommend to solve your problem. They are using your files because they are appealing to be used. If you make them less appealing, for example by adding branding to them, this will become advertisement for your server (in their server).
-
On 07/02/2024 at 21:24, Hiding said:
so I want my arrow marker to be visible even if there's an object front of it that obscures it.
You could try to use the dxDrawPrimitive3D function to mimic the marker and set postGUI to true, just keep in mind the downsides of postGUI.
© MTA wiki
- 1
-
4 hours ago, FreezyMTA said:
I gave HTTP authorization from ACL and meta.xml, but it still does not work.
You probably already did the following, but just checking.
What happens if you visit those URL's manually? (maybe it is asking for a login authorisation) -
5 hours ago, Turbe$Z said:
what wrong with the loop?
You have to index the variable veh one time less. Since the pairs loop did the first index already for you.
QuotedxDrawText(veh
[k][1].." | "..veh[k][2], sx/2-370,sy/2-297,sx/2,sy/2, tocolor(255, 255, 255, 220), 3, "default-bold", "left", "top", false, false, false, true )dxDrawText(veh[1].." | "..veh[2], sx/2-370,sy/2-297,sx/2,sy/2, tocolor(255, 255, 255, 220), 3, "default-bold", "left", "top", false, false, false, true )
- 1
-
6 hours ago, Snow-Man said:
what confuses me that when i get table into another tables inside and when i try to get a return from what?
Sometimes it really helps when you use the iprint function to print the current table. It shows you the current depth and helps you to decide how to index the next table.
When I for example I am working with a secret table.
iprint(result)
>
{ ["test"] = { { { [133]="found me!" } } } }
The first step is to peel it down.
Layer 1
iprint(result["test"])
>
{ { { [133]="found me!" } } }
Layer 2
iprint(result["test"][1])
>
{ { [133]="found me!" } }
Layer 3
iprint(result["test"][1][1])
>
{ [133]="found me!" }
Layer 4
iprint(result["test"][1][1][133])
>
"found me!"
-
21 hours ago, Snow-Man said:
im lost through a lot of tables
It helps if you write every table modification inside of a new function. This way you keep your code more readable.
The following examples are re-written code. You could use this as a start, but make sure to test it, because I didn't test it for you.
local farm = createFarm(123, 1, 1, 1)
local horse = createHorse(player, horseId) local farm = getFarmFromID (123) -- If the farm does exist if farm then addHorseToFarm(horse, farm) end
local horseCollection = {} -- all horses local farmCollection = {} -- all farms ---@param player userdata ---@param horseId integer ---@return table function createHorse(player, horseId) local horse = { id = horseId } horseCollection[horseId] = horse return horse end ---@param farmId integer ---@param x number ---@param y number ---@param z number ---@return table function createFarm (farmId, x, y, z) local marker = createMarker(x, y, z) local farm = { marker = marker, id = farmId, location = { x, y, z }, owner = nil, creator = nil, creationTime = getTickCount(), price = 0, horses = {} } farmCollection[farmId] = farm return farm end ---@param farmId integer ---@return table|false function getFarmFromID (farmId) return farmCollection[farmId] or false end ---@param farm table ---@param player userdata ---@return table function setFarmCreator (farm, player) farm.creator = player return farm end ---@param horse table ---@param farm table function addHorseToFarm (horse, farm) table.insert(farm, horse) end ---@param horse table ---@param farm table ---@return boolean function isHorseInFarm(horse, farm) for i=1, #farm do if farm[i] == horse then return true end end return false end ---@param farmId integer ---@return boolean function doesFarmExist(farmId) return farmCollection[farmId] and true or false end
- 2
-
You might want to leave a reply, even if you were not able to solve your issue with my response.
-
On 16/01/2024 at 04:44, Wasilij0814 said:
Hi guys i need help for this problem solving
QuoteGROUPS
(R); added in 8.0.2 (reserved)https://dev.mysql.com/doc/mysqld-version-reference/en/keywords-8-0.html
groups is a reserved keyword in MySQL: 8.0.2
Change:
SELECT * FROM groups
to
SELECT * FROM `groups`
You probably will have to fix the other queries as well.
-
- Popular Post
- Popular Post
Lua Language Server - Definition files
The Lua language server is a powerful tool that enhances the development experience for Lua programming. It provides a comprehensive set of code editing features, including suggestions, auto-completion, and error checking. With the Lua language server, developers can effortlessly navigate through their resource files, access documentation easily, and ensure code correctness by giving warnings.
Why should you care?
- The language server will inform you about all sorts of problems: type mismatches, missing function arguments, missing variables, etc.
- You have access to a lot of MTA syntax/autocomplete out of the box. The syntax information will remain while writing.
- You do not have to restart your resource so often in order to validate if everything is working.
Type validation
Having value type validation in your code editor is one of the main key features of the Lua Language Server. When working with variables, parameters, and arguments in Lua, you are not restricted to specific value types. This flexibility can make mistakes more likely to happen. However, being able to validate those mistakes instantly saves you a lot of time and frustration.
SpoilerIn the following example, we will be discussing type validation.
The code snippet below places a random player at the position (0, 0, 20).
local player = getRandomPlayer() setElementPosition(player, 0, 0, 20)
However, an issue arises as I receive the following warning:
Cannot assign `userdata|false` to parameter `userdata`.
- `false` cannot match `userdata`
- Type `false` cannot match `userdata`
(param-type-mismatch)
In this example, `userdata` represents a MTA element. The `setElementPosition` function expects to receive a `userdata` (element) type, but it is receiving either `userdata` or `false` type.
Let's analyze the `getRandomPlayer` function:
When I place my cursor on the `getRandomPlayer` function, you can see that it returns `false` when there are no players on the server. Therefore, the `player` variable can contain either a player `userdata` or `false`, depending on the player count.
userdata false
To resolve this warning, we can add an `if` statement to check if the `player` variable has a value that is not `nil` and not `false`.
local player = getRandomPlayer() if player then setElementPosition(player, 0, 0, 20) end
Now, only the player `userdata` is accessible within the `if` statement. userdata
falseType annotations for your own functions
Adding type annotations to your own functions can help improve validation and catch logic mistakes. It is particularly useful when calling functions from different parts of your code, as the annotations provide clarity on the expected input (arguments) and output (return values).
Additionally, comments that are placed above or adjacent to a variable or function are visible when hovering over them in another file or line. This can provide helpful information and context when working with the code.
How that looks like:
How can I quickly add annotations in less than a second? Open the spoiler:
SpoilerStarting with a basic function.
Spoilerfunction sum (a, b) return a + b end
Typing --- lines before the function name, will show this option.
Press enter
Spoiler---comment ---@param a any ---@param b any ---@return unknown function sum (a, b) return a + b end
Fill in the comment if you want. (optional)
Press tab to go to the next one.
Type number for a and b
And return a number as well.
Final result:
Spoiler---@param a number ---@param b number ---@return number function sum (a, b) return a + b end
When you hover over the sum function, you can see that it takes in 2 numbers and returns 1.
Adding these annotations can take less than 1 second of your time (that is if you auto complete also the type's).
What did we gain from our previous work?
The first benefit is showing us a warning if you are missing any required arguments.
The second one is showing us a warning about a type mismatches.
For example if we have this code:
local inputA = 123 local inputB = "123" sum(inputA, inputB)
The editor will warn us when we are using a string in our sum function.
Lets quickly fix that and return our result.
local inputA = 123 local inputB = 123 local result = sum(inputA, inputB)
Now lets make another mistake.
This time we want to enable birds when the result is higher than 10. Before we added the annotation, you wouldn't have noticed the mistake below.
local inputA = 123 local inputB = 123 local result = sum(inputA, inputB) setBirdsEnabled(result)
This warning indicates that the setBirdsEnabled function expects a boolean on it's first argument. But we gave it a number, which resulted in an angry . I mean a warning... ughm.
Lets fix that as well:
local inputA = 123 local inputB = 123 local result = sum(inputA, inputB) setBirdsEnabled(result > 10) -- Operators: https://www.lua.org/pil/3.2.html
AddEventHandler auto-complete
Most MTA addEventHandler functions have full eventName autocompletion. And the attached anonymous function is fully autocompleted and typed as well.
SpoilerNavigation features of Lua Language Server
It can be time consuming to find out where a (global) function or variable is located. Being able to jump right to it, saves you a lot of time.
Spoiler-
Go to Definition: Developers can quickly jump to the definition of a function, variable, or class within their codebase, allowing for easy exploration and understanding of code structure. (vscode: right click > Go to Definitions)
-
Find References: The Lua language server enables developers to locate all the places where a specific function, variable, or class is referenced throughout their code. (vscode: right click > Go to References)
-
Symbol Search: With the Lua language server, developers can quickly search for specific symbols (such as functions or variables) within their codebase. (vscode: ctrl + t)
Other information which you can find in the readme
Known issues
-
Make sure to always have an empty new line at the end of your files, as recommended in this issue.
-
Currently, the Lua server language definition files do not have a clear separation between serverside functions/events and clientside functions/events. However, it is possible to enforce this separation for specific functions if needed.
outputChatBox--[[@as outputChatBox_server]]("Serverside", player)
- In certain cases, certain functions in the Lua server language definition files may return multiple types, even if you have selected a different syntax. To handle this situation, you can use the `cast` or `as` notation to explicitly specify the desired type or adjust the returned type. See `Casting and as` syntax below.
Casting and as
In certain situations, you may have a strong understanding of the type(s) that a variable or expression will have. This is where the keywords "cast" and "as" come into play. These keywords enable you to explicitly specify the intended type, ensuring proper type handling.
local varName = exampleFunc() ---@cast varName string
Spoilerlocal varName = exampleFunc() ---@cast varName string | number
local varName = exampleFunc() --[[@as string]]
local varName = exampleFunc() --[[@as string | number]]
Download
The definition files can be downloaded here.
- 2
- 4
Lua Language Server - Definition files
in Tutorials
Posted
Visual Studio Code (for everything).
While I must say that I definitely love Sublime it's responsiveness, but it was (for me) not enough to change editors.