setElementModel | Multi Theft Auto: Wiki Skip to content

setElementModel

Client-side
Server-side
Shared

Pair: getElementModel

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


Sets the model of a given element. This allows you to change the model of a player (or ped), a vehicle or an object.

OOP Syntax Help! I don't understand this!

  • Method:element:setModel(...)
  • Variable: .model

Syntax

bool setElementModel ( element theElement, int model )
Required Arguments
  • theElement: the element you want to change.
  • model: the model ID to set. For players/peds: A GTASA player model (skin) ID. See Character Skins . For vehicles: The vehicle ID of the vehicle being changed. For objects/projectiles/weapons: An int specifying the model id.

Returns

  • bool: value

Returns true if successful, false otherwise.

Code Examples

shared

This example allows players to change their own skin with a command (/skin [ID])

local spam = {}
function setSkin(player, cmd, skin)
if spam[player] and getTickCount() - spam[player] < 4000 then
return outputChatBox("You cannot change skin that often!", player, 255, 0, 0)
end
skin = skin and tonumber(skin)
if getElementModel(player) == skin or isPedDead(player) then
return
end
if skin and skin <= 99999 then -- what do we know about dynamic ped ID range?
setElementModel(player, skin)
spam[player] = getTickCount()
else
outputChatBox("Invalid skin ID!", player, 255, 0, 0)
end
end
addCommandHandler("skin", setSkin)
function cleanUp()
if spam[source] then
spam[source] = nil
end
end
addEventHandler("onPlayerQuit", root, cleanUp)

See Also

Element Functions