Jump to content

I have a problem with custom plates


Mr3b

Recommended Posts

So i am trying to edit a custom plate script to new style but when i use

dxSetShaderValue(tex_plates[vehicle], "platetex", rt)

The plate show small like this 

spacer.png

and when i add

engineApplyShaderToWorldTexture(tex_plates[vehicle], "plateback*")

It show 2 plates the small one and correct one like this 

spacer.png

Full Code:

local color = 0xff111111
local font = dxCreateFont("files/font.ttf", 20, true)
local size = 1.5

local tex_plates = {}
local raw_shader = [[
    texture platetex;
    technique TECHNIQUE_REPLACE {
        pass P0 {
            Texture[0] = platetex;
        }
    }
]]

-- Load the custom image for the license plate
local customPlateTexture = dxCreateTexture("files/plate.png", "dxt5")

local function getPlateShader(vehicle)
    if tex_plates[vehicle] then
        if isElement(tex_plates[vehicle]) then
            destroyElement(tex_plates[vehicle])
        end
        tex_plates[vehicle] = nil
    end

    local rtWidth, rtHeight = 226, 123
    local rt = dxCreateRenderTarget(rtWidth, rtHeight)
    dxSetRenderTarget(rt)
        dxDrawImage(0, 0, rtWidth, rtHeight, customPlateTexture) -- Add the custom plate background image
        dxDrawText("111", 2, 2, 112 + 2, 59 + 2, color, size, font, "center", "center")
        dxDrawText("R3B", 117, 3, 78 + 117, 58 + 3, color, size, font, "center", "center")
        dxDrawText("111", 2, 64, 112 + 2, 59 + 64, color, size, font, "center", "center")
        dxDrawText("R3B", 117, 64, 78 + 117, 58 + 64, color, size, font, "center", "center")
    dxSetRenderTarget()

    tex_plates[vehicle] = dxCreateShader(raw_shader)
    dxSetShaderValue(tex_plates[vehicle], "platetex", rt)
    -- engineApplyShaderToWorldTexture(tex_plates[vehicle], "plateback*")

    return tex_plates[vehicle]
end

local function onStreamIn(vehicle)
    local shader = getPlateShader(vehicle)
    engineApplyShaderToWorldTexture(shader, "custom_car_plate", vehicle)
end

local function onStreamOut(vehicle)
    if tex_plates[vehicle] then
        engineRemoveShaderFromWorldTexture(tex_plates[vehicle], "custom_car_plate", vehicle)
        if isElement(tex_plates[vehicle]) then
            destroyElement(tex_plates[vehicle])
        end
        tex_plates[vehicle] = nil
    end
end

addEventHandler("onClientElementStreamIn", root, function()
    if getElementType(source) == "vehicle" then
        onStreamIn(source)
    end
end)

addEventHandler("onClientElementStreamOut", root, function()
    if getElementType(source) == "vehicle" then
        onStreamOut(source)
    end
end)

addEventHandler("onClientResourceStart", resourceRoot, function()
    local vehicles = getElementsByType("vehicle", root, true)
    for i = 1, #vehicles do
        onStreamIn(vehicles[i])
    end
end)

addEventHandler("onClientRestore", root, function(cleared)
    if cleared then
        for vehicle in pairs(tex_plates) do
            onStreamOut(vehicle)
            onStreamIn(vehicle)
        end
    end
end)
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...