multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.38k stars 427 forks source link

More math functions for mta #654

Closed CrosRoad95 closed 10 months ago

CrosRoad95 commented 5 years ago

Is your feature request related to a problem? Please describe. Low amount of math function that are used often

Describe the solution you'd like Add more math functions

Describe alternatives you've considered Copy and paste one piece of code to every resource

Additional context few math functions that could be added, all of them you can find on wiki and in google getDistanceBetweenPointAndSegment2D getDistanceBetweenPointAndSegment3D, findRotation2D, findRotation3D, getPointFromDistanceRotation, getOffsetFromXYZ except that, should be added function for bazier curve and splines in 2d and 3d

qaisjp commented 5 years ago

Would library inclusion solve this problem for you?

ArranTuna commented 5 years ago

This is basically a request to not have to type exports.resourceName: so what if there was an MTA function like addExportAsFunction(function) which would be called inside the script that creates the export, then each resource would have that function added as a function that can be called without need for exports.resourceName or even addFunctionAsGlobalFunction(function) that would clone any function (doesn't need to be exported) into each resource's function register (that _gc thing?)

CrosRoad95 commented 5 years ago

@ArranTuna no, already exists getDistanceBetweenPoints2/3D why not other useful math functions? this function implementation is shorter then name of this function, but getDistanceBetweenPointAndSegment3D is i think ~30 lines of code

i also want require addFunctionAsGlobalFunction and other simillar things

ArranTuna commented 5 years ago

What I mean is servers can add those functions (plus we could have a default resource with all the useful functions included) and all you have to do is start that resource, then it will make all the useful functions accessible in any resource.

CrosRoad95 commented 5 years ago

now, we need wait for someone who say security "you can overwrite other resource", "you can do X" "you can do Y" but you don't need this functions to destroy server, just destroyElement(root) #security

qaisjp commented 5 years ago

Quickest, easiest and most lightweight solution ( for the solution being discussed here is a new function getResourceExports.

Then someone can just write code to automate those exports being introduced into the global scope with an exports wrapper.

@CrosRoad95, you mentioned that library inclusion with require would not solve your problem. Why not?

CrosRoad95 commented 5 years ago

require can solve almost every problem in mta. Why some math functions ( easing functions, tocolor, getDistanceBetweenPoints2/3D ) are build in mta and others wouldn't be in mta?

getDistanceBetweenPoints2D math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)

^ look at length of both, why mta implementing formula that is 20% longer then function name????

jushar commented 5 years ago

I think exports are too slow for such a function (as they serialize and deserialize input and output data).

Library inclusion in form of require or something similar is probably the better solution. It might even make sense (without having further thought about it) to introduce a new library resource type that works similarly to exports, but actually loads the code into the importing resource rather than the traditional exports approach.

CrosRoad95 commented 5 years ago

require from original lua would be enough, i don't wanna make 10 resources, in each i have other type of functions

you should check lua-package branch

qaisjp commented 5 years ago

I would really prefer enabling the regular require from Lua (i.e the lua-package branch)

ghost commented 5 years ago

Well, let's say that require gets enabled: a server owner could now access your system with os., io. which means that require should be filtered - and even when filtered properly - it wont prevent scripters from using them (renaming etc) which might be a security flaw

Maybe there should be a library folder (1 mta resource / server path) containing all libraries which can be imported in meta.xml using <library name="Math utility" src=":libraries/maths.lua" />

OR we simply add another feature called <import type="server/client/shared" src="*.lua" /> which loads them directly into environment which might be the best solution.

Pirulax commented 5 years ago

just add a little + feature to Githubissues.

  • Githubissues is a development platform for aggregating issues.