ixjf Posted June 3, 2013 Share Posted June 3, 2013 Hi, I would appreciate if somebody could answer these two questions: Is there any documentation of the OOP implemented in the 1.4 release (e.g. "class" members signature)? How does a script of type "shared" work? Do we simply mix both server-side and client-side functions? How does it differentiate between the client and server files then? I know you can overload functions in C++, but would it be possible in Lua? Link to comment
qaisjp Posted June 4, 2013 Share Posted June 4, 2013 shared = client, server meaning this: <script src="script.lua" type="shared"/> is practically translated as <script src="script.lua" type="server"/> <script src="script.lua" type="client"/> idk about the oop. Link to comment
ixjf Posted June 4, 2013 Author Share Posted June 4, 2013 (edited) Makes no sense to me to have such a type. How about function documentation? Edited June 5, 2013 by Guest Link to comment
DakiLLa Posted June 4, 2013 Share Posted June 4, 2013 Not sure if developers have ever finished OOP stuff, otherwise they'd document it on the wiki, wouldn't they? Link to comment
Moderators IIYAMA Posted June 4, 2013 Moderators Share Posted June 4, 2013 btw what is the use of that? (I only know that it is handy for exporting) but nothing more or less. Link to comment
50p Posted June 4, 2013 Share Posted June 4, 2013 OOP-wise, they're still working on it. First they want to implement OOP client-side only and then translate it to server-side. There will be useful classes that will make things easier eg. vectors and matrices for position translation. For instance freecam resource can be shrank down from ~200 lines down to ~30 lines of code, that's because of all the calculations being done with math functions; vectors and matrices makes things simple The classes will be self explanatory, eg: Ped, Vehicle, etc. and will work the following way: local myPed = Ped.create( 0, 0.0, 0.0, 3.0 ); -- create a CJ ped at 0,0,3 myPed:position( 100.0, 100.0, 4.0 ); -- set myPed position to 100, 100, 4 local newPos = Vector3D( -104, 140, 15 ); myPed:Position( newPos ); -- set new position by vector local myVeh = Vehicle( 560, 0, 0, 4 ); -- create Sultan at 0, 0, 4 myVeh.health = 500; -- set the vehicle's health to 500 myPed.vehicle = myVeh; -- waprs the myPed to myVeh (waprs CJ to Sultan); localPlayer.skin = 3; -- change local player's skin to 3 There is plenty more to describe about the new OOP but these are just simple examples I can think of. Link to comment
ixjf Posted June 4, 2013 Author Share Posted June 4, 2013 (edited) btw what is the use of that? (I only know that it is handy for exporting)but nothing more or less. The object-oriented paradigm turns complicated things so easy: https://en.wikipedia.org/wiki/Object-or ... rogramming Edited June 5, 2013 by Guest Link to comment
Spajk Posted June 4, 2013 Share Posted June 4, 2013 I am intrestred about the "shared" thing, could anyone explain what it does exactly? Link to comment
qaisjp Posted June 4, 2013 Share Posted June 4, 2013 I am intrestred about the "shared" thing, could anyone explain what it does exactly? shared = client, servermeaning this: <script src="script.lua" type="shared"/> is practically translated as <script src="script.lua" type="server"/> <script src="script.lua" type="client"/> idk about the oop. OOP-wise, they're still working on it. First they want to implement OOP client-side only and then translate it to server-side. There will be useful classes that will make things easier eg. vectors and matrices for position translation. For instance freecam resource can be shrank down from ~200 lines down to ~30 lines of code, that's because of all the calculations being done with math functions; vectors and matrices makes things simpleThe classes will be self explanatory, eg: Ped, Vehicle, etc. and will work the following way: local myPed = Ped.create( 0, 0.0, 0.0, 3.0 ); -- create a CJ ped at 0,0,3 myPed:position( 100.0, 100.0, 4.0 ); -- set myPed position to 100, 100, 4 local newPos = Vector3D( -104, 140, 15 ); myPed:Position( newPos ); -- set new position by vector local myVeh = Vehicle( 560, 0, 0, 4 ); -- create Sultan at 0, 0, 4 myVeh.health = 500; -- set the vehicle's health to 500 myPed.vehicle = myVeh; -- waprs the myPed to myVeh (waprs CJ to Sultan); localPlayer.skin = 3; -- change local player's skin to 3 There is plenty more to describe about the new OOP but these are just simple examples I can think of. With object chaining: local myPed = Ped.create( 0, 0.0, 0.0, 3.0 ):position( 100.0, 100.0, 4.0 ); Link to comment
Spajk Posted June 4, 2013 Share Posted June 4, 2013 I read that, but the script file is same(script.lua), so how does it know if I am calling a client or server function? Link to comment
Cadu12 Posted June 4, 2013 Share Posted June 4, 2013 function isServer() return triggerClientEvent ~= nil end function isClient() return triggerServerEvent ~= nil end function getScriptLocation() return isServer() and "Server" or "Client" end if getScriptLocation() == "Client" then -- here client else -- here server end I got it from Race resource. Link to comment
50p Posted June 5, 2013 Share Posted June 5, 2013 Basically, shared files are used to define functions that can be used on both sides: client and server. For example you may have some math or table functions that work on both sides. eg: function table.equal( t1, t2 ) -- check if 2 tables are the same for i, v in pairs( t1 ) do if t2[ i ] ~= v then return false; end end return true; end This is very simple example, as you can see, this script doesn't use any MTA functions and therefore it can be used on client and server side thus "shared". Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now