• Playermodel Change Clientside
    19 replies, posted
Hallo Everybody, i write a code, for missing playermodels. This should help when a CLEINT didn't have the costum Playermodel. That he saw a standard playermodel. Why i need that? I use a Workshop Downloader, that download the most Addons for the Pointshop after Joining, this helps to have lower jointime. The player want costum Playermodels so i try to finde a way the replace this stupid ERROR.mdl on a Client with an Playermodel. I write this together with Kamshark, kamshark dont have much time. So i try to finisch it and change things a bit [CODE]if SERVER then util.AddNetworkString( "PS2_PlayerSetModelServerside" ) function PlayerChangeThings( ply ) local model = ply:GetModel( ) net.Start( "PS2_PlayerSetModelServerside" ) net.WriteEntity( ply ) net.WriteString( model ) net.Broadcast( ) end hook.Add("PlayerSetModel","123dasd",PlayerChangeThings) end if CLIENT then local cache = {} local function ApplyModelToPlayerSafe( ply, model ) if cache[model] == nil then cache[model] = file.Exists( model, "GAME" ) and true or false end local modelExists = cache[model] if modelExists then print("Test: "..ply:GetModel()) ply:SetModel( model ) ply._Ps2ShouldHaveModel = nil else print("NOT FoundModel -- Phoenix") print("Test: "..ply:GetModel()) timer.Simple( 0.01, function( ) ply:SetModel( "models/player/phoenix.mdl" ) end ) timer.Simple( 0.05, function( ) ply:SetModel( "models/player/phoenix.mdl" ) end ) timer.Simple( 0.1, function( ) ply:SetModel( "models/player/phoenix.mdl" ) end ) timer.Simple( 1, function( ) ply:SetModel( "models/player/phoenix.mdl" ) end ) ply:SetModel( "models/player/phoenix.mdl") ply._Ps2ShouldHaveModel = model print("[WARN] Missing Playermodel %s, SetModel ignored", model ) end end net.Receive( "PS2_PlayerSetModelServerside", function( ) local ply, model = net.ReadEntity( ), net.ReadString( ) if IsValid(ply) then print( "Apply", ply, model ) ApplyModelToPlayerSafe( ply, model ) end end ) end[/CODE] This Code works so far, the only problem ist the: [CODE] ply:SetModel( "models/player/phoenix.mdl") ply._Ps2ShouldHaveModel = model print("[WARN] Missing Playermodel %s, SetModel ignored", model ) [/CODE] the local Client can't change the playermodel. I dont know why, I think the SERVER overwrites the local Client setModel. Did someone have any better idea or something? the print() are only for testing things!
Change the information a bit! I know my english is not the best..
I'm pretty sure the [URL="https://wiki.garrysmod.com/page/PLAYER/SetModel"]PLAYER:SetModel [/URL]function is server-side, it cannot be ran client-side. I recommend using net messages for this.
How do you want to use net message for that? I really have no idea how to use net messages for that
The net library gmod wiki page has a very clear example on how to use it: [url]https://wiki.garrysmod.com/page/Net_Library_Usage[/url] When the user clicks a button clientside, send the file model filepath to the server via net.WriteString, then read in net.Receive and set it to the player's model
[CODE] if SERVER then util.AddNetworkString( "PS2_PlayerSetModelServerside" ) function PlayerChangeThings( ply ) local model = ply:GetModel( ) net.Start( "PS2_PlayerSetModelServerside" ) net.WriteEntity( ply ) net.WriteString( model ) net.Broadcast( ) end hook.Add("PlayerSetModel","123dasd",PlayerChangeThings) end [/CODE] I know how to use the net libary. But i have no idea, how to use it for the Playermodel set. When the player cant set it ClientSide. I dont know did you read my code?
[QUOTE=UnDeadClank;50502131][CODE] if SERVER then util.AddNetworkString( "PS2_PlayerSetModelServerside" ) function PlayerChangeThings( ply ) local model = ply:GetModel( ) net.Start( "PS2_PlayerSetModelServerside" ) net.WriteEntity( ply ) net.WriteString( model ) net.Broadcast( ) end hook.Add("PlayerSetModel","123dasd",PlayerChangeThings) end [/CODE] I know how to use the net libary. But i have no idea, how to use it for the Playermodel set. When the player cant set it ClientSide. I dont know did you read my code?[/QUOTE] Its just ply:SetModel("playermodel.mdl")
What gamemode are you in? may be the gamemode the one thats changing the playermodel constantly or something.
[QUOTE=geferon;50502160]What gamemode are you in? may be the gamemode the one thats changing the playermodel constantly or something.[/QUOTE] Probably sandbox because hes using pointshop 2 (looking at his code PS2_PlayerSetModelServerside) [editline]12th June 2016[/editline] What i mean is people mainly use it for sandbox nothing else
[QUOTE=rtm516;50502167]Probably sandbox because hes using pointshop 2 (looking at his code PS2_PlayerSetModelServerside) [editline]12th June 2016[/editline] What i mean is people mainly use it for sandbox nothing else[/QUOTE] No, people use it for TTT as well and other gamemodes.
[QUOTE=geferon;50502183]No, people use it for TTT as well and other gamemodes.[/QUOTE] didnt think about ttt but 90% of gamemodes don't have a think hook setting the player model
[QUOTE=rtm516;50502189]didnt think about ttt but 90% of gamemodes don't have a think hook setting the player model[/QUOTE] I meant pointshop, not playermodel changing constantly. I know most of TTT's code and it doesn't change the playermodel on a think hook. Only at the start of the round
You can set the model clientside, but it will only show for the client.
I do have a question, if you try to set the playermodel of the local player in sandbox it gets set back to what the player's cl_playermodel is. Is there any way to get around this functionality and set the localplayer's playermodel in sandbox?
[QUOTE=Serafloof;50503442]I do have a question, if you try to set the playermodel of the local player in sandbox it gets set back to what the player's cl_playermodel is. Is there any way to get around this functionality and set the localplayer's playermodel in sandbox?[/QUOTE] Hook onto [url]http://wiki.garrysmod.com/page/GM/PlayerSetModel[/url]
[QUOTE=rtm516;50503475]Hook onto [url]http://wiki.garrysmod.com/page/GM/PlayerSetModel[/url][/QUOTE] It isn't allowing me to set the PlayerModel Client side. It almost instantly switches back.
Wow how much answers ^^ I test it on Sandbox yes, i dont test it in TTT. I use the Pointshop2 on TTT, Deathrun, PropHunt atm. And yes @tyguy, i want to change it clientside! ^^ I want the Clients to download the Playermodels after Joining, so they can join fast. The most player want play TTT 2 or 3 rounds and then leave. And often the Server have a 5 - 10 min join time. How can i finde out if the playermodel set is in the think hook?
[QUOTE=Serafloof;50503850]It isn't allowing me to set the PlayerModel Client side. It almost instantly switches back.[/QUOTE] Try delaying it using a timer
[QUOTE=UnDeadClank;50504469]And yes @tyguy, i want to change it clientside! ^^ I want the Clients to download the Playermodels after Joining, so they can join fast. The most player want play TTT 2 or 3 rounds and then leave. And often the Server have a 5 - 10 min join time.[/QUOTE] I don't really know how to help (sorry), I just want to say that this is a great idea, and I hope you succeed.
+bump. Interesting bu if changing the clientside works? I mean ply.SetModel is serverside... and i guess u want that the player that joined dont see the errors when he dont et the workshop addons so the error gets clientside replaced by kleiner or something default..?
Sorry, you need to Log In to post a reply to this thread.