Jump to content

MTA Classes


Recommended Posts

You need to understand first of all the MTA's element tree. Object's, vehicle's, player's, ped's objects are inherited from Element class. If you want to override the setData for all of these classes, you should override in the Element class.

 

Element._setData = setElementData

function Element:setData(name,data)
	self:_setData(name,data)
	outputDebugString("Element Data `"..name.."` changed to `"..tostring(data).."` for the element: "..tostring(self))
end

 

Self element will be the element, what you called before the function. Important thing, that you need to call with ':', like:

localPlayer:setData("source.inheritance",localPlayer)

These classes, which are in the element tree are automaticly declaired by MTA, so you do not need to declair them.

 

But if you want for example an other specific override for just players, you can do it:

Player._setData = setElementData -- Unfortunatelly, if you want it to replace it to the parent class, for a real inheritance, it will cause stack owerflow...

function Player:setData(name,data)
	self:_setData(name,data) -- this will be the original setData function, not the function of the parent class...
	outputDebugString("Element Data `"..name.."` changed to `"..tostring(data).."` for the player: "..self.name)
end

 

https://wiki.multitheftauto.com/wiki/Element

Edited by Awang
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...