Derma Help

Hey. What I am trying to do is make it so what I put in the dtextentry will be used for the command. For example on this i’m trying to make it so you put in the modelpath and when you hit enable your character will change to that model. My problem is I don’t know how to use the text that was used in the dtextentry. Here is what I have so far


function SetModel( ply )

local Spawn
local ModelPath
local Path
local Enable
local SetModel

SetModel = vgui.Create('DFrame')
SetModel:SetSize(285, 141)
SetModel:SetPos(235, 392)
SetModel:SetTitle('                               Set Your Model')
SetModel:SetDeleteOnClose(false)
SetModel:MakePopup()

Enable = vgui.Create('DButton')
Enable:SetParent(SetModel)
Enable:SetSize(118, 29)
Enable:SetPos(66, 101)
Enable:SetText('Enable')
Enable.DoClick = function()
RunConsoleCommand("supermodel")
end

Path = vgui.Create('DLabel')
Path:SetParent(SetModel)
Path:SetPos(18, 36)
Path:SetText('Model Path')
Path:SetSize(56, 12)

ModelPath = vgui.Create('DTextEntry')
ModelPath:SetParent(SetModel)
ModelPath:SetSize(186, 16)
ModelPath:SetPos(7, 65)
ModelPath:SetText('')
ModelPath.OnEnter = function() end

Spawn = vgui.Create('SpawnIcon')
Spawn:SetParent(SetModel)
Spawn:SetPos(208, 37)
Spawn:SetModel(ModelPath)
end
hook.Add("ShowTeam", "SetModel", SetModel)
concommand.Add("modelset", SetModel)

Here is the other function


local function SuperModel( ply )
if not ply:IsSuperAdmin() then
Notify(ply,1,4, "You cannot change your model")
else
ply:SetModel(ModelPath)
		end
	end
concommand.Add("supermodel", SuperModel)


It’s really common sense, that you look up the thing you need help with on the Wiki first. In this case, you need help with DTextEntry.


ModelPath:GetValue()

Will get you the value of the DTextEntry.

:ms:

Thank you to the people that helped. I am sort of just doing this for fun and to see what I can do.

[editline]10:27PM[/editline]

It is now getting ModelPath is a nil value which doesn’t make any sense to me…

Post the code you’ve got now.

Try making the ModelPath Global.
instead of Local Modelpath just use Modelpath

Also, here is a way of checking the user has entered an appropriate model (you might be using a different way but ah well)



function SetModel(ply)
 if ply:IsSuperAdmin() then
    Notify(ply, 1, 4, "You cannot change your model!")
 else
    if !string.Find(modelpath, "models/") then
      Notify(ply, 1, 4, "Please enter an appropriate Model Path!")
    else
      ply:SetModel(modelpath)
      Notify(ply, 1, 4, "You character model has been changed!")
    end
end


I think the !string.Find line might not work, try it.

Kingzy

gamemodes\darkrp\gamemode\main.lua:2330: attempt to call field ‘Find’ (a nil value)

I don’t know what this even means.

[editline]12:28AM[/editline]

Ok I fixed the string.find thing. Now the error is


gamemodes\darkrp\gamemode\main.lua:2330: bad argument #1 to 'find' (string expected, got nil)


[editline]12:35AM[/editline]


function SetModel(ply)
 if not ply:IsSuperAdmin() then
    Notify(ply, 1, 4, "You cannot change your model!")
 else
    ply:SetModel(ModelPath:GetValue())
      Notify(ply, 1, 4, "You character model has been changed!")
	   end
    end

concommand.Add("setmodel", SetModel, SetModel)

It seems the problem is in the textentry it is not detecting when there is text in it

The problem is the SetModel function is serverside, but the ModelPath is created on the client.

Serverside:



function SetModel(ply, command, args)
 if not ply:IsSuperAdmin() then
    Notify(ply, 1, 4, "You cannot change your model!")
 else
    ply:SetModel(args[1])
      Notify(ply, 1, 4, "You character model has been changed!")
	   end
    end

concommand.Add("setmodel", SetModel)


and then clientside:



function SetModel( ply )

local Spawn
local ModelPath
local Path
local Enable
local SetModel

SetModel = vgui.Create('DFrame')
SetModel:SetSize(285, 141)
SetModel:SetPos(235, 392)
SetModel:SetTitle('                               Set Your Model')
SetModel:SetDeleteOnClose(false)
SetModel:MakePopup()

Enable = vgui.Create('DButton')
Enable:SetParent(SetModel)
Enable:SetSize(118, 29)
Enable:SetPos(66, 101)
Enable:SetText('Enable')
Enable.DoClick = function()
RunConsoleCommand("setmodel", ModelPath:GetValue())
end

Path = vgui.Create('DLabel')
Path:SetParent(SetModel)
Path:SetPos(18, 36)
Path:SetText('Model Path')
Path:SetSize(56, 12)

ModelPath = vgui.Create('DTextEntry')
ModelPath:SetParent(SetModel)
ModelPath:SetSize(186, 16)
ModelPath:SetPos(7, 65)
ModelPath:SetText('')
ModelPath.OnEnter = function() end

Spawn = vgui.Create('SpawnIcon')
Spawn:SetParent(SetModel)
Spawn:SetPos(208, 37)
Spawn:SetModel(ModelPath:GetValue())
end
hook.Add("ShowTeam", "SetModel", SetModel)
concommand.Add("modelset", SetModel)


Report back any errors you get with that.

Lol Drakehawke thanks it works perfectly.

[editline]04:14AM[/editline]

One thing I have no idea why the hook isn’t working did I do something wrong with that

which hook?

hook.Add(“ShowTeam”, “SetModel”, SetModel)

Do you get any errors involving the hook? Could it be another hook with a similar name?

Try hook.Add( “ShowTeam”, “SetModel2”, SetModel )