Tessék, nálam működött lackos888 egyszerűbb megoldása alapján.
Szerver oldal:
addCommandHandler(\'apaintjob\',
function(player, cmd, id)
local vehicle = getPedOccupiedVehicle(player);
if (vehicle) then
setElementData(vehicle, \'tuning.paintjob\', tonumber(id), true);
else
outputChatbox(\'Nem vagy járműben!\');
end
end
)
Kliens oldal:
Paintjob = {};
Paintjob.File = \'Assets/Images/Paintjobs/\';
Paintjob.Format = \'.png\';
Paintjob.Textures = {
-- *vehiclegrunge256*
[562] = {
{\'*#emapelegybody128*\', \'elegy1body256\'},
{\'*#emapelegybody128*\', \'elegy2body256\'},
{\'*#emapelegybody128*\', \'elegy3body256\'}
},
[565] = {
{\'*#emapflash92body256*\', \'flash1body256\'},
{\'*#emapflash92body256*\', \'flash2body256\'}
},
[559] = {
{\'*emapjesterbody256*\', \'jester1body256\'},
{\'*emapjesterbody256*\', \'jester3body256\'},
{\'*emapjesterbody256*\', \'jester2body256\'}
},
[560] = {
{\'*emapsultanbody256*\', \'sultan1body256\'},
{\'*emapsultanbody256*\', \'sultan2body256\'},
{\'*emapsultanbody256*\', \'sultan3body256\'}
},
[558] = {
{\'*emapuranus92body256*\', \'uranus1body256\'},
{\'*emapuranus92body256*\', \'uranus2body256\'},
{\'*emapuranus92body256*\', \'uranus3body256\'}
}
};
Paintjob.VehicleList = {};
Paintjob.VehicleList.Shader = {};
Paintjob.VehicleList.Texture = {};
addEventHandler(\'onClientResourceStart\', resourceRoot,
function()
for k, v in ipairs(getElementsByType(\'vehicle\')) do
local vehiclePaintjob = getElementData(v, \'tuning.paintjob\') or 0;
if (vehiclePaintjob ~= 0) then
setElementData(v, \'tuning.paintjob\', vehiclePaintjob, true);
setVehiclePaintjobTexture(v, vehiclePaintjob);
end
end
end
);
addEventHandler(\'onClientElementDataChange\', getRootElement(),
function(data, oldPaintjob)
if (data == \'tuning.paintjob\') then
local newPaintjob = getElementData(source, \'tuning.paintjob\') or 0;
local vehicleID = getElementModel(source);
if (newPaintjob ~= 0) then
if (Paintjob.Textures[vehicleID][newPaintjob]) then
setVehiclePaintjobTexture(source, newPaintjob);
else
setElementData(source, \'tuning.paintjob\', oldPaintjob, true);
end
else
engineRemoveShaderFromWorldTexture(Paintjob.VehicleList.Shader[source], Paintjob.Textures[vehicleID][oldPaintjob][1], source);
end
end
end
)
addEventHandler(\'onClientElementStreamIn\', getRootElement(),
function()
if (getElementType(source) == \'vehicle\') then
local paintjob = getElementData(source, \'tuning.paintjob\') or 0;
if (paintjob ~= 0) then
setVehiclePaintjobTexture(source, paintjob);
end
end
end
);
addEventHandler(\'onClientElementStreamOut\', getRootElement(),
function()
if (getElementType(source) == \'vehicle\') then
if (Paintjob.VehicleList.Shader[source] and Paintjob.VehicleList.Texture[source]) then
local paintjob = getElementData(source, \'tuning.paintjob\') or 0;
local vehicleID = getElementModel(source);
if (paintjob ~= 0 and vehicleID) then
engineRemoveShaderFromWorldTexture(Paintjob.VehicleList.Shader[source], Paintjob.Textures[vehicleID][paintjob][1], source);
end
end
end
end
);
function setVehiclePaintjobTexture(vehicle, paintjob)
if (vehicle and paintjob) then
local vehicleID = getElementModel(vehicle);
if (vehicleID and Paintjob.Textures[vehicleID][paintjob]) then
Paintjob.VehicleList.Shader[vehicle] = dxCreateShader(\'Assets/Files/Paintjob.fx\', 0, 0, true, \'vehicle\');
Paintjob.VehicleList.Texture[vehicle] = dxCreateTexture(Paintjob.File .. Paintjob.Textures[vehicleID][paintjob][2] .. Paintjob.Format);
if (Paintjob.VehicleList.Shader[vehicle] and Paintjob.VehicleList.Texture[vehicle]) then
dxSetShaderValue(Paintjob.VehicleList.Shader[vehicle], \'gTexture\', Paintjob.VehicleList.Texture[vehicle]);
engineApplyShaderToWorldTexture(Paintjob.VehicleList.Shader[vehicle], Paintjob.Textures[vehicleID][paintjob][1], vehicle);
end
end
end
end
E: Kiegészítettem még pár dologgal.