I've been experimenting with spawn icons and I ran into a little bit of trouble. I'm trying to make it so when you click on the icon it changes your player model to that. I don't do a lot of derma coding so sorry if I did something obviously wrong.
Here's the code:
[LUA]
function PlayerModels()
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 20, 20 )
Frame:SetSize( 100, 100 )
Frame:SetVisible( true )
Frame:SetDraggable( true )
Frame:ShowCloseButton ( true )
local Icon = vgui.Create( "SpawnIcon", Frame)
Icon:SetPos( 30, 20 )
Icon:SetModel( "models/breen.mdl" )
Icon.DoClick(ply:SetModel("models/player/breen.mdl"))
end
concommand.Add("Menu", PlayerModels)
[/LUA]
And when I open the menu i get this error
DarkRP\gamemode\cl_init.lua:1087: attempt to call method 'SetModel' (a nil value)
And is there any way to get rid of the name of the model when you hover over it.
[img]http://img812.imageshack.us/i/gmod.jpg/[/img]
try[lua] Icon.DoClick = function() LocalPlayer():SetModel("models/player/breen.mdl") end [/lua]
That should works:
[lua]
-- Somewhere serverside
function SetModel(ply, cmd, args)
if (!args[1]) then return end;
ply:SetModel(args[1]);
end
concommand.Add("setmodel", SetModel)
-- Somewhere clientside
function PlayerModels()
local Frame = vgui.Create( "DFrame" );
Frame:SetPos( 20, 20 );
Frame:SetSize( 100, 100 );
Frame:SetVisible( true );
Frame:SetDraggable( true );
Frame:ShowCloseButton ( true );
local Icon = vgui.Create( "SpawnIcon", Frame);
Icon:SetPos( 30, 20 );
Icon:SetModel( "models/breen.mdl" );
Icon.DoClick = function()
RunConsoleCommand("setmodel", "models/player/breen.mdl");
end
end
concommand.Add("Menu", PlayerModels)
[/lua]
1. Ply is serverside
2. SetModel() is serverside
3. .DoClick() should be a function (but I am not sure)
Ah, Thanks for the help guys!
[editline]10:35PM[/editline]
How would I make it so that there are multiple spawn icons? When i try to add another Icon it messes up the menu.
oh, yes i forget that SetModel() is serverside :p
to add another spawnicon, just do [lua]
local Icon2 = vgui.Create( "SpawnIcon", Frame);
Icon2:SetPos( 30, 90 );
Icon2:SetModel( "models/breen.mdl" );[/lua]
but you need to set the frame size to (100, 165)
I want the second icon to be like the first one. Where you click it and it changes your model. How would i do that?
You add this:
[lua]
-- The other icon
local Icon = vgui.Create( "SpawnIcon", Frame);
Icon:SetPos( 30, 20 );
Icon:SetModel( "models/breen.mdl" ); -- Remplace it by the model you want
Icon.DoClick = function()
RunConsoleCommand("setmodel", "models/player/breen.mdl"); -- Same here
end
-- the end of the code
[/lua]
Ah, i got it thanks for the help both of you!
Sorry, you need to Log In to post a reply to this thread.