Jump to content

Texture problem


-Doc-

Recommended Posts

Hi i got this script from community and added team name in tables, so who has the team will be able to put the texture but i want to make to replace automatically by getting team name texture not by command.

Client

local paintjobVehicles = {}; 
  
addEventHandler('onClientResourceStart', resourceRoot, 
    function() 
        for index, value in ipairs(getElementsByType('vehicle', root, true)) do 
            local paintjobID = getElementData(value, 'tuning.paintjob') or 0; 
             
            if (paintjobID == 0) then 
                return; 
            end 
             
            triggerServerEvent('applyPaintjob', localPlayer, value, paintjobID); 
        end 
    end 
); 
  
addEventHandler('onClientElementStreamIn', root, 
    function() 
        if (getElementType(source) == 'vehicle') then 
            local paintjobID = getElementData(source, 'tuning.paintjob') or 0; 
            local teamName = getTeamName(source) 
            if (paintjobID == 0) then 
                return; 
            end 
             
            local modelID = getElementModel(source); 
             
            if (availablePaintjobs[modelID]) then 
                if (availablePaintjobs[modelID][paintjobID][teamName]) then 
                    applyPaintjob(source, {availablePaintjobs[modelID][paintjobID][teamName][2], availablePaintjobs[modelID][paintjobID][1]}); 
                end 
            end 
        end 
    end 
); 
  
addEventHandler('onClientElementStreamOut', root, 
    function() 
        if (getElementType(source) == 'vehicle') then 
            local paintjobID = getElementData(source, 'tuning.paintjob') or 0; 
             
            if (paintjobID == 0) then 
                return; 
            end 
             
            local modelID = getElementModel(source); 
             
            if (availablePaintjobs[modelID]) then 
                if (availablePaintjobs[modelID][paintjobID]) then 
                    removePaintjob(source, availablePaintjobs[modelID][paintjobID][1]); 
                end 
            end 
        end 
    end 
); 
  
addEvent('applyPaintjob', true); 
function applyPaintjob(element, data) 
    paintjobVehicles[element] = dxCreateShader('paintjobs/paintjob.fx', 0, 0, false, 'vehicle'); 
    local textureElement = dxCreateTexture('paintjobs/' .. data[1]); 
  
    if (paintjobVehicles[element] and textureElement) then 
        dxSetShaderValue(paintjobVehicles[element], 'paintjobTexture', textureElement); 
        engineApplyShaderToWorldTexture(paintjobVehicles[element], data[2], element); 
    end 
end 
addEventHandler('applyPaintjob', root, applyPaintjob); 
  
addEvent('removePaintjob', true); 
function removePaintjob(element, textureElement) 
    if (paintjobVehicles[element]) then 
        engineRemoveShaderFromWorldTexture(paintjobVehicles[element], textureElement, element); 
    end 
end 
addEventHandler('removePaintjob', root, removePaintjob); 

Another client

  
  
availablePaintjobs = { 
    [520] = {  
        {'*hydrabody256*', 'textures/1.png','Atlantas'}, 
        {'*hydrabody256*', 'textures/2.png','Black Ops'}, 
        {'*hydrabody256*', 'textures/3.png','Patriots'} 
    } 
}; 

Server

  
local paintjobVehicles = {}; 
  
addEvent('applyPaintjob', true); 
function applyPaintjob(vehicle, paintjobID) 
    if (vehicle and paintjobID) then 
        local modelID = getElementModel(vehicle); 
         
        if (availablePaintjobs[modelID][paintjobID]) then 
            if (paintjobVehicles[vehicle]) then 
                return; 
            end 
             
            triggerClientEvent(root, 'applyPaintjob', root, vehicle, {availablePaintjobs[modelID][paintjobID][2], availablePaintjobs[modelID][paintjobID][1]}); 
            paintjobVehicles[vehicle] = vehicle; 
            setElementData(vehicle, 'tuning.paintjob', paintjobID, true); 
        end 
    end 
end 
addEventHandler('applyPaintjob', root, applyPaintjob); 
  
addCommandHandler('addtexture', 
    function(player, cmd, id) 
        local vehicle = getPedOccupiedVehicle(player); 
        local modelID = getElementModel(vehicle); 
         
        if (vehicle) then 
            if (availablePaintjobs[modelID][tonumber(id)]) then 
                if (paintjobVehicles[vehicle]) then 
                    return; 
                end 
                 
                triggerClientEvent(root, 'applyPaintjob', root, vehicle, {availablePaintjobs[modelID][tonumber(id)][2], availablePaintjobs[modelID][tonumber(id)][1]}); 
                paintjobVehicles[vehicle] = vehicle; 
                setElementData(vehicle, 'tuning.paintjob', tonumber(id), true); 
            end 
        end 
    end 
); 
  
addCommandHandler('deltexture', 
    function(player, cmd) 
        local vehicle = getPedOccupiedVehicle(player); 
        local modelID = getElementModel(vehicle); 
         
        if (vehicle) then 
            if (paintjobVehicles[vehicle]) then 
                local vehiclePaintjob = getElementData(vehicle, 'tuning.paintjob') or 0; 
             
                if (vehiclePaintjob ~= 0) then 
                    triggerClientEvent(root, 'removePaintjob', root, vehicle, availablePaintjobs[modelID][vehiclePaintjob][1]); 
                    paintjobVehicles[vehicle] = nil; 
                    setElementData(vehicle, 'tuning.paintjob', 0, true); 
                end 
            end 
        end 
    end 
); 
  
addCommandHandler('getpaintjob', 
    function(player, cmd) 
        local vehicle = getPedOccupiedVehicle(player); 
         
        if (vehicle) then 
            local vehiclePaintjob = getElementData(vehicle, 'tuning.paintjob') or 0; 
                 
            outputChatBox('Vehicle paintjob ID: ' .. vehiclePaintjob, player, 255, 100, 100, true); 
        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...