Make a player creator? (RP)

You know on cakescript and tacoscript when you join the server when you first spawn and you create a character? With a name and player model, how would i do that? I know i have to have a vgui and i got that covered, i just dont know the rest. I will give you credit when it will be released.

(I am sorry if this has been already asked, I dont want to look through all those pages for nothing.)

I have really ugly codes, but I think that this might work.
[lua]
–init.lua
include(“startup_derma.lua”)

function PlayerInitialSpawn(ply)
//command to run the derma menu
end

function PlayerSpawn(ply)
ply:setmodel(RPModel)
end
[/lua]
That to run the derma menu when they first spawn then this to put in the derma menu. Not going to give the full code because you could make the derma button different ways.

[lua]
–Going to call this startup_derma.lua
–Rest of the derma here
DermaButton.DoClick = function()
local PlayerModel = “models/barney.mdl” --random model
ply:setmodel(PlayerModel)
RPModel = PlayerModel
end
[/lua]

My code, I approve.

Note that RPModel is defined as a global in a file included in every file that uses it, so its value is cross-file.

yeah it’s true I was talking to banana in steam for help with setting the variable and using it correctly :smiley:
Banana owns me in coding.

Thanks for your help. But I have found a different way, can you guys check this if it is right?
[lua]function testpanel() – Create the function
test = vgui.Create(“DFrame”) – Create the frame
menu1 = vgui.Create(“DButton”) – Create the button

local DermaPanel = vgui.Create( "DFrame" )

DermaPanel:SetPos( 250,250 )
DermaPanel:SetSize( 500, 50 )
DermaPanel:SetTitle( “RolePlay Name” )
DermaPanel:ShowCloseButton( true )
DermaPanel:SetVisible( true )
DermaPanel:MakePopup()

local DermaText = vgui.Create( "DTextEntry", DermaPanel )

