• Player team Bodygroups (Help me please)
    2 replies, posted
Hi, so can someone help me out with a Script that would detect the LOCAL PLAYERS team and if it was eg: Police it would set his model bodygroups. I know some bits and peices about how to do this but could someone help me out? Thanks any help is appriciated. :) Script raw idea: Check Ply's team, If team = police Then, Apply Bodygroups
[code] PoliceTeams = {--Put the name of your jobs here "Police Officer", "Police Chief" } if table.HasValue(PoliceTeams,team.GetName(ply:Team())) then ply:SetBodygroup(1,1)--An example, it sets the first bodygroup to 1. Change this to what you want. end [/code]
You'd assign the body groups on the server when the client spawns. I'd recommend using hook.Add PlayerLoadout instead of PlayerSetModel because hook.Add runs prior to main function... Create a table like this: [code]local TeamBodyGroups = { [ TEAM_POLICE ] = { model = "police/player/model.mdl"; -- string or table for random // Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; // Using table method bodygroups = { [ 1 ] = 1; [ 2 ] = 1; [ 3 ] = 5; }; }; [ TEAM_CHIEF ] = { model = "blah.mdl"; }; }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) then _p:SetModel( _model ); elseif ( istable( _model ) then _p:SetModel( table.Random( _model ) ); end end local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) then -- using my system elseif ( istable( _bodygroups ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end // Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end end end );[/code]
Sorry, you need to Log In to post a reply to this thread.