Nil value to DropWeapon() why ?

I try to drop weapon from the weapon I hold but I get this error
Thanks



autorun/test2.lua:48: attempt to call method 'DropWeapon' (a nil value)

[lua]local ThePlayer = LocalPlayer()
local pos = { 225 , 50 }
local size = { 200 , 300 }

local sW = ScrW()
local sH = ScrH()
local In = false

MoveX = CreateClientConVar( “Move_X”, “1”, false, false )
MoveY = CreateClientConVar( “Move_Y”, “1”, false, false )

function myhud()

for k,v in pairs (LocalPlayer():GetWeapons()) do
if v:GetClass() == “weapon_ar2” then

draw.RoundedBox( 6, sW / 2 + 216 + MoveX:GetInt() , sH / 2 + 275 + MoveY:GetInt(), 177, 25, Color ( 0, 0, 0, 120 ) )
draw.RoundedBox( 6, sW / 2 + 411 + MoveX:GetInt() , sH / 2 + 275 + MoveY:GetInt(), 80, 25, Color ( 0, 0, 0, 120 ) )

– Ammo Text Hud
– Primary
local PriAmmo = {}
PriAmmo.pos = {}
PriAmmo.pos[1] = sW / 2 + 224 + MoveX:GetInt() – x pos
PriAmmo.pos[2] = 597 – y pos
PriAmmo.color = Color(255,204,51,255) – Red
PriAmmo.text = "Ammo : " … LocalPlayer():GetActiveWeapon():Clip1() … " / " … LocalPlayer():GetAmmoCount(ThePlayer:GetActiveWeapon():GetPrimaryAmmoType())-- Text
PriAmmo.font = “Trebuchet19” – Font
PriAmmo.xalign = TEXT_ALIGN_LEFT – Horizontal Alignment
PriAmmo.yalign = TEXT_ALIGN_LEFT – Vertical Alignment
draw.Text( PriAmmo )

– Alt Ammo
local AltAmmo = {}
AltAmmo.pos = {}
AltAmmo.pos[1] = sW / 2 + 417 + MoveX:GetInt() – x pos
AltAmmo.pos[2] = 597 – y pos
AltAmmo.color = Color(255,204,51,255) – Red
AltAmmo.text = "Alt : " … ThePlayer:GetAmmoCount(ThePlayer:GetActiveWeapon():GetSecondaryAmmoType()) – Text
AltAmmo.font = “Trebuchet19” – Font
AltAmmo.xalign = TEXT_ALIGN_LEFT – Horizontal Alignment
AltAmmo.yalign = TEXT_ALIGN_LEFT – Vertical Alignment
draw.Text( AltAmmo )

function DropPhysGun()
for _, v in pairs(player.GetAll()) do
LocalPlayer():DropWeapon(LocalPlayer():GetActiveWeapon())
end
end
concommand.Add(“dropphys”, DropPhysGun)

	end
end

end

hook.Add(“HUDPaint”, “myhud”, myhud)

