[Need-Help]GLUA Script, simple playermodel changer !

Hello everybody,

I recently tried to make a simple player model changer. When people log on my server, a window popup, and they can choose a model to play with ! But ! It don’t work ! (xD). It’s really basic, only a DFrame and a DButton !

Here’s my cl_init.lua :


function pickmodel()
	local DermaPanel = vgui.Create("DFrame")
	DermaPanel:Center()
	DermaPanel:SetSize( 720, 720 )
	DermaPanel:SetTitle("Before Playing, choose a playermodel here !")
	DermaPanel:SetVisible(true)
	DermaPanel:SetDraggable(false)
	DermaPanel:ShowCloseButton(false)
	DermaPanel:MakePopup()

	local DermaBUtton = vgui.Create("DButton")
	DermaBUtton:SetParent(DermaPanel)
	DermaBUtton:SetPos(10, 30)
	DermaBUtton:SetText("Amaterasu")
	DermaBUtton:SetSize(150, 50)
	DermaBUtton.DoClick = function (DermaBUtton)
		function GAMEMODE:PlayerSetModel( ply )
			ply:SetModel("models/Amaterasu/models/player_amaterasu.mdl")
		end
		DermaPanel:Close()
	end
end

usermessage.Hook( "call_vgui", pickmodel )

And here’s my init.lua code :


function GM:PlayerInitialSpawn(ply)
self.BaseClass:PlayerInitialSpawn(ply)
umsg.Start("call_vgui", ply)
umsg.End()
end

I wish you can help me !

Thanks :slight_smile: !

PLAYER/SetModel Is a server side only function.

-snip-

It means I have to set it in init.lua instead of cl_init.lua ? :slight_smile:

[editline]11th February 2016[/editline]

I put this :


function pickmodel()
	local DermaPanel = vgui.Create("DFrame")
	DermaPanel:Center()
	DermaPanel:SetSize( 720, 720 )
	DermaPanel:SetTitle("Before Playing, choose a playermodel here !")
	DermaPanel:SetVisible(true)
	DermaPanel:SetDraggable(false)
	DermaPanel:ShowCloseButton(false)
	DermaPanel:MakePopup()

	local DermaBUtton = vgui.Create("DButton")
	DermaBUtton:SetParent(DermaPanel)
	DermaBUtton:SetPos(10, 30)
	DermaBUtton:SetText("Amaterasu")
	DermaBUtton:SetSize(150, 50)
	DermaBUtton.DoClick = function (DermaBUtton)
		function GAMEMODE:PlayerSetModel( ply )
			ply:SetModel("models/Amaterasu/models/player_amaterasu.mdl")
		end
		DermaPanel:Close()
	end
end

usermessage.Hook( "call_vgui", pickmodel )

In init.lua ?

cl_init.lua



function pickmodel()
	local Panel1 = vgui.Create("DFrame")
	Panel1:SetTitle("Before Playing, choose a playermodel here !")
	Panel1:ShowCloseButton(false)
	Panel1:SetDraggable(false)
	Panel1:SetSize(720,720)
	Panel1:SetVisible(true)
	Panel1:MakePopup()
	Panel1:Center()

	local SingleModel = vgui.Create("DButton",Panel1)
	SingleModel:SetPos(10, 30)
	SingleModel:SetText("Amaterasu")
	SingleModel:SetSize(150, 50)
	SingleModel.DoClick = function() net.Start("select_playermodel") net.WriteString("models/Amaterasu/models/player_amaterasu.mdl") net.SendToServer() Panel1:Remove() end
end
net.Receive("select_playermodel",function() pickmodel() end)


init.lua



function GM:Initialize()
util.AddNetworkString("select_playermodel")
end

function GM:PlayerInitialSpawn(ply)
net.Start("select_playermodel")
net.Send(ply)
end

function setmodel(model,ply)
if IsValid(ply) and file.Exists(model,"GAME") then
ply:SetModel(model)
end
end
net.Receive("select_playermodel",function(len,ply) setmodel(net.ReadString(),ply) end)


?

Goind to test that…