Shuubaru Posted July 17, 2016 Share Posted July 17, 2016 Hi, I'm making a GUI to select skins for a car, sync it with the server, and then use engineApplyShaderToWorldTexture, I have a problem with the visibility of the skins, only the player can see his skin, and he see the other players with the default texture (the texture on the .txd). Here is my code: client side skin = { [0] = nil , [1] = dxCreateTexture("texture2.png","dxt3") , [2] = dxCreateTexture("texture6.png","dxt3") } function buytheskin () if (source == botonSkin1) then setElementData( getLocalPlayer(), "infernusSkin", skin[1] ) triggerServerEvent ( "buySkin1", getLocalPlayer(), getLocalPlayer()) elseif (source == botonSkin2) then setElementData( getLocalPlayer(), "infernusSkin", skin[2] ) triggerServerEvent ( "buySkin2", getLocalPlayer(), getLocalPlayer()) end end addEventHandler ( "onClientGUIClick", getRootElement(), buytheskin ) function quitarSkin () setElementData( getLocalPlayer(), "infernusSkin", skin[0] ) triggerServerEvent ("quitarSkin", getLocalPlayer(), getLocalPlayer()) end addCommandHandler("testquitarskin", quitarSkin) --------------------------------------- --activacion de skins desde el server-- --skin 1 function pintar1 () local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local shader = dxCreateShader("pintura.fx") dxSetShaderValue(shader,"gTexture",skin[1]) engineApplyShaderToWorldTexture(shader,"texture",vehicle) end addEvent("pintar1", true) addEventHandler("pintar1", getLocalPlayer(), pintar1) --skin 2 function pintar2 (vehicle, player) local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local shader = dxCreateShader("pintura.fx") dxSetShaderValue(shader,"gTexture",skin[2]) engineApplyShaderToWorldTexture(shader,"texture",vehicle) end addEvent("pintar2", true) addEventHandler("pintar2", getLocalPlayer(), pintar2) -------------------------------------------------------- ----cargar skin al comienzo del mapa desde el server---- -------------------------------------------------------- function loadServerSkin (loadAccountSkinData) local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local shader = dxCreateShader("pintura.fx") dxSetShaderValue(shader,"gTexture",loadAccountSkinData) engineApplyShaderToWorldTexture(shader,"texture",vehicle) outputChatBox("Skin loaded successfully.") end addEvent("loadSkin", true) addEventHandler("loadSkin", getLocalPlayer(), loadServerSkin) addCommandHandler("forceskinload", loadServerSkin) function quitarPintura () local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local shader = dxCreateShader("pintura.fx") dxSetShaderValue(shader,"gTexture",skin[0]) engineApplyShaderToWorldTexture(shader,"texture",vehicle) end addEvent("quitarPintura", true) addEventHandler("quitarPintura", getLocalPlayer(), quitarPintura) --server side --buy skin 1 function buySkin1(player) if not player then return end if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) --if onTakeMoney( player, infos.nitroPrice) then if vehicle then local theSkin = getElementData (player, "infernusSkin") local playeraccount = getPlayerAccount ( player ) setAccountData (playeraccount, "infernuSkin", theSkin) triggerClientEvent(player, "pintar1", player) outputChatBox (getPlayerName(player).. " #ffffffhas set the skin 1",root,255,255,255,true) end --else --outputChatBox("#bd4749[ERROR] #cacacaYou dont have enough cash!",player,255,0,0,true) --end else outputConsole ( "You must be in a vehicle!",player,255,0,0,true) end end addEvent("buySkin1",true) addEventHandler("buySkin1",root,buySkin1) --buy skin 2 function buySkin2(player) if not player then return end if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) --if onTakeMoney( player, infos.nitroPrice) then if vehicle then local theSkin = getElementData (player, "infernusSkin") local playeraccount = getPlayerAccount ( player ) setAccountData (playeraccount, "infernuSkin", theSkin) triggerClientEvent(player, "pintar2", player) outputChatBox (getPlayerName(player).. " #ffffffhas set the skin 2",root,255,255,255,true) end --else --outputChatBox("#bd4749[ERROR] #cacacaYou dont have enough cash!",player,255,0,0,true) --end else outputConsole ( "You must be in a vehicle!",player,255,0,0,true) end end addEvent("buySkin2",true) addEventHandler("buySkin2",root,buySkin2) function quitarSkin (player) if not player then return end if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) if vehicle then triggerClientEvent(player, "quitarPintura", player) outputChatBox (getPlayerName(player).. " #ffffffhas succesfully removed his skin.",root,255,255,255,true) end else outputConsole ( "You must be in a vehicle!",player,255,0,0,true) end end addEvent("quitarSkin",true) addEventHandler("quitarSkin",root,quitarSkin) ------------------------------------- function cargarSkin () local getTheActualSkin = getElementData ( source, "infernusSkin") local playeraccount = getPlayerAccount ( source ) local loadAccountSkinData = getAccountData ( playeraccount, "infernuSkin" ) triggerClientEvent (source, "loadSkin", source, loadAccountSkinData) end addEventHandler( "onPlayerVehicleEnter",getRootElement(), cargarSkin ) I don't get any errors on the debug. Link to comment
RaceXtreme Posted July 18, 2016 Share Posted July 18, 2016 You want every player (X) in the server to view that vehicle skin of a specific player (A), right? When you call engineApplyShaderToWorldTexture, you just applied for that player A on his machine using the vehicle variable. Hence, only him will see his skin. If you need all players to be able to view so you would need to call pintar1 in all server's clients. But if I'm not wrong, the player A's vehicle element just exists if it is streammed in one Player X machine. So in addition, you would need a onClientElementStreamIn event to check whether the Player A's has vehicle appeared in Player X's world and if he has any skin to be applied. Instead to call the costum event pintar1 on the Player A's machine, you need onClientElementStreamIn event instead, where it checks if the source element is a valid player vehicle and whether if his account has the said infernusSkin. If so, apply the shader with engineApplyShaderToWorldTexture. Link to comment
Shuubaru Posted July 18, 2016 Author Share Posted July 18, 2016 You want every player (X) in the server to view that vehicle skin of a specific player (A), right? When you call engineApplyShaderToWorldTexture, you just applied for that player A on his machine using the vehicle variable. Hence, only him will see his skin.If you need all players to be able to view so you would need to call pintar1 in all server's clients. But if I'm not wrong, the player A's vehicle element just exists if it is streammed in one Player X machine. So in addition, you would need a onClientElementStreamIn event to check whether the Player A's has vehicle appeared in Player X's world and if he has any skin to be applied. Instead to call the costum event pintar1 on the Player A's machine, you need onClientElementStreamIn event instead, where it checks if the source element is a valid player vehicle and whether if his account has the said infernusSkin. If so, apply the shader with engineApplyShaderToWorldTexture. Thank you so much for the information, I didn't know the onClientElementStreamIn event. I rebuilt the script and now it works beatiful and all the important is on client side now. local skinShaders = {} addEventHandler("onClientResourceStart",resourceRoot, function () setElementData(localPlayer,"vehicleSkin",false) end ) addEventHandler("onClientElementStreamIn",root, function () if getElementType(source) == "vehicle" then loadVehicleSkins(source) end end ) addEventHandler("onClientVehicleEnter",root, function () loadVehicleSkins(source) end ) function loadVehicleSkins (vehicle) local controllerSkin = getVehicleController(vehicle) if not controllerSkin then return end local playerSkin = getElementData(controllerSkin,"vehicleSkin") if not playerSkin then return end if not skinShaders[playerSkin] then local theTexture = dxCreateTexture("texture"..playerSkin..".png","dxt3") local skinsFX = dxCreateShader("pintura.fx") dxSetShaderValue(skinsFX,"gTexture",theTexture) skinShaders[playerSkin] = skinsFX end engineApplyShaderToWorldTexture(skinShaders[playerSkin],"texture",vehicle) end function unloadVehicleLights(controllerSkin) setElementData(controllerSkin,"vehiclelight",false) end I will add later the triggers for my needs but it works. I hope this would be useful for someone else, and thank you again. 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