Jump to content

[HELP] Skin shader apply not saving


Drackles

Recommended Posts

Greetings, my question is to apply a skin shader in my script. My problem is that another player does not see the shader when he has just entered the game, and when I reconnect, the shader disappears, so I have to apply the shader again every time, how can I save it?

 

shaders = {}
names = {}
textures = {}
applied = {}
groups = {
{ name = "FBI", texture= "lf.png", shader= "test.fx", num = 1, worldname = "swat" },
{ name = "FBI", texture= "sf.png", shader= "test.fx", num = 2, worldname = "swat" },
{ name = "FBI", texture= "sf2.png", shader= "test.fx", num = 3, worldname = "swat" },
{ name = "FBI", texture= "287.png", shader= "test.fx", num = 3, worldname = "army" },
{ name = "FBI", texture= "dym.png", shader= "test.fx", num = 5, worldname = "swmotr5" },
{ name = "FBI", texture= "fbi1.PNG", shader= "test.fx", num = 4, worldname = "swat" },
{ name = "FBI", texture= "fbi2.PNG", shader= "test.fx", num = 5, worldname = "swat" },
{ name = "FBI", texture= "fbi3.PNG", shader= "test.fx", num = 6, worldname = "swat" },
{ name = "FBI", texture= "lf.png", shader= "test.fx", num = 7, worldname = "swat" },
{ name = "FBI", texture= "dsa287.png", shader= "test.fx", num = 9, worldname = "army" },
{ name = "FBI", texture= "acura.png", shader= "test.fx", num = 11, worldname = "wmycd1" },
{ name = "FBI", texture= "marvel.png", shader= "test.fx", num = 2, worldname = "wmycd1" },
{ name = "FBI", texture= "srblack.png", shader= "test.fx", num = 3, worldname = "wmycd1" },
{ name = "FBI", texture= "test2.png", shader= "test.fx", num = 33, worldname = "cop2_cit" },
{ name = "FBI", texture= "160.png", shader= "test.fx", num = 35, worldname = "cwmohb2" },
{ name = "FBI", texture= "260.png", shader= "test.fx", num = 63, worldname = "swmotr5" },

}  

  addEventHandler( "onClientResourceStart", resourceRoot,
        function()

       for i,val in ipairs(groups) do
            perfectname = val.name..""..val.num
                        textures[perfectname] = dxCreateTexture ( val.texture )
            shaders[perfectname] = dxCreateShader( val.shader,999999, 0, false, "ped" )
           names[perfectname] = val.worldname
           dxSetShaderValue ( shaders[perfectname], "Tex0", textures[perfectname] )
        --   engineApplyShaderToWorldTexture ( shaders[perfectname], val.worldname )
            --bit of sanity checking
            if not shaders[perfectname] then
                exports.DRKdx:new( "Could not create shader. Please use debugscript 3" )
                destroyElement( textures[perfectname] )
                return
            elseif not textures[perfectname] then
                exports.DRKdx:new( "loading texture failed" )
                destroyElement ( shaders[perfectname] )
                tec = nil
                return
            end
           
        end
        end
    )

                function groupskinapply(cmd,num)
                

                local grp = getElementData(localPlayer,"Group")
                local perfectname = grp..""..num
            if grp and grp ~= "" and shaders[perfectname]  then
                if applied[perfectname] then
                triggerServerEvent("SunApplyToAllServer", root, perfectname, theplayer)
                applied[perfectname] = nil
                return end
                theplayer = localPlayer
                val = groups[1]
                applied[perfectname] = true
                triggerServerEvent("SonApplyToAllServer", root, perfectname, theplayer)
exports.DRKdx:new("Applied group skin "..num,0,255,0)
                end
                end
    addCommandHandler("groupskin", groupskinapply)
    
    
    addEvent("onApplyToAllServer", true )
    function applyitdude(val, player)
        
                                                        bool1 = engineApplyShaderToWorldTexture ( shaders[val], names[val], player )
---                                                        if not bool1 then outputChatBox("oh 4",255,0,0) end
    end
    addEventHandler("onApplyToAllServer", root, applyitdude)
    
    addEvent("unApplyToAllServer", true )
    function unapplyitdude(val, player)
        
                                                        bool1 = engineRemoveShaderFromWorldTexture ( shaders[val], names[val], player )
                                                        if not bool1 then outputChatBox("oh 4",255,0,0) end
    end
    addEventHandler("unApplyToAllServer", root, unapplyitdude)


    
 

Link to comment
  • Moderators
8 hours ago, Drackles said:

so I have to apply the shader again every time, how can I save it?

Use a database (and manager resource).

 

There are some community resources out there that can help you with that.

For example this one (which is not official released on the community resource since I am still building on it, but never the less feel free to use it.

https://gitlab.com/IIYAMA12/asyncdatabase

  1. Read the readme
  2. Modify the config and set to SQLite
  3. Check the examples

 

Others:

https://community.multitheftauto.com/index.php?p=resources&s=details&id=17541

https://community.multitheftauto.com/index.php?p=resources&s=details&id=6313

Search query:

https://community.multitheftauto.com/index.php?p=resources&s=list&name=data&descr=&category=

 

  • Like 1
Link to comment
  • Moderators
17 hours ago, Drackles said:

I don't know how to do it, is there any sample code or something please

You could start with first making sure it works without database. Instead you save it inside of the memory. Unlike elementdata which is bound to an element, this will stay until the resource is stopped.

local serialData = {}
function setPlayerSerialData(player, value)
    serialData[getPlayerSerial(player)] = value
    return true
end

function getPlayerSerialData(player)
    return serialData[getPlayerSerial(player)]
end

 

-- SET
setPlayerSerialData(player, perfectname)

 

-- GET
local perfectname = getPlayerSerialData(player)
print(perfectname)

 

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...