function hidehud(name)
for k, v in pairs{ “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( pos[1] , pos[2] )
DermaPanel:SetSize( size[1], size[2] )
DermaPanel:SetTitle( “Testing Derma Stuff” )
DermaPanel:SetVisible( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

button = vgui.Create( “DButton”, DermaPanel );
button:SetSize( 85, 24 );
button:SetPos( 25, 180 );
button:SetText( “Test Button” );
button.DoClick = function( button )
RunConsoleCommand(“dropphys”)
end

NumSliderX = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderX:SetPos( 25,50 )
NumSliderX:SetWide( 150 )
NumSliderX:SetText( “Move Left/Right” )
NumSliderX:SetMin( 0 ) – Minimum number of the slider
NumSliderX:SetMax( 1024 ) – Maximum number of the slider
NumSliderX:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderX:SetValue( 217 )
NumSliderX:SetConVar( “Move_X” ) – Set the convar

NumSliderY = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderY:SetPos( 25,100 )
NumSliderY:SetWide( 150 )
NumSliderY:SetText( “Move Up/Down” )
NumSliderY:SetMin( 0 ) – Minimum number of the slider
NumSliderY:SetMax( 256 ) – Maximum number of the slider
NumSliderY:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderY:SetConVar( “Move_Y” ) – Set the convar

[/lua]

Because DropWeapon() is serverside and your using it clientside

oh ok thanks

Is there a function like this for ClientSide ?

Edit: I tryied in with serverside but I get error with console command



Unknown Command: 'dropphys'

[lua]local ThePlayer = LocalPlayer()
local pos = { 225 , 50 }
local size = { 200 , 300 }

local sW = ScrW()
local sH = ScrH()
local In = false

MoveX = CreateClientConVar( “Move_X”, “1”, false, false )
MoveY = CreateClientConVar( “Move_Y”, “1”, false, false )

function myhud()

for k,v in pairs (LocalPlayer():GetWeapons()) do
if v:GetClass() == “weapon_ar2” then

draw.RoundedBox( 6, sW / 2 + 216 + MoveX:GetInt() , sH / 2 + 275 + MoveY:GetInt(), 177, 25, Color ( 0, 0, 0, 120 ) )
draw.RoundedBox( 6, sW / 2 + 411 + MoveX:GetInt() , sH / 2 + 275 + MoveY:GetInt(), 80, 25, Color ( 0, 0, 0, 120 ) )

– Ammo Text Hud
– Primary
local PriAmmo = {}
PriAmmo.pos = {}
PriAmmo.pos[1] = sW / 2 + 224 + MoveX:GetInt() – x pos
PriAmmo.pos[2] = 597 – y pos
PriAmmo.color = Color(255,204,51,255) – Red
PriAmmo.text = "Ammo : " … LocalPlayer():GetActiveWeapon():Clip1() … " / " … LocalPlayer():GetAmmoCount(ThePlayer:GetActiveWeapon():GetPrimaryAmmoType())-- Text
PriAmmo.font = “Trebuchet19” – Font
PriAmmo.xalign = TEXT_ALIGN_LEFT – Horizontal Alignment
PriAmmo.yalign = TEXT_ALIGN_LEFT – Vertical Alignment
draw.Text( PriAmmo )

– Alt Ammo
local AltAmmo = {}
AltAmmo.pos = {}
AltAmmo.pos[1] = sW / 2 + 417 + MoveX:GetInt() – x pos
AltAmmo.pos[2] = 597 – y pos
AltAmmo.color = Color(255,204,51,255) – Red
AltAmmo.text = "Alt : " … ThePlayer:GetAmmoCount(ThePlayer:GetActiveWeapon():GetSecondaryAmmoType()) – Text
AltAmmo.font = “Trebuchet19” – Font
AltAmmo.xalign = TEXT_ALIGN_LEFT – Horizontal Alignment
AltAmmo.yalign = TEXT_ALIGN_LEFT – Vertical Alignment
draw.Text( AltAmmo )

	end
end

end

hook.Add(“HUDPaint”, “myhud”, myhud)

function hidehud(name)
for k, v in pairs{ “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( pos[1] , pos[2] )
DermaPanel:SetSize( size[1], size[2] )
DermaPanel:SetTitle( “Testing Derma Stuff” )
DermaPanel:SetVisible( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

button = vgui.Create( “DButton”, DermaPanel );
button:SetSize( 85, 24 );
button:SetPos( 25, 180 );
button:SetText( “Test Button” );
button.DoClick = function( button )
RunConsoleCommand(“dropphys”)
end

NumSliderX = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderX:SetPos( 25,50 )
NumSliderX:SetWide( 150 )
NumSliderX:SetText( “Move Left/Right” )
NumSliderX:SetMin( 0 ) – Minimum number of the slider
NumSliderX:SetMax( 1024 ) – Maximum number of the slider
NumSliderX:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderX:SetValue( 217 )
NumSliderX:SetConVar( “Move_X” ) – Set the convar

NumSliderY = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderY:SetPos( 25,100 )
NumSliderY:SetWide( 150 )
NumSliderY:SetText( “Move Up/Down” )
NumSliderY:SetMin( 0 ) – Minimum number of the slider
NumSliderY:SetMax( 256 ) – Maximum number of the slider
NumSliderY:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderY:SetConVar( “Move_Y” ) – Set the convar

if SERVER then
function DropPhysGun()
for _, v in pairs(player.GetAll()) do
v:DropWeapon(v:GetWeapon(“weapon_physgun”))
end
end
concommand.Add(“dropphys”, DropPhysGun)

end
[/lua]

Are you sure your file is included serverside? Because if it were you would be bathing in errors from having all that clientside stuff. :smile:

I have one other file working with serverside too in autorun/test3.lua but this one is in the same place and also I tryied after modification of the file with lua_run_cl and lua_run autorun/test3.lua and nothing good