• Derma Help
    12 replies, posted
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 [Code]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)[/Code] Here is the other function [Code]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) [/Code]
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 [URL=http://wiki.garrysmod.com/?title=DTextEntry][b]DTextEntry[/b][/URL].
[code]ModelPath:GetValue()[/code] Will get you the value of the DTextEntry.
[QUOTE=Drakehawke;23642853][code]ModelPath:GetValue()[/code] Will get you the value of the DTextEntry.[/QUOTE] :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) [code] 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 [/Code] 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 [Code]gamemodes\darkrp\gamemode\main.lua:2330: bad argument #1 to 'find' (string expected, got nil) [/Code] [editline]12:35AM[/editline] [code]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)[/code] 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: [code] 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) [/code] and then clientside: [code] 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) [/code] 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)
[QUOTE=dpoolas;23656675]hook.Add("ShowTeam", "SetModel", SetModel)[/QUOTE] Do you get any errors involving the hook? Could it be another hook with a similar name? Try hook.Add( "ShowTeam", "SetModel2", SetModel )
Sorry, you need to Log In to post a reply to this thread.