Hey all. I'll keep this brief and as informative as possible.
I'm having an issue with making it so that when I want to kick a player (actually, in this case a bot, same thing :P ), it occurs with an error. I've tried to work around it, but I lack the knowledge to do so. :(
So, here's my error...:
[code][@lua\dermapanel.lua:48] bad argument #1 to 'pairs' (table expected, got string)[/code]
Here's my code...:
[LUA]
--local PlayerCollect
-- for k, v in pairs(player.GetAll) do
local DermaBase = vgui.Create("DFrame")
DermaBase:SetPos( ScrW() / 33.5, ScrH() / 26.3 )
DermaBase:SetSize( 430, 369 )
DermaBase:SetTitle("BACONLUL")
DermaBase:SetVisible( true )
DermaBase:SetDraggable( false )
DermaBase:SetBackgroundBlur( true )
DermaBase:MakePopup()
local DermaBasePanel = vgui.Create("DPanel", DermaBase)
DermaBasePanel:SetPos( 5, 27 )
DermaBasePanel:SetSize( 420, 297 )
DermaBasePanel:SetVisible( true )
local DermaBasePanelTextEnt1 = vgui.Create("DTextEntry", DermaBasePanel)
DermaBasePanelTextEnt1:SetPos( 10, 10 )
DermaBasePanelTextEnt1:SetSize( 335, 20 )
DermaBasePanelTextEnt1:SetVisible( true )
DermaBasePanelTextEnt1:SetMultiline( false )
local DermaBasePanelTextBut1 = vgui.Create("DButton", DermaBasePanel)
DermaBasePanelTextBut1:SetPos( 350, 10 )
DermaBasePanelTextBut1:SetSize( 60, 20 )
DermaBasePanelTextBut1:SetText( "Enter" )
DermaBasePanelTextBut1:SetVisible( true )
DermaBasePanelTextBut1.DoClick = function()
Msg(DermaBasePanelTextEnt1:GetValue().."\n")
DermaBase:Close()
end
local DermaBaseCombo1 = vgui.Create("DComboBox", DermaBasePanel)
DermaBaseCombo1:SetPos( 10, 45 )
DermaBaseCombo1:SetSize( 140, 235 )
DermaBaseCombo1:SetVisible( true )
DermaBaseCombo1:SetMultiple( true )
DermaBaseCombo1:EnableHorizontal( false )
DermaBaseCombo1:EnableVerticalScrollbar( true )
for k, v in pairs(player.GetAll()) do --k = Key, v = Value
DermaBaseCombo1:AddItem( v:Nick().."\n" )
end
function PlayerKick()
for _, v in pairs( DermaBaseCombo1:GetSelectedItems()[1]:GetValue() ) do --DermaBaseCombo1:GetSelectedItems()[1]:GetValue()
v:Kick("I don't need to give you a reason!\n")
end
end
local KickPlayerButton1 = vgui.Create("DButton", DermaBasePanel)
KickPlayerButton1:SetPos( 215, 45 )
KickPlayerButton1:SetSize( 70, 25 )
KickPlayerButton1:SetText("Kick Players")
KickPlayerButton1:SetVisible( true )
KickPlayerButton1.DoClick = function()
PlayerKick()
end
-- New Panel... thing
local DermaBasePanel2 = vgui.Create("DPanel", DermaBase)
DermaBasePanel2:SetPos( 5, 329 )
DermaBasePanel2:SetSize( 420, 35 )
DermaBasePanel2:SetVisible( true )
local DermaBaseButton = vgui.Create("DButton", DermaBasePanel2)
DermaBaseButton:SetPos( 345, 5 )
DermaBaseButton:SetSize( 70, 25 )
DermaBaseButton:SetText("Close")
DermaBaseButton:SetVisible( true )
DermaBaseButton.DoClick = function()
DermaBase:Close()
end
[/LUA]
And here's a pic...:
[URL=http://imageshack.us/photo/my-images/155/botdermakickpanel.png/][IMG]http://img155.imageshack.us/img155/9384/botdermakickpanel.png[/IMG][/URL]
Hopefully this is enough info for you to work with. I know where the problem lies, but how do I fix it?
Cheers.
[lua] function PlayerKick()
for _, v in pairs( DermaBaseCombo1:GetSelectedItems()[1]:GetValue() ) do --DermaBaseCombo1:GetSelectedItems()[1]:GetValue()
v:Kick("I don't need to give you a reason!\n")
end
end[/lua]
Is the issue
Maybe try
[lua]function PlayerKick()
for _, v in pairs( DermaBaseCombo1:GetSelectedItems() ) do
if( string.len( DermaBasePanelTextEnt1:GetValue() ) > 0 ) then
v:Kick(DermaBasePanelTextEnt1:GetValue())
else
v:Kick("I don't need to give you a reason!\n")
end
end
end[/lua]
Of course I'm not sure if you have to cast a player string name to some kind of entity, somehow to allow that to work. (the v:Kick part)
[editline]e[/editline]
Instead of
[lua]DermaBaseCombo1:AddItem( v:Nick().."\n" )[/lua]
do
[lua]DermaBaseCombo1:AddItem(v:Nick())[/lua]
and try looking up the nick through player.GetAll, like maybe
[lua]function PlayerByComboItem( text )
for k, v in pairs(player.GetAll) do
if( v:Nick() == text ) then return v end
end
end
-- meanwhile
function PlayerKick()
for _, v in pairs( DermaBaseCombo1:GetSelectedItems() ) do
if( string.len( DermaBasePanelTextEnt1:GetValue() ) > 0 ) then
PlayerByComboItem(v):Kick(DermaBasePanelTextEnt1:GetValue())
else
PlayerByComboItem(v):Kick("I don't need to give you a reason!\n")
end
end
end[/lua]
Sanity checking not included
Nice try, but now it's appeared with this error:
[code][lua\dermapanel.lua:58] attempt to call method 'Kick' (a nil value)[/code]
Really dislikes the v:Kick... lol
[code]
function PlayerKick()
for _, v in pairs( DermaBaseCombo1:GetSelectedItems() ) do
if( string.len( DermaBasePanelTextEnt1:GetValue() ) > 0 ) then
v:Kick(DermaBasePanelTextEnt1:GetValue())
else
v:Kick("I don't need to give you a reason!\n") --THIS is the line with the error (line 58, in my code, cut down to save post space)
end
end
end
[/code]
EDIT:
The lua tags aren't working... Hang on.
EDIT2:
Fuck it. Code tags FTW.
You are using kick clientside when its a serverside function
Try making a console command and calling it in the derma menus via RunConsoleCommand (command, arguments)
[lua]
function PlayerKick()
for _, v in pairs( DermaBaseCombo1:GetSelectedItems()[1]:GetValue() ) do
RunConsoleCommand ("PlayerKick", <insert your reason here>)
end
end
function PlayerKickConsole (ply, cmd, args)
if ply:IsAdmin () then
args[1]:Kick (args[2])
end
end
concommand.Add ("PlayerKick", PlayerKickConsole)[/lua]
Or something like that. Just make sure to pass a player argument, and not a string one.
Found a way around it.
[code]
for k, v in pairs(player.GetAll()) do --k = Key, v = Value
DermaBaseCombo1:AddItem( v:Nick() )
end
local function PlayerKick()
if DermaBaseCombo1:GetSelectedItems() and DermaBaseCombo1:GetSelectedItems()[1] then
LocalPlayer():ConCommand( "kick "..DermaBaseCombo1:GetSelectedItems()[1]:GetValue() )
end
end
[/code]
The "kick" command is OK, but I can't seem to find a way of doing "kickid". Changing onto that, does anyone have an idea? :P
Look at code above your post
AFAIK (Just tested now) kickid <player id> <reason> uses the IDs from the status commands, which in turn can be retrieved with player:UserID ()
If you pass it to the concommand you should be done (ply:UserID () is shared so there should be no problem in creating proper derma callbacks involving the kickid concommand)
[QUOTE=Insomnia Array;30095101]AFAIK (Just tested now) kickid <player id> <reason> uses the IDs from the status commands, which in turn can be retrieved with player:UserID ()
If you pass it to the concommand you should be done (ply:UserID () is shared so there should be no problem in creating proper derma callbacks involving the kickid concommand)[/QUOTE]
Sorry I don't understand what you mean. :O
Bear with me, I had to look around on tutorials to get the...
[code]DermaBaseCombo1:GetSelectedItems()[1]:GetValue()[/code]
...Thing.
Also, I don't understand your function here. Mind taking me through it? The ply:IsAdmin() line makes sense, but where did you get those arguments from?
[QUOTE=Insomnia Array;30084984]
[code]function PlayerKickConsole (ply, cmd, args)
if ply:IsAdmin () then
args[1]:Kick (args[2])
end
end
concommand.Add ("PlayerKick", PlayerKickConsole)[/code]
Or something like that. Just make sure to pass a player argument, and not a string one.[/QUOTE]
args[1] is the first argument and args[2] is the second argument PlayerKick "El_Jameo" "Lua" and it'll kick that person ply:IsAdmin is an check to see if the player is an Admin but he's done it an stupid way and I don't recommend using it like that.
Sorry, you need to Log In to post a reply to this thread.