Jump to content

dvo shader for peds


Recommended Posts

Im trying to set the shader to peds with setElementData  and an id for the effect

this works but only renders per client 

im trying to make it render the effect for all clients but only apply the effect to yourself and not others with effect active 

 

Spoiler

--[[
    .-.                     .-.
 .--' /                     \ '--.
 '--. \       _______       / .--'
     \ \   .-"       "-.   / /
      \ \ /     [?]     \ / /
       \ /               \ /
        \|   .--. .--.   |/
         | )/   | |   \( |
         |/ \__/   \__/ \|
         /      /^\      \
         \__    '='    __/
           |\         /|
           |\'"VUUUV"'/|
           \ `"""""""` /
            `-._____.-'
              / / \ \
             / /   \ \
            / /     \ \
         ,-' (       ) `-,
         `-'._)     (_.'-`
	   "Scientia potentia est"
		    (C) Itachi
		  Incognito Gaming
]]--

local _VER = "1.0"

local dvo = {}
dvo.shaders = {}

dvo.allowedElementType = {
	["ped"] = true;
}

dvo.texturesWhereApplyIt = {
	-- chasis
	"pedgrunge256"; 
	"map";
	"vicechee86body8bit128";
	"hunterbody8bit256a";
	"@hite";
	
	"body_base";
    "o-f_base";
	":~ass:O";
	"ped";
	"bycobain2";
}

dvo.allowedElementType = {
	["ped"] = true;
}

dvo.texturesWhereApplyIt = {
	-- chasis
	"pedgrunge256"; 
	"map";
	"vicechee86body8bit128";
	"hunterbody8bit256a";
	"@hite";
	
	"body_base";
    "o-f_base";
	":~ass:O";
	"ped";
	"bycobain2";
}

function dvo.onStream()
	if dvo.allowedElementType[getElementType(source)] then
		dvo.load(source)
	end
end
addEventHandler("onClientElementStreamIn", getRootElement(), dvo.onStream)
--addEventHandler("onClientResourceStart", getRootElement(), dvo.onStream)
--addEventHandler("onElementdataChanged", getRootElement(), dvo.onStream)

function dvo.load(ped)
	local controller = localPlayer
	if controller then
		local id = getElementData(controller, "dvo.id")
		local r, g, b = unpack(getElementData(controller, "dvo.color") or {255, 255, 255})
		if id then
			if dvo.shaders[controller] then
				if isElement(dvo.shaders[controller].ped) then
					for index,texture in ipairs(dvo.texturesWhereApplyIt) do
						engineRemoveShaderFromWorldTexture(dvo.shaders[controller].shader, texture, dvo.shaders[controller].ped)
					end
				end
				if isElement(dvo.shaders[controller].shader) then
					destroyElement(dvo.shaders[controller].shader)
				end
			end
			local shaderBody = dxCreateShader("type"..id..".fx", 1, 100, true,"ped")
			dxSetShaderValue(shaderBody, "intensity", 1)
			dxSetShaderValue(shaderBody, "rate", 1)
			dxSetShaderValue(shaderBody, "opacity", 1)
			dxSetShaderValue(shaderBody, "amp", 0.5)
			dxSetShaderValue(shaderBody, "color", r/255, g/255, b/255)
			dxSetShaderValue(shaderBody, "resolution", 1, 1)
			dxSetShaderValue(shaderBody, "surfacePosition", 0.5)
			dxSetShaderValue(shaderBody, "inten", 0.05)
			dxSetShaderValue(shaderBody, "iResolution", 1, 1)
			dxSetShaderValue(shaderBody, "mfw", 0, 1, 0)
			dxSetShaderValue(shaderBody, "mleft", 1, 0, 0)
			dxSetShaderValue(shaderBody, "vehspeed", 0.5)
			for index,texture in ipairs(dvo.texturesWhereApplyIt) do
				engineApplyShaderToWorldTexture(shaderBody, texture,ped)
			end
			dvo.shaders[controller] = {shader=shaderBody; ped=ped}
		end
	end
end

dvo.amp = 4

function dvo.soundAmp(key) -- just for testing, but fun to test
	if key == "mouse_wheel_up" then
		dvo.amp = dvo.amp+1
	elseif key == "mouse_wheel_down" then
		dvo.amp = dvo.amp-1
	end
end
--bindKey("mouse_wheel_up", "down", dvo.soundAmp)
--bindKey("mouse_wheel_down", "down", dvo.soundAmp)

