Sign in to follow this  
Fanbox

[HELP] Synchronization shader player

Recommended Posts

--Client

local shader = dxCreateShader("tex.fx",0, 0, true, 'ped')

addEvent("broadcastEnableShader", true) -- allow remotely triggered (from server)
addEventHandler("broadcastEnableShader", root, 
  function(some_data) -- receive broadcast from the server
        local img = dxCreateTexture(""..math.random(1,3)..".png")
        dxSetShaderValue(shader, "tex", img)
        engineApplyShaderToWorldTexture(shader, "Hoodie_green_co",some_data)
  end
)


addEventHandler( 'onClientResourceStart', resourceRoot,
    function()
            for _, p in ipairs(getElementsByType('ped')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
            for _, p in ipairs(getElementsByType('player')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
    end)

addEventHandler( 'onClientElementStreamIn', root,
    function()
        if getElementType(source) == 'player' or getElementType(source) == 'ped' then
            local clothing = getElementData(source, 'blood')
            if clothing then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)

addEventHandler( 'onClientElementDataChange', root,
    function(name)
        if (getElementType(source) == 'player' or getElementType(source) == 'ped') and isElementStreamedIn(source) and name == 'blood' then
            if getElementData(source, 'blood') then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)


--SERVER

addEvent("announceEnableShader", true) 
addEventHandler("announceEnableShader", root, 
  function (some_data) --
    triggerClientEvent(root, "broadcastEnableShader", source, some_data) 
  end
)


 

Ita not Synchronization((

Share this post


Link to post
--Client

local shader = dxCreateShader("tex.fx",0, 0, true, 'ped')

addEvent("broadcastEnableShader", true) -- allow remotely triggered (from server)
addEventHandler("broadcastEnableShader", root, 
  function(some_data) -- receive broadcast from the server
        local img = dxCreateTexture(""..math.random(1,3)..".png")
        dxSetShaderValue(shader, "tex", img)
        engineApplyShaderToWorldTexture(shader, "Hoodie_green_co",some_data)
  end
)


addEventHandler( 'onClientResourceStart', resourceRoot,
    function()
            for _, p in ipairs(getElementsByType('ped')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
            for _, p in ipairs(getElementsByType('player')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
    end)

addEventHandler( 'onClientElementStreamIn', root,
    function()
        if getElementType(source) == 'player' or getElementType(source) == 'ped' then
            local clothing = getElementData(source, 'blood')
            if clothing then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)

addEventHandler( 'onClientElementDataChange', root,
    function(name)
        if (getElementType(source) == 'player' or getElementType(source) == 'ped') and isElementStreamedIn(source) and name == 'blood' then
            if getElementData(source, 'blood') then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)


--SERVER

addEvent("announceEnableShader", true) 
addEventHandler("announceEnableShader", root, 
  function (some_data) --
	for i,player in ipairs(getElementsByType("player")) do
		triggerClientEvent("broadcastEnableShader", player, some_data) 
	end
  end
)

I didnt test it but i hope it will work.

Share this post


Link to post
2 hours ago, URBAN said:

--Client

local shader = dxCreateShader("tex.fx",0, 0, true, 'ped')

addEvent("broadcastEnableShader", true) -- allow remotely triggered (from server)
addEventHandler("broadcastEnableShader", root, 
  function(some_data) -- receive broadcast from the server
        local img = dxCreateTexture(""..math.random(1,3)..".png")
        dxSetShaderValue(shader, "tex", img)
        engineApplyShaderToWorldTexture(shader, "Hoodie_green_co",some_data)
  end
)


addEventHandler( 'onClientResourceStart', resourceRoot,
    function()
            for _, p in ipairs(getElementsByType('ped')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
            for _, p in ipairs(getElementsByType('player')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
    end)

addEventHandler( 'onClientElementStreamIn', root,
    function()
        if getElementType(source) == 'player' or getElementType(source) == 'ped' then
            local clothing = getElementData(source, 'blood')
            if clothing then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)

addEventHandler( 'onClientElementDataChange', root,
    function(name)
        if (getElementType(source) == 'player' or getElementType(source) == 'ped') and isElementStreamedIn(source) and name == 'blood' then
            if getElementData(source, 'blood') then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)


--SERVER

addEvent("announceEnableShader", true) 
addEventHandler("announceEnableShader", root, 
  function (some_data) --
	for i,player in ipairs(getElementsByType("player")) do
		triggerClientEvent("broadcastEnableShader", player, some_data) 
	end
  end
)

I didnt test it but i hope it will work.

The problem is that I see the texture on me, but I also see it on other players (instead of seeing them)

Share this post


Link to post
18 hours ago, Fanbox said:

It's not synchronization

NOT TESTED.

shader = dxCreateShader("tex.fx",0, 0, true, 'ped')

addEvent("broadcastEnableShader", true) -- allow remotely triggered (from server)
addEventHandler("broadcastEnableShader", root, 
  function(some_data) -- receive broadcast from the server
        img = dxCreateTexture(""..math.random(1,3)..".png")
        dxSetShaderValue(shader, "tex", img)
        engineApplyShaderToWorldTexture(shader, "Hoodie_green_co",thePlayer)
  end
)


addEventHandler( 'onClientResourceStart', resourceRoot,
    function()
            for _, p in ipairs(getElementsByType('ped')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
            for _, p in ipairs(getElementsByType('player')) do
                if isElementStreamedIn(p) then
                    local clothing = getElementData(p, 'blood')
                    if clothing then
                        triggerServerEvent("announceEnableShader", localPlayer, p)
                    end
                end
            end
    end)

addEventHandler( 'onClientElementStreamIn', root,
    function()
        if getElementType(source) == 'player' or getElementType(source) == 'ped' then
            local clothing = getElementData(source, 'blood')
            if clothing then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)

addEventHandler( 'onClientElementDataChange', root,
    function(name)
        if (getElementType(source) == 'player' or getElementType(source) == 'ped') and isElementStreamedIn(source) and name == 'blood' then
            if getElementData(source, 'blood') then
                triggerServerEvent("announceEnableShader", localPlayer, source)
            end
        end
    end)


--SERVER

addEvent("announceEnableShader", true) 
addEventHandler("announceEnableShader", root, 
  function (some_data) --
    triggerClientEvent(root, "broadcastEnableShader", source, some_data) 
  end
)

I think the above code should work, but if it doesn't, try replacing all "localPlayer" with "thePlayer".
If that also doesn't work, replace all the "source" with "thePlayer" also.

Also from my experience, shaders don't effect MTA performance, I'm not sure though.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.