Admin Model Changing

Okay, well I was working on some type of toggle able admin playermodel. What happens is, when I go ingame the cvar doesn’t even work. Heres what I have

[lua]local modelArray = {
“models/player/magnusson.mdl”
}
if CLIENT then
end

if not SERVER then return end
AddCSLuaFile( “autorun/adminModel.lua” )
CreateConVar(“colz_custompmodel”,“0”)

local custompmodel = GetConVarNumber(“colz_custompmodel”)
if Ply:IsAdmin() then
if (GetConVarNumber(“colz_custompmodel”) == “1”) then
Ply:SetModel(modelArray[1])
end
end
[/lua]

What am I doing wrong?
Also the magnusson model is just a test, its not really going to be that x3

That is really messy to read, can you please use lua tags instead of code tags.

Im sorry, didn’t know they existed. Done!

GetConVarNumber returns a number, not a string. It would be == 1, not == “1”.

Also, this function needs to be called every time a player spawns, so put int in a PlayerSpawn hook.

OK, I did the first thing you said, but how would I go about doing the second thing?

I added a hook to my function, I don’t know what to do next :expressionless:

[lua]
function adminModel()
if Ply:IsAdmin() then
if (GetConVarNumber(“colz_custompmodel”) == 1) then
Ply:SetModel(modelArray[1])
end
end
end
hook.Add( “Think”, “adminModel”, adminModel)
[/lua]

EDIT: Oh wait nevermind, now I get it…

[lua]
function adminModel()
if Ply:IsAdmin() then
if (GetConVarNumber(“colz_custompmodel”) == 1) then
Ply:SetModel(modelArray[1])
end
end
end
hook.Add( “PlayerSpawn”, “adminModel”, adminModel)
[/lua]

but the convar isn’t even being added…

here is an implementation suited for letting the player select from a list. The model only changes if they are an admin. The code is set up as if the lua file containing it is located in the lua/autorun/adminmodel.lua file which will make it automatically run and start working when the player/server loads

I am aware that it could be optimized by bypassing the clientconvar. It is there so the player has 2 options: Set the desired model using the concommand and have it change now or use the convar directly to have it change next spawn. Also the convar allows the setting to be saved so the player keeps their settings on next join
[lua]
local models = {
“models/player/magnusson.mdl”
}

if (CLIENT) then
CreateClientConVar( “colz_custompmodel_num”, 0, true, true )
concommand.Add( “colz_custompmodel_list”, function()
if (!models) then return end
MsgN( “==Custom Admin Models==” )
for k, v in pairs(models) do
MsgN( " ["…k…"] "…v )
end
MsgN( “==End of List==” )
end )
end

if (SERVER) then
AddCSLuaFile( “autorun/adminmodel.lua” )
local function PlayerSpawn( ply )
if (!models) then return end
if (ply:IsAdmin()) then
local modelNum = ply:GetInfoNum( “colz_custompmodel_num”, 0 )
if (modelNum == 0 || !models[ modelNum ]) then return end
ply:SetModel( models[ modelNum ] )
end
end
concommand.Add( “colz_custompmodel”, function( ply, cmd, args )
if (!args || !args[1]) then return end
ply:ConCommand( "colz_custompmodel_num "…args[1] )
PlayerSpawn( ply )
end )
hook.Add( “PlayerSpawn”, “colz_custompmodel_spawn”, PlayerSpawn )
end
[/lua]

I know that code will work, but one problem. I’m running DarkRP (Yes yes, I know DarkRP fails. I don’t have the knowledge to create a custom RP gamemode) wouldn’t I have to make a thing like if the convar is 1 then darkrp does not use setmodel of the F4 Class? What I mean is, I think the DarkRP class model is overriding the admin player model thing.

oh that’s an easy one

[lua]
local models = {
“models/player/magnusson.mdl”
}

if (CLIENT) then
CreateClientConVar( “colz_custompmodel_num”, 0, true, true )
concommand.Add( “colz_custompmodel_list”, function()
if (!models) then return end
MsgN( “==Custom Admin Models==” )
for k, v in pairs(models) do
MsgN( " ["…k…"] "…v )
end
MsgN( “==End of List==” )
end )
end

if (SERVER) then
AddCSLuaFile( “autorun/adminmodel.lua” )
local function PlayerSpawn( ply )
if (!models) then return end
if (ply:IsAdmin()) then
local modelNum = ply:GetInfoNum( “colz_custompmodel_num”, 0 )
if (modelNum == 0 || !models[ modelNum ]) then return end
timer.Simple( 5, function( ply, modelNum ) ply:SetModel( models[ modelNum ] ) end, ply, modelNum )
end
end
concommand.Add( “colz_custompmodel”, function( ply, cmd, args )
if (!args || !args[1]) then return end
ply:ConCommand( "colz_custompmodel_num "…args[1] )
PlayerSpawn( ply )
end )
hook.Add( “PlayerSpawn”, “colz_custompmodel_spawn”, PlayerSpawn )
end
[/lua]

The 5 second delay will make it change their model 5 seconds after they spawn, thus overriding whatever DarkRP sets them to

You are a HUGE help! You helped me fix both of my issues! Thank you so much. :slight_smile:

EDIT: Add me on steam :stuck_out_tongue:

“Shadowblade90222”