Jump to content

CJ Одежда - Shader


Recommended Posts

Всем привет!

Я хотел сделать систему одежд с помощи шейдеров.

Т.е одев футболку

addPedClothes(source, 'tshirtwhite', 'tshirt', 0) 

, я хотел чтобы менялась только текстура футболки.

Клиент

  
local Shader = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped') --- Создаем шейдер для игрока 
---Таблица одежды 
local Clothes = { 
    ['cj_ped_torso'] = { 
        ['tshirtwhite'] = {---белая текстура 
            model = nil 
        }, 
        ['tshirtred'] = {---красная текстура 
            model = nil 
        }, 
        ['tshirtblack'] = {---черная текстура 
            model = nil 
        } 
    } 
} 
  
---Создаем текстуры 
for model, clothe in pairs(cClothes['cj_ped_torso']) do 
    clothe.model = dxCreateTexture('files/clothes/'..model..'.png') 
end 
  
---Применяем текстуры на одежду 
addEvent('addClothes', true) 
function addClothes(player, clothesTexture, clothesModel) 
    local cType = cClothes[clothesModel] 
    local clothe = cType[clothesTexture] 
    if (Shader) then 
        dxSetShaderValue(Shader, 'gTexture', clothe.model) 
        engineApplyShaderToWorldTexture(Shader, clothesModel, player) 
    end 
end 
addEventHandler('addClothes', root, addClothes) 
  

Сервер

  
triggerClientEvent(source, 'addClothes', source, source, 'tshirtblack', 'cj_ped_torso') 
  

Шейдер

  
texture gTexture; 
technique TexReplace 
{ 
    pass P0 
    { 
        Texture[0] = gTexture; 
    } 
} 
  

Функция работает, но дело в том что текстура видна только локальному игроку, другим игрокам как стандартная одежда.

Можно ли сделать чтобы было видно всем?

Link to comment

Функция вызывается только одним игроком, поэтому только он и видит текстуру.

triggerClientEvent(getRootElement(), 'addClothes', getRootElement(),  source, 'tshirtblack', 'cj_ped_torso') 

Link to comment
Функция вызывается только одним игроком, поэтому только он и видит текстуру.
triggerClientEvent(getRootElement(), 'addClothes', getRootElement(),  source, 'tshirtblack', 'cj_ped_torso') 

Так тоже пробовал не помогло

Link to comment

Так вы не учитываете что игроки могут быть за стриммером или вообще не быть на сервере. Лучше используйте ElementData (проще) для этих целей + событие входа в стриммер и событие изменения ElementData.

Псевдокод:

-- Server 
function SetPedClothes( ped, clothesTexture, clothesModel, clothesType ) 
    local data =  
    { 
        ClothesTexture  = clothesTexture; 
        ClothesModel    = clothesModel; 
        ClothesType     = clothesType; 
    }; 
  
    setElementData( ped, "clothes", data ); 
  
    return addPedClothes( ped, clothesTexture, clothesModel, clothesType ); 
end 
  
-- Client 
  
function OnClientElementDataChange( dataName, oldValue ) 
    if getElementType( source ) == "player" and dataName == "clothes" then 
        local value = getElementData( source ); 
  
        if not value then 
            engineRemoveShaderFromWorldTexture( source.ClothesShader, value.ClothesModel, source ); 
  
            source.ClothesShader.Destroy(); 
  
            return; 
        end 
  
        if source.ClothesShader then 
            source.ClothesShader.Destroy(); 
  
            source.ClothesShader = null; 
        end 
  
        -- для каждого педа нужен свой шейдер, так как шейдер имеет свои значения под конкретного игрока! 
        -- сам шейдер конечно же нужно где-то хранить. 
        -- source.ClothesShader - это для примера. У себя реализуйте по своему. 
        source.ClothesShader = dxCreateShader( "files/shaders/replace.fx", 0, 0, true, 'ped' ); 
  
  
        -- Где-то и текстуру храните (какой-то конфиг в виде глобального массива или что там увас) 
        dxSetShaderValue( source.ClothesShader, "gTexture", ?.Texture ); 
  
        engineApplyShaderToWorldTexture( source.ClothesShader, clothesModel, source ); 
    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...