dvo.beat = true

function dvo.animatedDVO()
	if dvo.beat then
		if isElement(dvo.song) then
			if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].shader) then
				local soundFFT = getSoundFFTData(dvo.song, 8192, 3)
				if soundFFT then
					local value = soundFFT[1]*dvo.amp
					--dxDrawText("Amplitud: "..dvo.amp, 20, 400)	-- just for testing
					dxSetShaderValue(dvo.shaders[localPlayer].shader, "intensity", value)
				end
			end
		else
			if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].shader) then
				dxSetShaderValue(dvo.shaders[localPlayer].shader, "intensity", 1)
			end
		end
	end
end
addEventHandler("onClientRender", root, dvo.animatedDVO)

function dvo.onClientSoundStarted(reason)
	if eventName == "onClientSoundStarted" then
		if isElement(source) and reason == "play" and getSoundLength(source) > 60 then -- check if sound is longer than 60 seconds so we can count it as a song
			dvo.song = source
		end	
	elseif eventName == "onClientSoundStream" then
		if reason then -- in onClientSoundStream event, first argument parsed is if the streaming was successful
			dvo.song = source
		end
	end
end
addEventHandler("onClientSoundStarted", root, dvo.onClientSoundStarted)

function dvo.onClientSoundStopped()
	if dvo.song == source then
		dvo.song = nil
	end
end
addEventHandler("onClientSoundStopped", root, dvo.onClientSoundStopped)

function dvo.toggleBeat()
	if dvo.beat then
		dvo.beat = false
		if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].shader) then
			dxSetShaderValue(dvo.shaders[localPlayer].shader, "intensity", 1)
		end
		outputChatBox("#eeeeee[DVO] #eeeeeeSound animation #ee0000DISABLED",255,255,255,true)
	else
		dvo.beat = true
		outputChatBox("#eeeeee[DVO] #eeeeeeSound animation #00ee00ENABLED",255,255,255,true)
	end
end
addCommandHandler("dvobeat", dvo.toggleBeat)

function dvo.command(cmd, id)
	local id = tonumber(id)
	if id and id > 0 and id < 32 then
		setElementData(localPlayer, "dvo.id", id)
		outputChatBox("#eeeeee[DVO] #eeeeeeID set to: "..id,255,255,255,true)
		local ped = localPlayer
		dvo.manageDVO("save", id)
		if ped then
			dvo.load(ped)
		end
	end
end
addCommandHandler("dvoid", dvo.command)

function dvo.color(cmd, r, g, b)
	local r, g, b = (r and tonumber(r) or 255), (g and tonumber(g) or 255), (b and tonumber(b) or 255)
	setElementData(localPlayer, "dvo.color", {r, g, b})
	if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].ped) and isElement(dvo.shaders[localPlayer].shader) then
		dxSetShaderValue(dvo.shaders[localPlayer].shader, "color", r/255, g/255, b/255)
	end
	outputChatBox("#eeeeee[DVO] #eeeeeeNew color: "..r..", "..g.." "..b,255,255,255,true)
end
addCommandHandler("dvocolor", dvo.color)

function dvo.manageDVO(handler, id)
	local path = "id.dat"
	local exists = fileExists(path)
	if handler == "load" then
		if exists then
			local file = fileOpen(path, true)
			local content = fileRead(file, fileGetSize(file))
			fileClose(file)
			return tonumber(content)
		else
			return false
		end
	elseif handler == "save" and id then
		local file = fileCreate("id.dat")
		fileWrite(file, tostring(id))
		fileClose(file)
	end
end

function dvo.remove(cmd)
	local id = getElementData(localPlayer, "dvo.id")
	if id then
		setElementData(localPlayer, "dvo.id", false)
		dvo.manageDVO("delete")
		if isElement(dvo.shaders[localPlayer].shader) then		
			if isElement(dvo.shaders[localPlayer].ped) then
				for index,texture in ipairs(dvo.texturesWhereApplyIt) do
					engineRemoveShaderFromWorldTexture(dvo.shaders[localPlayer].shader, texture, dvo.shaders[localPlayer].ped)
				end
			end
			destroyElement(dvo.shaders[localPlayer].shader)
		end
	end
end
addCommandHandler("dvoremove", dvo.remove)

 

 

Link to comment
22 minutes ago, Tekken said:

