Wiki

Clone wiki

EFLC-MP LUA / getVehicleModelId

Description

Gets the vehicle ID using its model name

Parameters

String modelName
String modelName: the model name is always in uppercase. Ex: INFERNUS

Return values

Int modelId

Example

#!lua
function carSpawningChatEvent(playerid, text)
    if(string.sub(text, 1, 2) == "/v") then
        local modelName = string.upper(string.sub(text, 4))
        local modelId = getVehicleModelId(modelName)
        if(modelId == -1) then
            sendPlayerMsg(playerid, "'" .. modelName .. "' is an invalid vehicle name", 0xFFFF0000)
            return
        end
        local x, y, z = getPlayerPos(playerid)
        local rColor = math.random(0, 170)
        local carId = createVehicle(modelId, x, y, z, 0.0, 0.0, 0.0, rColor, rColor, rColor, rColor, getPlayerWorld(playerid))
        sendPlayerMsg(playerid, modelName .. " spawned with id " .. carId .. " with color " .. rColor, 0xFFFFFFFF)          
    end
end
registerEvent("carSpawningChatEvent", "onPlayerChat")

Updated