iAxel Posted April 13, 2015 Share Posted April 13, 2015 Hello everyone! I wanted to make a system of clothing with shaders. code: CLIENT local Shader = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped') --- Create shader for player ---Clothes Table local Clothes = { ['cj_ped_torso'] = { ['tshirtwhite'] = { model = nil }, ['tshirtred'] = { model = nil }, ['tshirtblack'] = { model = nil } } } ---Create texture for player for model, clothe in pairs(cClothes['cj_ped_torso']) do clothe.model = dxCreateTexture('files/clothes/'..model..'.png') end ---Appy Texture for player 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) SERVER triggerClientEvent(source, 'addClothes', source, source, 'tshirtblack', 'cj_ped_torso') replace.fx texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } The function works fine but the texture is visible only localPlayer other players see the standard clothing Are there any ideas that it was visible all players? Link to comment
Walid Posted April 13, 2015 Share Posted April 13, 2015 just use this triggerClientEvent(root, 'addClothes',root, source, 'tshirtblack', 'cj_ped_torso') Link to comment
iAxel Posted April 13, 2015 Author Share Posted April 13, 2015 just use this triggerClientEvent(root, 'addClothes',root, source, 'tshirtblack', 'cj_ped_torso') Don't work If use root then the localPlayer and another Player the same texture Link to comment
iAxel Posted April 13, 2015 Author Share Posted April 13, 2015 Please help me community! Link to comment
Ren_712 Posted April 13, 2015 Share Posted April 13, 2015 Please help me community! How about executing the addClothes function onClientResourceStart ? Or at least when the element is streamed in. Link to comment
Walid Posted April 14, 2015 Share Posted April 14, 2015 just use this triggerClientEvent(root, 'addClothes',root, source, 'tshirtblack', 'cj_ped_torso') Don't work If use root then the localPlayer and another Player the same texture You must add something like this in your client side : if player == localPlayer then end Link to comment
iAxel Posted April 14, 2015 Author Share Posted April 14, 2015 You must add something like this in your client side : if player == localPlayer then end In this way? addEvent('addClothes', true) function addClothes(player, clothesTexture, clothesModel) local cType = cClothes[clothesModel] local clothe = cType[clothesTexture] if (player == localPlayer) then if (Shader) then dxSetShaderValue(Shader, 'gTexture', clothe.model) engineApplyShaderToWorldTexture(Shader, clothesModel, player) end end end addEventHandler('addClothes', root, addClothes) Link to comment
iAxel Posted April 14, 2015 Author Share Posted April 14, 2015 Please help me community! How about executing the addClothes function onClientResourceStart ? Or at least when the element is streamed in. Can be an example? Link to comment
Walid Posted April 14, 2015 Share Posted April 14, 2015 You must add something like this in your client side : if player == localPlayer then end In this way? addEvent('addClothes', true) function addClothes(player, clothesTexture, clothesModel) local cType = cClothes[clothesModel] local clothe = cType[clothesTexture] if (player == localPlayer) then if (Shader) then dxSetShaderValue(Shader, 'gTexture', clothe.model) engineApplyShaderToWorldTexture(Shader, clothesModel, player) end end end addEventHandler('addClothes', root, addClothes) yes Link to comment
ALw7sH Posted April 14, 2015 Share Posted April 14, 2015 local Shader = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped') --- Create shader for player ---Clothes Table local cClothes = { ['cj_ped_torso'] = { ['tshirtwhite'] = { model = nil }, ['tshirtred'] = { model = nil }, ['tshirtblack'] = { model = nil } } } ---Create texture for player for model, clothe in pairs(cClothes['cj_ped_torso']) do clothe.model = dxCreateTexture('files/clothes/'..model..'.png') end ---Appy Texture for player addEvent('addClothes', true) function addClothes(player, clothesTexture, clothesModel) local cType = cClothes[clothesModel] local clothe = cType[clothesTexture] local clothes = getElementData(player,"clothes") if type(clothes) == "table" and table.getn(clothes) > 0 then table.insert(clothes,{clothesModel,clothe}) setElementData(player,"clothes",clothes) else local cTable = {} table.insert(cTable,{clothesModel,clothe}) setElementData(player,"clothes",cTable) end end addEventHandler('addClothes', root, addClothes) addEventHandler("onClientElementStreamIn",root, function() if getElementType(source) == "player" then if (Shader) then local clothes = getElementData(source,"clothes") if type(clothes) == "table" and table.getn(clothes) > 0 then for k,v in pairs(clothes) do dxSetShaderValue(Shader, 'gTexture', v[2].model) engineApplyShaderToWorldTexture(Shader, v[1], source) end end end end end ) Link to comment
iAxel Posted April 14, 2015 Author Share Posted April 14, 2015 local Shader = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped') --- Create shader for player ---Clothes Table local cClothes = { ['cj_ped_torso'] = { ['tshirtwhite'] = { model = nil }, ['tshirtred'] = { model = nil }, ['tshirtblack'] = { model = nil } } } ---Create texture for player for model, clothe in pairs(cClothes['cj_ped_torso']) do clothe.model = dxCreateTexture('files/clothes/'..model..'.png') end ---Appy Texture for player addEvent('addClothes', true) function addClothes(player, clothesTexture, clothesModel) local cType = cClothes[clothesModel] local clothe = cType[clothesTexture] local clothes = getElementData(player,"clothes") if type(clothes) == "table" and table.getn(clothes) > 0 then table.insert(clothes,{clothesModel,clothe}) setElementData(player,"clothes",clothes) else local cTable = {} table.insert(cTable,{clothesModel,clothe}) setElementData(player,"clothes",cTable) end end addEventHandler('addClothes', root, addClothes) addEventHandler("onClientElementStreamIn",root, function() if getElementType(source) == "player" then if (Shader) then local clothes = getElementData(source,"clothes") if type(clothes) == "table" and table.getn(clothes) > 0 then for k,v in pairs(clothes) do dxSetShaderValue(Shader, 'gTexture', v[2].model) engineApplyShaderToWorldTexture(Shader, v[1], source) end end end end end ) Don't Work Link to comment
ALw7sH Posted April 14, 2015 Share Posted April 14, 2015 local Shader = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped') --- Create shader for player ---Clothes Table local cClothes = { ['cj_ped_torso'] = { ['tshirtwhite'] = { model = nil }, ['tshirtred'] = { model = nil }, ['tshirtblack'] = { model = nil } } } ---Create texture for player for model, clothe in pairs(cClothes['cj_ped_torso']) do clothe.model = dxCreateTexture('files/clothes/'..model..'.png') end ---Appy Texture for player addEvent('addClothes', true) function addClothes(player, clothesTexture, clothesModel) local cType = cClothes[clothesModel] local clothe = cType[clothesTexture] local clothes = getElementData(player,"clothes") if type(clothes) == "table" and table.getn(clothes) > 0 then table.insert(clothes,{clothesModel,clothe}) setElementData(player,"clothes",clothes) else local cTable = {} table.insert(cTable,{clothesModel,clothe}) setElementData(player,"clothes",cTable) end end addEventHandler('addClothes', root, addClothes) addEventHandler("onClientElementStreamIn",root, function() if getElementType(source) == "player" then if (Shader) then local clothes = getElementData(source,"clothes") if type(clothes) == "table" and table.getn(clothes) > 0 then for k,v in pairs(clothes) do dxSetShaderValue(Shader, 'gTexture', v[2].model) engineApplyShaderToWorldTexture(Shader, v[1], source) end end end end end ) Don't Work What's doesn't works explain more so we can help you Link to comment
iAxel Posted April 14, 2015 Author Share Posted April 14, 2015 What's doesn't works explain more so we can help you In debug no errors or warnings Use a function but nothing happens triggerClientEvent(root, 'addClothes', source, source, 'tshirtblack', 'cj_ped_torso') Perhaps from for it? Server Clothes = { ['cj_ped_torso'] = { {'tshirtwhite'}, {'tshirtgrey'}, {'tshirtbeige'} }, ['cj_ped_legs'] = { {'legsblack'}, {'legsblue'}, {'legsbrown'} } } local s = Clothes['cj_ped_torso'][math.random(1, 3)] local t = Clothes['cj_ped_legs'][math.random(1, 3)] triggerClientEvent(root, 'addClothes', source, source, s[1], 'cj_ped_torso') triggerClientEvent(root, 'addClothes', source, source, t[1], 'cj_ped_legs') Client ---Shaders local Shader = {} Shader[1] = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped')---Shirt Shader[2] = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped')---Leg --Table Clothes = { ['cj_ped_torso'] = { ['tshirtwhite'] = { index = 1, model = nil }, ['tshirtgrey'] = { index = 1, model = nil }, ['tshirtbeige'] = { index = 1, model = nil } }, ['cj_ped_legs'] = { ['legsblack'] = { index = 2, model = nil }, ['legsdblue1'] = { index = 2, model = nil }, ['legsblue'] = { index = 2, model = nil } } } --Loop for model, clothe in pairs(cClothes['cj_ped_torso']) do clothe.model = dxCreateTexture('files/clothes/'..model..'.png') end for model, clothe in pairs(cClothes['cj_ped_legs']) 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] local clothes = getElementData(player, 'clothes') if type(clothes) == 'table' and table.getn(clothes) > 0 then table.insert(clothes, {clothesModel, clothe}) setElementData(player, 'clothes', clothes) else local cTable = {} table.insert(cTable, {clothesModel, clothe}) setElementData(player, 'clothes', cTable) end --[[if (Shader[clothe.index]) then resetClothes(player, clothesModel, clothe.index) dxSetShaderValue(Shader[clothe.index], 'gTexture', clothe.model) engineApplyShaderToWorldTexture(Shader[clothe.index], clothesModel, player) end]] end addEventHandler('addClothes', root, addClothes) addEventHandler('onClientElementStreamIn', root, function () if getElementType(source) == 'player' then local clothes = getElementData(source, 'clothes') if type(clothes) == 'table' and table.getn(clothes) > 0 then for k, v in pairs(clothes) do dxSetShaderValue(Shader[v[2].index], 'gTexture', v[2].model) engineApplyShaderToWorldTexture(Shader[v[2].index], v[1], source) end end end end ) Link to comment
ALw7sH Posted April 14, 2015 Share Posted April 14, 2015 Because there's no erros use outputDebugString to see what's doesn't works ---Shaders local Shader = {} Shader[1] = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped')---Shirt Shader[2] = dxCreateShader('files/shaders/replace.fx', 0, 0, true, 'ped')---Leg --Table Clothes = { ['cj_ped_torso'] = { ['tshirtwhite'] = { index = 1, model = nil }, ['tshirtgrey'] = { index = 1, model = nil }, ['tshirtbeige'] = { index = 1, model = nil } }, ['cj_ped_legs'] = { ['legsblack'] = { index = 2, model = nil }, ['legsdblue1'] = { index = 2, model = nil }, ['legsblue'] = { index = 2, model = nil } } } --Loop for model, clothe in pairs(cClothes['cj_ped_torso']) do clothe.model = dxCreateTexture('files/clothes/'..model..'.png') end for model, clothe in pairs(cClothes['cj_ped_legs']) 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] local clothes = getElementData(player, 'clothes') if type(clothes) == 'table' and table.getn(clothes) > 0 then table.insert(clothes, {clothesModel, clothe}) setElementData(player, 'clothes', clothes) outputDebugString("Cloth element data has been added to"..getPlayerName(player)) else local cTable = {} table.insert(cTable, {clothesModel, clothe}) setElementData(player, 'clothes', cTable) outputDebugString("Cloth element data has been added to"..getPlayerName(player)) end --[[if (Shader[clothe.index]) then resetClothes(player, clothesModel, clothe.index) dxSetShaderValue(Shader[clothe.index], 'gTexture', clothe.model) engineApplyShaderToWorldTexture(Shader[clothe.index], clothesModel, player) end]] end addEventHandler('addClothes', root, addClothes) addEventHandler('onClientElementStreamIn', root, function () if getElementType(source) == 'player' then local clothes = getElementData(source, 'clothes') if type(clothes) == 'table' and table.getn(clothes) > 0 then outputDebugString("Adding cloth to "..getPlayerName(source)) for k, v in pairs(clothes) do dxSetShaderValue(Shader[v[2].index], 'gTexture', v[2].model) engineApplyShaderToWorldTexture(Shader[v[2].index], v[1], source) outputDebugString(v[1].." Has been added to"..getPlayerName(source)) end end end end ) Link to comment
iAxel Posted April 14, 2015 Author Share Posted April 14, 2015 Event 'onClientElementStreamIn' is not work Message is not sent to Debug Maybe due to the fact that the player chooses clothes are not logged in? Link to comment
iAxel Posted April 14, 2015 Author Share Posted April 14, 2015 ALw7sH I do hope for your help I really need this system Link to comment
iAxel Posted April 15, 2015 Author Share Posted April 15, 2015 Please help me community... I really need this system Link to comment
ALw7sH Posted April 15, 2015 Share Posted April 15, 2015 I cant help you before i know what's the problem so work on the code little bit try to find why onClientElementStreamIn is not working for example output the element data because maybe the problem is from the element data addEventHandler('onClientElementStreamIn', root, function () if getElementType(source) == 'player' then local clothes = getElementData(source, 'clothes') outputDebugString("Clothes data is: "..type(clothes).." - and it's: "..tostring(clothes)) if type(clothes) == 'table' and table.getn(clothes) > 0 then outputDebugString("Adding cloth to "..getPlayerName(source)) for k, v in pairs(clothes) do dxSetShaderValue(Shader[v[2].index], 'gTexture', v[2].model) engineApplyShaderToWorldTexture(Shader[v[2].index], v[1], source) outputDebugString(v[1].." Has been added to"..getPlayerName(source)) end end end end ) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now