OOP: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Added tuts)
m (Added some more links)
Line 61: Line 61:
* Document all the existing functions in OOP form on the documentation
* Document all the existing functions in OOP form on the documentation


== Useful tutorials ==
== Useful Links ==
This list may not contain all the OOP related tutorials, for a full list, check [[Tutorials]].
* '''[[OOP Introduction]]''' - teaches you about the basics of OOP
* '''[[OOP Introduction]]''' - teaches you about the basics of OOP
* '''[https://code.google.com/p/mtasa-blue/source/browse/trunk/MTA10/mods/shared_logic/lua/CLuaMain.cpp#126 Function list (client)]''' - the most up to date list of functions, you should be able to infer from this.
* '''[https://code.google.com/p/mtasa-blue/source/browse/trunk/MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp#166 Function list (server)]''' - the most up to date list of functions, you should be able to infer from this.

Revision as of 01:35, 26 June 2014

Object Orientated Programming is introduced in MTA:SA 1.4 and comes with special utility classes like Vector and Matrix. This page contains general information about the OOP functions and provides useful links.

Turning it on

You must set the <oop> key in the server configuration file from false to true to enable OOP in your server. However, Vectors and Matrices will always work regardless of OOP being enabled.

Vectors and Matrices

Vectors and Matrices make it easier to drop the complex maths and go straight ahead with fun part of maths. As mentioned above, OOP does not have to be enabled in the server config for this to be enabled.

OOP Metatable Structure

You will undersand this if you're an advanced scripter with an understanding in metatables.

-- Exposed to global environment
Element = {
    create = createElement,
    setPosition = setElementPosition,
    ...
}

Vehicle = {
    create = createVehicle,
    setColor = setVehicleColor,
    ...
}

-- Hidden in lua registry, applied to userdata
ElementMT = {
    __index = CLuaClassDefs::Index,
    __newindex = CLuaClassDefs::NewIndex,
    __class = Element,
    __call = __class.create,
    __set = {
        type = CLuaClassDefs::ReadOnly,
        health = setElementHealth,
        ...
    },
    __get = {
        type = getElementType,
        health = getElementHealth,
        ...
    },
}

VehicleMT = {
    __index = CLuaClassDefs::Index,
    __newindex = CLuaClassDefs::NewIndex,
    __class = Vehicle,
    __parent = ElementMT,
    __call = __class.create,
    __set = {
        damageProof = setVehicleDamageProof
        ...
    },
    __get = {
        damageProof = isVehicleDamageProof
        ...
    },
}

Things to do

  • Document all the existing functions in OOP form on the documentation

Useful Links