Jump to content

I am new to Mtasa scripting.


scolen

Recommended Posts

"Root" is the main script file of a resource that can access everything in MTA it has access to all functions and resources it can create and manipulate elements such as vehicles players and objects and "Source" is the specific element that triggered an event
when a player joins a server, "Source" refers to that player. When the resource starts, "Root" refers to the main script file.

--this is the root element
function onstart()
    outputChatBox("Resource started!", root, 255, 255, 0)
end
addEventHandler("onResourceStart", resourceRoot, onstart)

--this is an event handler that uses source
function playerjoin()
    outputChatBox(getPlayerName(source).." has joined the server!", root, 0, 255, 0)
end
addEventHandler("onPlayerJoin", root, playerjoin)

lets say in the code above the "onstart" function is executed when the resource is started, and it uses root to refer to the root element of the resource and the "playerjoin" function is executed whenever a player joins the server and it uses the source keyword to refer to the player who triggered the event, take a look in here that might help ya https://wiki.multitheftauto.com/wiki/Event_Source_Element

Edited by FLUSHBICEPS
Link to comment
20 hours ago, FLUSHBICEPS said:

"Root" is the main script file of a resource that can access everything in MTA it has access to all functions and resources it can create and manipulate elements such as vehicles players and objects

What nonsense is that? Root is an element sui generis that represents the top of the element tree, that is, all elements descend from it. Most, if not all, functions are recursive down the element tree (except where propagation is disabled), so setVehicleColor(root, ...) would, while returning false (because the function makes no sense on its principal element, root), set the color of every vehicle that descends from it, or in other words, every vehicle in the world. Then there's resource root, from which all elements spawned by one resource descend. These elements can be recalled with getRootElement and getResourceRootElement (and the pre-defined variables root and resourceRoot). You can read more about this on the MTA wiki page for the Element tree.

Source is the element on which an event is triggered, an element that is the source of that event. Typically this will be the subject of the event name, for example, in the event onPlayerEnterVehicle, the player is the grammatical subject, and is therefore the source of the event. In an event handler -- that is, the function that is called when the event triggers (registered with addEventHandler) -- MTA defines a local variable called source that references said element. For example, in onPlayerEnterVehicle, the source variable references the player element of the player that entered a vehicle. The vehicle's element will be in the event handler's parameters. To look up what the source of an event is, and the parameters of each event, look up the wiki page for that event.

Edited by Addlibs
  • Like 1
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...