OnElementModelChange: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (I think 1.2 is no longer the new version.)
(The code still provides the newModel as argument to the event handler)
Line 5: Line 5:
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int oldModel
int oldModel, int newModel
</syntaxhighlight>  
</syntaxhighlight>  


* '''oldModel:''' The model of the element beforehand.
* '''oldModel:''' The model of the element beforehand.
* '''newModel:''' The new model of the element.


==Source==
==Source==
Line 19: Line 20:
This example sends a message to players when their model changes telling them what the model ID is and was.
This example sends a message to players when their model changes telling them what the model ID is and was.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function informPlayerOnModelChange(oldModel)
function informPlayerOnModelChange(oldModel, newModel)
     if ( getElementType(source) == "player" ) then -- Make sure the element is a player
     if ( getElementType(source) == "player" ) then -- Make sure the element is a player
         outputChatBox("Model ID changing from: "..oldModel.." to: "..getElementModel(source), source, 0, 255, 0) -- Message for player
         outputChatBox("Model ID changing from: "..oldModel.." to: ".. newModel, source, 0, 255, 0) -- Message for player
     end
     end
end
end

Revision as of 12:00, 2 January 2018

This event is triggered when the model of an element is changed using setElementModel.

Parameters

int oldModel, int newModel
  • oldModel: The model of the element beforehand.
  • newModel: The new model of the element.

Source

The source of this event is the element that changed its model

Cancel Effect

This event doesn't support cancellation. Use setElementModel with the old value to reverse.

Example

This example sends a message to players when their model changes telling them what the model ID is and was.

function informPlayerOnModelChange(oldModel, newModel)
    if ( getElementType(source) == "player" ) then -- Make sure the element is a player
        outputChatBox("Model ID changing from: "..oldModel.." to: ".. newModel, source, 0, 255, 0) -- Message for player
    end
end
addEventHandler("onElementModelChange", root, informPlayerOnModelChange) -- Bind the event to every element

See Also

Element events


Event functions