So you are trying to apply this only to PEDS and not PLAYERS, I'm I right ? And this is only working for you? And not for other clients?

im tryin to make it show on player's skin via texture name

this is working, but its only client side others cant see unless they type /dvoid #number ect

originally this script was for vehicles. When the player entered the vehicle it would update the clients to show their effect number on their car and other clients would see the effect and still see their own effect as well. 

basically i just want it to update all clients that whoever typed the cmd updated their effect and all clients will see. been trying to avoid doing server side because the script did not use server side scripting working just fine 

ill post the original if you want to see what it did before i screwed with it lol
 

Spoiler

--[[
    .-.                     .-.
 .--' /                     \ '--.
 '--. \       _______       / .--'
     \ \   .-"       "-.   / /
      \ \ /     [?]     \ / /
       \ /               \ /
        \|   .--. .--.   |/
         | )/   | |   \( |
         |/ \__/   \__/ \|
         /      /^\      \
         \__    '='    __/
           |\         /|
           |\'"VUUUV"'/|
           \ `"""""""` /
            `-._____.-'
              / / \ \
             / /   \ \
            / /     \ \
         ,-' (       ) `-,
         `-'._)     (_.'-`
	   "Scientia potentia est"
		    (C) Itachi
		  Incognito Gaming
]]--

local _VER = "1.0"

local dvo = {}
dvo.shaders = {}

dvo.allowedElementType = {
	["vehicle"] = true;
}

dvo.texturesWhereApplyIt = {
	-- chasis
	"vehiclegrunge256"; 
	"map";
	"vicechee86body8bit128";
	"hunterbody8bit256a";
	"@hite";
}

function dvo.onStream()
	if dvo.allowedElementType[getElementType(source)] then
		dvo.load(source)
	end
end
addEventHandler("onClientElementStreamIn", getRootElement(), dvo.onStream)
addEventHandler("onClientVehicleEnter", getRootElement(), dvo.onStream)

function dvo.load(vehicle)
	local controller = getVehicleController(vehicle)
	if controller then
		local id = getElementData(controller, "dvo.id")
		local r, g, b = unpack(getElementData(controller, "dvo.color") or {255, 255, 255})
		if id then
			if dvo.shaders[controller] then
				if isElement(dvo.shaders[controller].vehicle) then
					for index,texture in ipairs(dvo.texturesWhereApplyIt) do
						engineRemoveShaderFromWorldTexture(dvo.shaders[controller].shader, texture, dvo.shaders[controller].vehicle)
					end
				end
				if isElement(dvo.shaders[controller].shader) then
					destroyElement(dvo.shaders[controller].shader)
				end
			end
			local shaderBody = dxCreateShader("type"..id..".fx", 1, 100, true)
			dxSetShaderValue(shaderBody, "intensity", 1)
			dxSetShaderValue(shaderBody, "rate", 1)
			dxSetShaderValue(shaderBody, "opacity", 1)
			dxSetShaderValue(shaderBody, "amp", 0.5)
			dxSetShaderValue(shaderBody, "color", r/255, g/255, b/255)
			dxSetShaderValue(shaderBody, "resolution", 1, 1)
			dxSetShaderValue(shaderBody, "surfacePosition", 0.5)
			dxSetShaderValue(shaderBody, "inten", 0.05)
			dxSetShaderValue(shaderBody, "iResolution", 1, 1)
			dxSetShaderValue(shaderBody, "mfw", 0, 1, 0)
			dxSetShaderValue(shaderBody, "mleft", 1, 0, 0)
			dxSetShaderValue(shaderBody, "vehspeed", 0.5)
			for index,texture in ipairs(dvo.texturesWhereApplyIt) do
				engineApplyShaderToWorldTexture(shaderBody, texture, vehicle)
			end
			dvo.shaders[controller] = {shader=shaderBody; vehicle=vehicle}
		end
	end
end

dvo.amp = 4

function dvo.soundAmp(key) -- just for testing, but fun to test
	if key == "mouse_wheel_up" then
		dvo.amp = dvo.amp+1
	elseif key == "mouse_wheel_down" then
		dvo.amp = dvo.amp-1
	end
end
--bindKey("mouse_wheel_up", "down", dvo.soundAmp)
--bindKey("mouse_wheel_down", "down", dvo.soundAmp)

dvo.beat = true

