Jump to content

AddPedClothes with custom texture?


DanHR

Recommended Posts

Maybe should use shader?

local shader = dxCreateShader("shader.fx", 0, 0, true, "ped")
local texture = dxCreateTexture("texture.png")

addEventHandler("onClientResourceStart", resourceRoot,
function()
    engineApplyShaderToWorldTexture(shader, "cj_ped_torso") 
    dxSetShaderValue(shader, "Tex0", texture)
end)
  • shader.fx
Spoiler

//-- Declare the texture. These are set using dxSetShaderValue( shader, "Tex0", texture )
texture Tex0;

technique simple
{
    pass P0
    {
        Texture[0] = Tex0;
    }
}

 

 

Edited by Geteco
  • Thanks 1
Link to comment
14 hours ago, Geteco said:

Maybe should use shader?


local shader = dxCreateShader("shader.fx", 0, 0, true, "ped")
local texture = dxCreateTexture("texture.png")

addEventHandler("onClientResourceStart", resourceRoot,
function()
    engineApplyShaderToWorldTexture(shader, "cj_ped_torso") 
    dxSetShaderValue(shader, "Tex0", texture)
end)
  • shader.fx
  Reveal hidden contents


 
//-- Declare the texture. These are set using dxSetShaderValue( shader, "Tex0", texture )
texture Tex0;

technique simple
{
    pass P0
    {
        Texture[0] = Tex0;
    }
}

 

 

This will only work for replacement right?

I wanna have more textures than the default ones in order to add more clothes

Link to comment
3 hours ago, Threule said:

This will only work for replacement right?

I wanna have more textures than the default ones in order to add more clothes

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

local avaliableClothes = {
    {"cj_ped_torso", "1.png"},
    {"cj_ped_torso", "2.png"},
    {"cj_ped_torso", "3.png"},
    {"cj_ped_torso", "4.png"}

    -- vector 1 = tex name, vector 2 = tex file
}

function createClothes(id)
	local clothes = getAvaliableClothes()
	local texture = dxCreateTexture(clothes[id][2])

	if (id) then
		if (clothes[id]) then
			engineApplyShaderToWorldTexture(shader, clothes[id][1])
			dxSetShaderValue(shader, "Tex0", texture)

			outputChatBox("creating shader")
		else
			outputChatBox("invalid id")
		end
	else
		outputChatBox("please provied an id")
	end
end

 

Link to comment
8 minutes ago, Geteco said:

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

local avaliableClothes = {
    {"cj_ped_torso", "1.png"},
    {"cj_ped_torso", "2.png"},
    {"cj_ped_torso", "3.png"},
    {"cj_ped_torso", "4.png"}

    -- vector 1 = tex name, vector 2 = tex file
}

function createClothes(id)
	local clothes = getAvaliableClothes()
	local texture = dxCreateTexture(clothes[id][2])

	if (id) then
		if (clothes[id]) then
			engineApplyShaderToWorldTexture(shader, clothes[id][1])
			dxSetShaderValue(shader, "Tex0", texture)

			outputChatBox("creating shader")
		else
			outputChatBox("invalid id")
		end
	else
		outputChatBox("please provied an id")
	end
end

 

With this I can play with 1.png and my friend with 2.png?

Link to comment
1 hour ago, Threule said:

With this I can play with 1.png and my friend with 2.png?

I don't know, if does not work, test code from below.

  • client-side
Spoiler

local shader = dxCreateShader("fx/base.fx", 0, 0, true, "ped")
local playersWithTex = {}

local avaliableClothes = {
    {"cj_ped_torso", "1.png"},
    {"cj_ped_torso", "3.png"},
    {"cj_ped_torso", "4.png"},

    -- vector 1 = tex name, vector 2 = tex file
}

function createClothes(thePlayer, id)
	if (thePlayer and id) then
		playersWithTex[thePlayer] = {}
		playersWithTex[thePlayer][1] = dxCreateTexture(avaliableClothes[id][2])
		
		if (avaliableClothes[id]) then
			engineApplyShaderToWorldTexture(shader, avaliableClothes[id][1], thePlayer)
			dxSetShaderValue(shader, "Tex0", playersWithTex[thePlayer][1])

			outputChatBox("creating shader")
		else
			outputChatBox("invalid id")
		end
	else
		outputChatBox("provied an id")
	end
end

addEvent("onClientCreateClothes", true)
addEventHandler("onClientCreateClothes", root, createClothes)

 

  • server-side
Spoiler

addCommandHandler("newc",
function(player, cmd, id)
	triggerClientEvent("onClientCreateClothes", player, player, tonumber(id))
	outputChatBox("generating clothes to player: " ..getPlayerName(player), root, 255, 255, 255, true)
end)

 


OBS: The first version of this code ins't work. use this one.

Edited by Geteco
  • Like 1
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...