• ply:SetModel() and other functions not working on Player Spawn?
    3 replies, posted
Hello! So I've got a (probably) simple issue with a custom spawn script I'm making. I'm adding a custom script that on spawn, the user is stripped of weapons, has their model set, and their "Color" adjusted. Here is the code: [CODE]hook.Add( "PlayerSpawn", "SetTeam", function(ply) current = ply:GetNWString(ply:UserID() .. "_CurrentTeam") if current == "spectator" then ply:StripWeapons() ply:PrintMessage(HUD_PRINTCONSOLE, "Team spawned as: " .. current .. "\nPlayer Name: " .. ply:Nick()) ply:SetModel("models/hunter/blocks/cube025x025x025.mdl") ply:SetColor(Color(0,0,0,0)) ply:SetupHands() else ply:StripWeapons() print("Team spawned as: " .. current) model = table.Random(CPConf.Teams[current]["playermodels"]) util.PrecacheModel( model ) ply:SetModel(model) ply:SetColor(Color(255,255,255,255)) ply:SetupHands() wep = table.Random(CPConf.Teams[current]["weapons"]) ply:Give(wep) end end)[/CODE] Now before you say "do X, Y, Z" I'd like to point out certain things: - the ply:PrintMessage(HUD_PRINTCONSOLE, etc.) [B]WORKS![/B] In-game the message appears as it should! But the model isnt set directly after nor are weapons stripped. - Tested using spectator team and not spectator, the print and PrintMessage's [B]BOTH APPEAR[/B] but models arent set, weapons arent removed and given, etc. - The code for player modification in general does work! I have another custom hook based on the net library to respond to a command and uses this same code as an end game (run command, choose option, player model set, weapons stripped, etc.) and that works flawlessly! - NO CONSOLE ERRORS So in short, I'm guessing I'm using the player spawn hook incorrectly or there has to be another way to do this. If you guys know, please tell me, this has been a huge pain for me.
Try to set a simple timer. I make a scripte to force player to spawn with a special swep and if i dont set a timer simple to make a little delay, player donc switch to correct swep.
[QUOTE=Nyhu;51393058]Try to set a simple timer. I make a scripte to force player to spawn with a special swep and if i dont set a timer simple to make a little delay, player donc switch to correct swep.[/QUOTE] That did it! Thank you so much!
[url]http://wiki.garrysmod.com/page/GM/PlayerSpawn[/url] Updated just for you.
Sorry, you need to Log In to post a reply to this thread.