function dvo.animatedDVO()
	if dvo.beat then
		local vehicle = getPedOccupiedVehicle(localPlayer)
		if isElement(dvo.song) then
			if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].shader) then
				local soundFFT = getSoundFFTData(dvo.song, 8192, 3)
				if soundFFT then
					local value = soundFFT[1]*dvo.amp
					--dxDrawText("Amplitud: "..dvo.amp, 20, 400)	-- just for testing
					dxSetShaderValue(dvo.shaders[localPlayer].shader, "intensity", value)
				end
			end
		else
			if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].shader) then
				dxSetShaderValue(dvo.shaders[localPlayer].shader, "intensity", 1)
			end
		end
	end
end
addEventHandler("onClientRender", root, dvo.animatedDVO)

function dvo.onClientSoundStarted(reason)
	if eventName == "onClientSoundStarted" then
		if isElement(source) and reason == "play" and getSoundLength(source) > 60 then -- check if sound is longer than 60 seconds so we can count it as a song
			dvo.song = source
		end	
	elseif eventName == "onClientSoundStream" then
		if reason then -- in onClientSoundStream event, first argument parsed is if the streaming was successful
			dvo.song = source
		end
	end
end
addEventHandler("onClientSoundStarted", root, dvo.onClientSoundStarted)

function dvo.onClientSoundStopped()
	if dvo.song == source then
		dvo.song = nil
	end
end
addEventHandler("onClientSoundStopped", root, dvo.onClientSoundStopped)

function dvo.toggleBeat()
	if dvo.beat then
		dvo.beat = false
		if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].shader) then
			dxSetShaderValue(dvo.shaders[localPlayer].shader, "intensity", 1)
		end
		outputChatBox("#eeeeee[DVO] #eeeeeeSound animation #ee0000DISABLED",255,255,255,true)
	else
		dvo.beat = true
		outputChatBox("#eeeeee[DVO] #eeeeeeSound animation #00ee00ENABLED",255,255,255,true)
	end
end
addCommandHandler("dvobeat", dvo.toggleBeat)

function dvo.command(cmd, id)
	local id = tonumber(id)
	if id and id > 0 and id < 32 then
		setElementData(localPlayer, "dvo.id", id)
		outputChatBox("#eeeeee[DVO] #eeeeeeID set to: "..id,255,255,255,true)
		local vehicle = getPedOccupiedVehicle(localPlayer)
		dvo.manageDVO("save", id)
		if vehicle then
			dvo.load(vehicle)
		end
	end
end
addCommandHandler("dvoid", dvo.command)

function dvo.color(cmd, r, g, b)
	local r, g, b = (r and tonumber(r) or 255), (g and tonumber(g) or 255), (b and tonumber(b) or 255)
	setElementData(localPlayer, "dvo.color", {r, g, b})
	if dvo.shaders[localPlayer] and isElement(dvo.shaders[localPlayer].vehicle) and isElement(dvo.shaders[localPlayer].shader) then
		dxSetShaderValue(dvo.shaders[localPlayer].shader, "color", r/255, g/255, b/255)
	end
	outputChatBox("#eeeeee[DVO] #eeeeeeNew color: "..r..", "..g.." "..b,255,255,255,true)
end
addCommandHandler("dvocolor", dvo.color)

function dvo.manageDVO(handler, id)
	local path = "id.dat"
	local exists = fileExists(path)
	if handler == "load" then
		if exists then
			local file = fileOpen(path, true)
			local content = fileRead(file, fileGetSize(file))
			fileClose(file)
			return tonumber(content)
		else
			return false
		end
	elseif handler == "save" and id then
		local file = fileCreate("id.dat")
		fileWrite(file, tostring(id))
		fileClose(file)
	end
end

function dvo.remove(cmd)
	local id = getElementData(localPlayer, "dvo.id")
	if id then
		setElementData(localPlayer, "dvo.id", false)
		dvo.manageDVO("delete")
		if isElement(dvo.shaders[localPlayer].shader) then		
			if isElement(dvo.shaders[localPlayer].vehicle) then
				for index,texture in ipairs(dvo.texturesWhereApplyIt) do
					engineRemoveShaderFromWorldTexture(dvo.shaders[localPlayer].shader, texture, dvo.shaders[localPlayer].vehicle)
				end
			end
			destroyElement(dvo.shaders[localPlayer].shader)
		end
	end
end
addCommandHandler("dvoremove", dvo.remove)

 

 

Edited by greentumbleweed
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...