DermaText:SetPos( 20,25 )
DermaText:SetTall( 20 )
DermaText:SetWide( 450 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
Msg(“You have set your roleplay name to -”…DermaText:GetValue()…"-!" ) – What happens when you press enter
DermaPanel:SetVisible( false )
test:SetPos(50,50) – set the frame’s position on the screen
test:SetSize(300, 300) – set the frame size
test:SetTitle( “Test” ) – set the frame title
menu1:ShowCloseButton( true )
test:SetVisible( true ) – Make the frame visible
test:MakePopup() – make the frame popup
menu1:SetParent( test ) – parent the button to the frame
menu1:SetText( “Menu >” ) – set the button text
menu1:SetPos(150, 150) – set the button position in the frame
menu1:SetSize( 100, 20 ) – set the button size
menu1.DoClick = function ( btn ) – this will be called when the button is clicked
local menu123 = DermaMenu() – create a derma menu
menu123:AddOption(“Female01”, function() SetModel(“models/player/Group01/Female_01.mdl”) end ) – adding options
menu123:AddOption(“Female02”, function() SetModel(“models/player/Group01/Female_02.mdl”) end )
menu123:AddOption(“Female03”, function() SetModel(“models/player/Group01/Female_03.mdl”) end )
menu123:AddOption(“Female04”, function() SetModel(“models/player/Group01/Female_04.mdl”) end )
menu123:AddOption(“Female06”, function() SetModel(“models/player/Group01/Female_06.mdl”) end )
menu123:AddOption(“Female07”, function() SetModel(“models/player/Group01/Female_07.mdl”) end )
menu123:AddOption(“Male01”, function() SetModel(“models/player/group01/male_01.mdl”) end )
menu123:AddOption(“Male02”, function() SetModel(“models/player/Group01/Male_02.mdl”) end )
menu123:AddOption(“Male03”, function() SetModel(“models/player/Group01/male_03.mdl”) end )
menu123:AddOption(“Male04”, function() SetModel(“models/player/Group01/Male_04.mdl”) end )
menu123:AddOption(“Male05”, function() SetModel(“models/player/Group01/Male_05.mdl”) end )
menu123:AddOption(“Male06”, function() SetModel(“models/player/Group01/Male_06.mdl”) end )
menu123:AddOption(“Male07”, function() SetModel(“models/player/Group01/Male_07.mdl”) end )
menu123:AddOption(“Male08”, function() SetModel(“models/player/Group01/Male_08.mdl”) end )
menu123:AddOption(“Male09”, function() SetModel(“models/player/Group01/Male_09.mdl”) end )
menu123:Open()
end – ending the doclick function
end – ending the function
concommand.Add(“menutest”, testpanel) – adding the console command
[/lua]

Not really sure if this works.

looked over it pretty quickly. looks fine to me.

might be missing an end, or maybe notepad++ is dumb and cant organize things correctly.

There is an end at the very end, an end right before the very end to end the player model selection.
What did I just say?

wait, wtf is this?[lua]

local DermaText = vgui.Create( “DTextEntry”, DermaPanel )

DermaText:SetPos( 20,25 )

DermaText:SetTall( 20 )

DermaText:SetWide( 450 )

DermaText:SetEnterAllowed( true )

DermaText.OnEnter = function()

Msg(“You have set your roleplay name to -”…DermaText:GetValue()…"-!" )[/lua]

all it does it say you’ve changed your rp name?

also, I thought that the model had to be set when people spawn or it’d go back to default. I don’t know much about changing models though…

[editline]05:13AM[/editline]

and don’t you think your players will want to see what model they are picking? or you just want them to pick a random male/female model (they have different ethnicities, like some asian, some black, some white.)not my gamemode, I just want to help though.

Yea I dont know how to do that, but its a start.

You should try using tables and some loops… It would save you adding every model into the list individually. Once you get the hang of tables you’ll be able to do alot more stuff with lua.

or you can do it the complicated way like I do because I don’t know much about tables or that stuff.

@Averice - Congrats on Gold Member :3

Right, based on the level of your Lua I would advise stopping trying to make a gamemode and attempting smaller projects and working your way up. The name does nothing and the model will only be set clientside, so only for you and not for other players looking at you.

I don’t think you should even call yourself a Lua coder if you can’t use tables. It’s not complex nor a hard concept to grasp.

Recommendation to the OP; learn the Lua syntax first, figure out how it works, check out some basic scripts, and begin by something MUCH easier than a gamemode. You’ll be saving time, and you’ll actually figure out what the hell are you doing.

that is why I don’t call myself a lua coder, In my posts I specifically say that my codes are ugly or that I’m not an expert.

Ok, he made me lookup tables. knowing about tables now this is what I would do.

This file we will call “dermamenu.lua”
[lua]
RpModel={}
RpModel[1]=“the first model.mdl”
RpModel[2]=“the second model.mdl” – you get the point add one then add a new model…

function testpanel() – Create the function
test = vgui.Create(“DFrame”) – Create the frame
menu1 = vgui.Create(“DButton”) – Create the button

local DermaPanel = vgui.Create( "DFrame" )

DermaPanel:SetPos( 250,250 )
DermaPanel:SetSize( 500, 50 )
DermaPanel:SetTitle( “RolePlay Name” )
DermaPanel:ShowCloseButton( true )
DermaPanel:SetVisible( true )
DermaPanel:MakePopup()

local DermaText = vgui.Create( "DTextEntry", DermaPanel )

DermaText:SetPos( 20,25 )
DermaText:SetTall( 20 )
DermaText:SetWide( 450 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
Msg(“You have set your roleplay name to -”…DermaText:GetValue()…"-!" ) – Idk what the fuck this is suppose to do… this doesn’t have a function to set the name, just tell the person they changed their name.
DermaPanel:SetVisible( false )
test:SetPos(50,50) – set the frame’s position on the screen
test:SetSize(300, 300) – set the frame size
test:SetTitle( “Test” ) – set the frame title
menu1:ShowCloseButton( true )
test:SetVisible( true ) – Make the frame visible
test:MakePopup() – make the frame popup
menu1:SetParent( test ) – parent the button to the frame
menu1:SetText( “Menu >” ) – set the button text
menu1:SetPos(150, 150) – set the button position in the frame
menu1:SetSize( 100, 20 ) – set the button size
menu1.DoClick = function ( btn ) – this will be called when the button is clicked
local menu123 = DermaMenu() – create a derma menu
menu123:AddOption(“Female01”, function(pl, index)
local RpPlayerModel = RpModel(1) – RpModel[1] was set before (yes use for the table function the () to call it. or at least that’s how the wiki said to do it :D)
pl:setmodel(RpPlayerModel) – this sets the model for the first time
RPModel = RpPlayerModel end ) – this sets the variable for the other file we put the hook in (I like using hooks.lua)
– to add more to this just copy-paste this then put RpModel(2) etc.
menu123:Open()
end – ending the doclick function
end – ending the function
concommand.Add(“menutest”, testpanel) – adding the console command
[/lua]
Moving on to the next file “Hooks.lua I’m going to call it”
[lua]
include(“dermamenu.lua”)

function Rpmdl.PlayerInitialSpawn()
–your derma menu’s command to show here
end

function Rpmdl.PlayerSpawn(pl)
pl:setmodel(RpModel)
end

–Don’t forget the 2 hooks to make these functions work
hook.Add(“PlayerSpawn”, “Rpmdl.PlayerSpawn”, Rpmdl.PlayerSpawn)
hook.Add(“PlayerInitialSpawn”, “Rpmdl.PlayerInitialSpawn”, Rpmdl.PlayerInitialSpawn)
[/lua]

Before you ask the only reason it has the comments about the derma menu is cause I used his code, and I’m to lazy to remove them…