Derma Panel open with SWEP/ChatCommand

Hey there,

I want a derma panel to be able to open when I input a chat command like “/open” and/or when I do primary click on a SWEP. Im also having issues with making the concommand to open the script… All of my code is in a cl file since its mostly derma for now. Do I need to do something in the init file as well…? I’m away for now but was thinking of what ill code next and have no idea. Yes I have looked it up.
Thanks :slight_smile:

-edit-
I think I need to call the function when I click with the SWEP my issue is how do I make sure the SWEP can read and run the derma code while the code isnt in the SWEP files… I want it seperate.

Well, if you want it to be a chat command, you shouldn’t be trying concommand stuff, you should be trying something like this:



hook.Add( 'OnPlayerChat', 'Some_Unique_Identifier', function( ply, txt, teamchat, dead )

    if txt == '/open' then

        -- put the derma opening stuff here

        return true -- returning true stops /open from being displayed in chat

    end

end )


Or, if you want it to be in the SWEP’s code, then maybe you should do this:



function SWEP:PrimaryAttack()
    if ( SERVER ) then -- if this hook is called on the server
        if ( game.SinglePlayer() ) then self:CallOnClient( "PrimaryAttack" ) end -- make sure this also gets called on the client's side as well so the panel can be created
    elseif IsFirstTimePredicted() -- this bit of the code below this statement gets called clientside, so we have to check if it's the first time it gets called and isn't a repeat (sometimes it calls the hook multiple times just in case)
        -- put your panel code here
    end
end


That thing above is untested, though.