GetElementModel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Edited language change)
 
(10 intermediate revisions by 8 users not shown)
Line 2: Line 2:
{{Server client function}}
{{Server client function}}


Returns the model ID of a given element. This can be a player/ped skin, an object model or a vehicle model.
Returns the model ID of a given element. This can be a player/ped skin, a pickup model, an object model or a vehicle model.


==Syntax==
==Syntax==
Line 8: Line 8:
int getElementModel ( element theElement )
int getElementModel ( element theElement )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[element]]:getModel|model|setElementModel}}


===Required Arguments===
===Required Arguments===
Line 14: Line 15:
===Returns===
===Returns===
Returns the model ID if successful, ''false'' otherwise.
Returns the model ID if successful, ''false'' otherwise.
* For players/peds: A GTASA player model (skin) ID. See [[Character Skins]].
* For vehicles: The [[Vehicle IDs|vehicle ID]] of the vehicle.
* For objects: An [[int]] specifying the model id.
==Example==
<section class="server" name="Example 1 (Server)" show="true">
This example destroys a haystack when a player targets it.''' It only works with elements created by MTA. '''
<syntaxhighlight lang="lua">
addEventHandler ("onPlayerTarget", root,
    function(targetElem)
        if (isElement(targetElem)) and (getElementType(targetElem)=="object") and (getElementModel(targetElem)==3374) then
            destroyElement (targetElem)
        end
    end
)
</syntaxhighlight>
</section>
<section class="server" name="Example 2 (Server)" show="true">
This example prints out a message when a Shamal or AT-400 is entered by a player.
<syntaxhighlight lang="lua">
function planeEnter ( theVehicle, seat, jacked ) -- when someone enters a vehicle
    local id = getElementModel ( theVehicle ) -- get the model ID of the vehicle
    if id == 519 or id == 577 then -- if theVehicle is either Shamal or AT-400
        local vehicleName = getVehicleName ( theVehicle ) -- get the name of theVehicle
        outputChatBox ( "Someone stole a " .. vehicleName .. "!" ) -- announce that someone stole the plane
    end
end
-- add the event handler to the event
addEventHandler ( "onPlayerVehicleEnter", root, planeEnter )
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Element functions}}
{{Element functions}}
[[ru:getElementModel]]

Latest revision as of 17:34, 6 June 2022

Returns the model ID of a given element. This can be a player/ped skin, a pickup model, an object model or a vehicle model.

Syntax

int getElementModel ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:getModel(...)
Variable: .model
Counterpart: setElementModel


Required Arguments

  • theElement: the element to retrieve the model ID of.

Returns

Returns the model ID if successful, false otherwise.

  • For players/peds: A GTASA player model (skin) ID. See Character Skins.
  • For vehicles: The vehicle ID of the vehicle.
  • For objects: An int specifying the model id.

Example

Click to collapse [-]
Example 1 (Server)

This example destroys a haystack when a player targets it. It only works with elements created by MTA.


addEventHandler ("onPlayerTarget", root, 
    function(targetElem)
        if (isElement(targetElem)) and (getElementType(targetElem)=="object") and (getElementModel(targetElem)==3374) then
            destroyElement (targetElem)
        end
    end
)
Click to collapse [-]
Example 2 (Server)

This example prints out a message when a Shamal or AT-400 is entered by a player.

function planeEnter ( theVehicle, seat, jacked ) -- when someone enters a vehicle
    local id = getElementModel ( theVehicle ) -- get the model ID of the vehicle
    if id == 519 or id == 577 then -- if theVehicle is either Shamal or AT-400
        local vehicleName = getVehicleName ( theVehicle ) -- get the name of theVehicle
        outputChatBox ( "Someone stole a " .. vehicleName .. "!" ) -- announce that someone stole the plane
    end
end
-- add the event handler to the event
addEventHandler ( "onPlayerVehicleEnter", root, planeEnter )

See Also