Demoting a player from cl_init

I basicly want to be able to demote a player from a client side dermalist,
but when I use what i do from the following code, I get demoted myself.

Like that you demote yourself when you want someone else to be demoted.

[lua]
for k,v in pairs(team.GetPlayers(4)) do
local Demote = vgui.Create( “DButton”, KnightDemote )
Demote:SetParent( DemoteM )
Demote:SetText( "Demote "…v:Nick() )
Demote:SetSize( 280, 25 )
KnightDemote:AddItem( Demote )
Demote.DoClick = function( Demote ) surface.PlaySound( “ui/buttonclickrelease.wav” )
v:ConCommand(“citizen”)
v:PrintMessage( HUD_PRINTTALK, "The Duke have demoted you, " … ply:Nick() ) end
end
[/lua]
I know that the problem is in using “v” but I dont really know anything else to try because im new to lua.

Also, Sorry for my english.

Well for one if you post some of your code, that would probably help.

Alright Then,
[lua]
local WorkM = vgui.Create(“DFrame”)

WorkM:SetParent( PropertySheet )
WorkM:Center()
WorkM:SetPos( 5, 5 )
WorkM:SetTitle("Work Benefits Menu")
WorkM:SetDraggable( false ) 
WorkM:ShowCloseButton( false )

if LocalPlayer():Team()==5 then

local DemoteM = vgui.Create("DFrame")
local KnightDemote = vgui.Create( "DPanelList", DemoteM ) 

DemoteM:SetParent( WorkM )
DemoteM:Center()
DemoteM:SetPos(10,30)
DemoteM:SetSize(310,170)
DemoteM:SetTitle("Demote Knights")
DemoteM:SetDraggable( false ) 
DemoteM:ShowCloseButton( false )

KnightDemote:EnableVerticalScrollbar( true ) 
KnightDemote:EnableHorizontal( true ) 
KnightDemote:SetPadding( 4 ) 
KnightDemote:SetPos(10,30)
KnightDemote:SetSize(290, 130)

for k,v in pairs(team.GetPlayers(4)) do
local Demote = vgui.Create( "DButton", KnightDemote ) 
Demote:SetParent( DemoteM )
Demote:SetText( "Demote "..v:Nick() )
Demote:SetSize( 280, 25 )
KnightDemote:AddItem( Demote )
Demote.DoClick = function( Demote ) surface.PlaySound( "ui/buttonclickrelease.wav" ) 
v:ConCommand("citizen")
v:PrintMessage( HUD_PRINTTALK, "The Duke have demoted you, " .. ply:Nick() )	end 
end 	
end

[/lua]

Btw, Made a quick video for it

your setting a new button in the same place…
something like this:

    DermaListView:SetPos(5, 0)
    DermaListView:SetSize(470, 300)
    DermaListView:SetMultiSelect(false)
    DermaListView:AddColumn("Name") -- Add column
    DermaListView:AddColumn("SteamID")
    local List = player.GetAll()
    for k,v in pairs(List) do
        DermaListView:AddLine(v:Nick(),v:SteamID()) -- Add lines
    end

but change column after your need
and button function

    button.DoClick = function( button )
        local Selected = DermaListView:GetSelectedLine( )
        local Player = List[Selected]
        if Selected != 0 then
        if DermaText:GetValue() != "" and Player:Nick() != LocalPlayer( ):Nick() then
        [CODE IF EVERYTHING IS AS IT SHOULD HERE]
        Help:Close()
        end
        end
    end

Changed that now, it fixed the PrintMessage, but not the Demotion.

“The Duke have demoted you, Bot05”
“You are now a Citizen, [ZC] Jonas”

You can’t run console commands on other people on the client.

like Player:ConCommand(“citizen”)
and that need to be serverside couse you cant run concommands on other players console via a client couse it can be abused.
So that function NEEDS to be server side

Hmm, any examples of how I would send something from the client to the server?

Ironically, you would use console commands.

[editline]07:16PM[/editline]

Something like this (on the server):
[lua]concommand.Add(“DemotePlayer”, function(ply, cmd, args)
if ply and ply:IsAdmin() and args[1] and tonumber(args[1]) then
local p = player.GetByID(args[1]);
if p and p:IsPlayer() then
p:ConCommand(“citizen”);
end
end
end);[/lua]

and on the client:

[lua]RunConsoleCommand(“DemotePlayer”, v:EntIndex());[/lua]

-snip-
Maker posted the same

Thanks for the help guys! :smiley:

no problem