My friend made me a code where a derma menu pops up with selections of player models. When you choose one, you become that player model, but when you die/respawn, you change back to your default model. Is there any way to stay that model you selected even after respawning? Here's the code:
[CODE]
if SERVER then
AddCSLuaFile( "admin_derma.lua" );
function Set_Model( p, c, a )
if a[1] == nil then
return;
end;
if p:Alive() then
p:SetModel( "models/player/" .. a[1] .. ".mdl" );
end;
if not p.Model then
p.Model = p:GetModel()
end;
end
concommand.Add( "Set_Model", Set_Model );
hook.Add( "PlayerSpawn", "SetPlayerModel", function( p, c, a )
if p:Alive() then
p:SetModel( p.Model );
end;
end );
function MyMenu( ply ) --Start the function
ply:ConCommand( "model_menu" )
end --End the function
hook.Add("ShowSpare2", "show model menu", MyMenu) --Add the hook "ShowHelp" so it opens with F1
else
local models = { "swat", "urban", "gasmask", "riot", "leet", "phoenix", "guerilla", "arctic"};
concommand.Add( "model_menu", function()
local Menu = vgui.Create( "DFrame" );
Menu:SetSize( 400, 400 );
Menu:SetTitle( "Choose a model" );
Menu:SetDraggable( false );
Menu:SetVisible( true )
Menu:MakePopup()
Menu:Center()
local List = vgui.Create( "DPanelList", Menu )
List:SetPos( 5, 20 );
List:SetSize( 390, 375 )
List:EnableHorizontal( true )
List:EnableVerticalScrollbar( true )
for k, v in pairs( models ) do
local Mdl = vgui.Create( "SpawnIcon", List )
Mdl:SetModel( "models/player/".. v .. ".mdl" )
Mdl:SetToolTip( "Models/player/" .. v .. ".mdl" )
Mdl.DoClick = function()
RunConsoleCommand( "Set_Model", v )
Menu:Close()
local effectdata = EffectData()
effectdata:SetOrigin( self.Owner:GetPos() )
effectdata:SetNormal( self.Owner:GetPos() )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
util.Effect( "Sparks", effectdata )
self.BaseClass.ShootEffects( self )
end
List:AddItem( Mdl );
end;
end );
end;[/CODE]
Sorry, you need to Log In to post a reply to this thread.