• I cant get my random player model working
    7 replies, posted
Hello there, Before making this thread i've searched numerous threads, I've searched these words in the search bar and looked at quite a few threads; "Setmodel" "Player model" "random model" On one thread i found this random model generator system which i copied and edited to fit the theme of my game mode, Im coding a jail break game mode, Non Fretta, As I am not a fan of Fretta (so do NOT post something like, Try using fretta / fretta related statements etc.). Anyway, At the moment the system isnt working, and just sets both teams model to the citizen model, this one to be precise ; "models/player/group01/male_01" Im confused of why my system isn't working, as it doesnt say any error in the console. it would much be appreciated if you were able to help (: Here is the section of my code; [code][lua]function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:StripWeapons() ply:StripAmmo() ply:SetGravity ( 1 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 170 ) ply:SetRunSpeed ( 220 ) if ply:Team() == 2 then ply:Spectate( 5 ) end if ply:Team() == 4 then ply:Spectate( 5 ) end -- Setting the players model PrisonerModels = {} PrisonerModels[1] = "models/player/group01/female_01" PrisonerModels[2] = "models/player/group01/female_02" PrisonerModels[3] = "models/player/group01/female_03" PrisonerModels[4] = "models/player/group01/female_04" PrisonerModels[5] = "models/player/group01/female_05" PrisonerModels[6] = "models/player/group01/female_06" PrisonerModels[7] = "models/player/group01/male_01" PrisonerModels[8] = "models/player/group01/male_02" PrisonerModels[9] = "models/player/group01/male_03" PrisonerModels[10] = "models/player/group01/male_04" PrisonerModels[11] = "models/player/group01/male_05" PrisonerModels[12] = "models/player/group01/male_06" PrisonerModels[13] = "models/player/group01/male_07" PrisonerModels[14] = "models/player/group01/male_08" function RandomPlayermodel( ply ) if ply:Team() == 3 then util.PrecacheModel( table.Random(PrisonerModels) ) ply:SetModel( table.Random(PrisonerModels) ) end end hook.Add("PrisonerSpawn", "Randomplayermodel", RandomPlayermodel) GuardModels = {} GuardModels[1] = "models/player/combine_soldier" GuardModels[2] = "models/player/combine_soldier_prisonguard" GuardModels[3] = "models/player/combine_super_soldier" function RandomPlayermodel2( ply ) if ply:Team() == 1 then util.PrecacheModel( table.Random(GuardModels) ) ply:SetModel( table.Random(GuardModels) ) end end hook.Add("GuardSpawn", "Randomplayermodel2", RandomPlayermodel) end[/lua][/code] Thankyou for reading (:
You missed a end at the first function. Other than that, what errors do you get?
[QUOTE=Ideal-Hosting;32145077]You missed a end at the first function. Other than that, what errors do you get?[/QUOTE] Its right at the bottom, But like i said i dont get any errors in console just doesnt work :S
Why is the end at the bottom? I've never seen a end after a hook...
[QUOTE=Persious;32145344]Why is the end at the bottom? I've never seen a end after a hook...[/QUOTE] So i take it i should move the end? EDIT I have moved it around a bit, but its still not working ; [code]function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:StripWeapons() ply:StripAmmo() ply:SetGravity ( 1 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 170 ) ply:SetRunSpeed ( 220 ) if ply:Team() == 2 then ply:Spectate( 5 ) end if ply:Team() == 4 then ply:Spectate( 5 ) end -- Setting the players model PrisonerModels = {} PrisonerModels[1] = "models/player/group01/female_01" PrisonerModels[2] = "models/player/group01/female_02" PrisonerModels[3] = "models/player/group01/female_03" PrisonerModels[4] = "models/player/group01/female_04" PrisonerModels[5] = "models/player/group01/female_05" PrisonerModels[6] = "models/player/group01/female_06" PrisonerModels[7] = "models/player/group01/male_01" PrisonerModels[8] = "models/player/group01/male_02" PrisonerModels[9] = "models/player/group01/male_03" PrisonerModels[10] = "models/player/group01/male_04" PrisonerModels[11] = "models/player/group01/male_05" PrisonerModels[12] = "models/player/group01/male_06" PrisonerModels[13] = "models/player/group01/male_07" PrisonerModels[14] = "models/player/group01/male_08" function RandomPlayermodel( ply ) if ply:Team() == 3 then util.PrecacheModel( table.Random(PrisonerModels) ) ply:SetModel( table.Random(PrisonerModels) ) end end GuardModels = {} GuardModels[1] = "models/player/combine_soldier" GuardModels[2] = "models/player/combine_soldier_prisonguard" GuardModels[3] = "models/player/combine_super_soldier" function RandomPlayermodel2( ply ) if ply:Team() == 1 then util.PrecacheModel( table.Random(GuardModels) ) ply:SetModel( table.Random(GuardModels) ) end end end hook.Add("PrisonerSpawn", "Randomplayermodel", RandomPlayermodel) hook.Add("GuardSpawn", "Randomplayermodel2", RandomPlayermodel)[/code] But still no error in console , so im confused as to why it isnt working.
[lua]-- It's a quite good idea to put it outside of the function, since we need it initialized only once, and with it inside the function, it will be re-initialized each time, which is just a loss of performance. PrisonerModels = {} PrisonerModels[1] = "models/player/group01/female_01" PrisonerModels[2] = "models/player/group01/female_02" PrisonerModels[3] = "models/player/group01/female_03" PrisonerModels[4] = "models/player/group01/female_04" PrisonerModels[5] = "models/player/group01/female_05" PrisonerModels[6] = "models/player/group01/female_06" PrisonerModels[7] = "models/player/group01/male_01" PrisonerModels[8] = "models/player/group01/male_02" PrisonerModels[9] = "models/player/group01/male_03" PrisonerModels[10] = "models/player/group01/male_04" PrisonerModels[11] = "models/player/group01/male_05" PrisonerModels[12] = "models/player/group01/male_06" PrisonerModels[13] = "models/player/group01/male_07" PrisonerModels[14] = "models/player/group01/male_08" GuardModels = {} GuardModels[1] = "models/player/combine_soldier" GuardModels[2] = "models/player/combine_soldier_prisonguard" GuardModels[3] = "models/player/combine_super_soldier" function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:StripWeapons() ply:StripAmmo() ply:SetGravity ( 1 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 170 ) ply:SetRunSpeed ( 220 ) if ply:Team() == 2 then ply:Spectate( 5 ) end if ply:Team() == 4 then ply:Spectate( 5 ) end if IsGuard ( ply ) RandomPlayermodel2 ( ply ) else RandomPlayermodel ( ply) end end function RandomPlayermodel( ply ) if ply:Team() == 3 then util.PrecacheModel( table.Random(PrisonerModels) ) ply:SetModel( table.Random(PrisonerModels) ) end end function RandomPlayermodel2( ply ) if ply:Team() == 1 then util.PrecacheModel( table.Random(GuardModels) ) ply:SetModel( table.Random(GuardModels) ) end end function IsGuard ( ply ) -- Some stuff to see if a player is a guard return true end[/lua] That's how I would have done it myself, each time a player spawns it checks whether he is a guard or not, and issues him with a random model based on that. Also, you had most of the stuff inside GM:PlayerSpawn, including function declarations. Creating custom hooks isn't really the best way to do it if you are only going to use it in a single place. EDIT: You might wanna put ".mdl" at the end of the model names. Not sure tho.
Yeah, you need a ".mdl" and if I'm sure @Insomnia's code should work.
Hey again, Insomnia thankyou for posting that code, very generous of you, and its fixed my problem :D Cant tahnkyou enough :) also tahnks to persious for posting aswell (:
Sorry, you need to Log In to post a reply to this thread.