can kill player via gui

okey i am trying to make a simpel admin menu for my gamemode

i list all players in a DComboBox list

like so



for k, v in pairs(player.GetAll())do
    DComboBox:AddChoice( v:Nick() )
 end


that works and i select the player with this. idk if this is good to do but here it is



DComboBox.OnSelect = function( panel, index, value )
   selplayer = value
   DButton:SetText( "Slay " .. selplayer )
   
end


selplayer is the complete Player Name

then i run all players agien to se if it match in my slay button

if it finds a player with selplayer name it should kill him

idk what i do wrong here works with my chat command in init.lua. se chat command in the bottom



DButton.DoClick = function()
 
	for k, v in pairs(player.GetAll())do
   if( v:Nick() == selplayer ) then
                  v:Kill();
	else
	LocalPlayer():ChatPrint("Error!");
	end
 end
	
end


this is the error i get i know what it means but idk how to fix it

menu.lua:39: attempt to call method ‘Kill’ (a nil value)

i have tried doing this



v:Nick():Kill();


that gives an error to

menu.lua:39: attempt to index a string value with bad key (‘Kill’ is not part of the string library)

PS Im still learning to code lua trying my best :slight_smile:

Chat Command

RegisterChatCommand is a custom made function



RegisterChatCommand("!slay", function(ply, args)
	if( ply:IsAdmin() ) then
		local pname = args[1];

		for _, v in pairs( player.GetAll() ) do
			if( string.find(v:Nick(), pname) ) then
				v:Kill();
			end
		end
	end
end)


It was hard for me to read the post but i think you are trying to call :Kill() client side. You either need to use net libary and send to server, or you need to add a console command, and have the client use the command upon pressing the button.

Did you know that you are trying to kill a player from the clientside?
Create a serverside function for kill a player and use NET messages for this.

You should end with this:



--clientside
DButton.DoClick = function()
 
	for k, v in pairs(player.GetAll())do
   if( v:Nick() == selplayer ) then
                  net.Start("admin") net.WriteEntity(v:) net.SendToServer()
	else
	LocalPlayer():ChatPrint("Error!");
	end
 end
	
end




--serverside
function admin_killplayer(ply)
if ply:IsPlayer() then
ply:Kill()
end
end
net.Receive("admin",function() admin_killplayer(net.ReadEntity()) end)


That can be exploited so easy,




for k,v in pairs( player.GetAll() ) do
	net.Start("admin")
	net.WriteEntity(v)
	net.SendToServer()
end



At least add some isadmin checks or something.

Just wondering, how the hell is it possible for anyone to run net functions with ‘exploits’? I’m quite worried now

Sv_allowcslua and lua_run_cl/lua_openfile_cl.
Sv_allowcslua can also be bypassed if it is 0.

I meant if sv_allowcslua was set as 0 (didn’t know you could exploit that, why hasn’t that been fixed yet?!)

Because if you’re bypassing sv_allowcslua, you’re probably doing it in C++, and if you’re doing it in C++, you don’t even need sv_allowcslua.