SetAmmo wont work with Slider.

Some one can help me with SetAmmo and Slider to modify the value of my current weapon ?

Thanks in advance.

[lua]if CLIENT then

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 )

AddAmmo1 = CreateClientConVar( “AddAmmo_1”, “1”, false, false )

function myhud()

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

NumSliderAmmo1:GetValue( LocalPlayer():GetActiveWeapon():Clip1() )

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)

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, 220 );
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

NumSliderAmmo1 = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderAmmo1:SetPos( 25,150 )
NumSliderAmmo1:SetWide( 150 )
NumSliderAmmo1:SetText( “Ammo 1” )
NumSliderAmmo1:SetMin( 0 ) – Minimum number of the slider
NumSliderAmmo1:SetMax( 1024 ) – Maximum number of the slider
NumSliderAmmo1:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderAmmo1:SetValue( 217 )

end

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

function GiveAmmo1( )
local player_1 = player.GetByID(1)
player_1:SetAmmo( AddAmmo1 , “Pistol” )
end
concommand.Add(“giveammo2”, GiveAmmo1)

end[/lua]

Not sure, but try this:

[lua]
local player_1 = player.GetByID(1)
player_1:GiveAmmo(AddAmmo1,“pistol”);
end
[/lua]

I’m not sure if it works, but worth a try?

[editline]01:27PM[/editline]

Oh, evermind, I didn’t even know about SetAmmo

thnx but no one have another idea ?

I believe your code is too messy for most people to properly debug.

What do you mean by messy ? I can’t do this with a Slider only and a Convar ?

What do you think he means half this code is copy and pasted and just put together in one big mess thats how its a mess