Getting Ammo String from Weapon:GetPrimaryAmmoType()?
6 replies, posted
What's the best way to get a weapon's primary ammo type as a string?
Anyone know?
for k,v in pairs(player.GetAll()) do
if(v == theweapon.Owner)
return "http://wiki.garrysmod.com/index.php?title=Special%3ASearch&search=ammo&go=Go"
end
end
Something like this should return the ammo type enumeration if I recall correctly.
print( LocalPlayer( ):GetActiveWeapon( ):GetPrimaryAmmoType( ) );
print( LocalPlayer( ):GetActiveWeapon( ):GetSecondaryAmmoType( ) );
Alternatively, you can use list.Get( "Weapons" ) and go through until you get v.ClassName == your weapon, then you can get v.Primary.Ammo or something. You should be able to GetTable( ) of the ActiveWeapon in order to grab ammo type as a "String"
[QUOTE=Acecool;44490247]Something like this should return the ammo type enumeration if I recall correctly.
print( LocalPlayer( ):GetActiveWeapon( ):GetPrimaryAmmoType( ) );
print( LocalPlayer( ):GetActiveWeapon( ):GetSecondaryAmmoType( ) );
Alternatively, you can use list.Get( "Weapons" ) and go through until you get v.ClassName == your weapon, then you can get v.Primary.Ammo or something.[/QUOTE]
Or you know you could just do LocalPlayer():GetActiveWeapon().Primary.Ammo because the table is saved on the weapon unless it's a C weapon.
[QUOTE=OzymandiasJ;44490381]Or you know you could just do LocalPlayer():GetActiveWeapon().Primary.Ammo because the table is saved on the weapon unless it's a C weapon.[/QUOTE]
Yeah. I thought I'd have to go with this as much. I'll try it.
For the C Weapons - found this on this forum somewhere:
[lua] MaxAmmo={}
client = LocalPlayer()
MaxAmmo["weapon_crowbar"]=0
MaxAmmo["weapon_physcannon"]=0
MaxAmmo["weapon_physgun"]=0
MaxAmmo["weapon_pistol"]=18
MaxAmmo["gmod_tool"]=0
MaxAmmo["weapon_357"]=6
MaxAmmo["weapon_smg1"]=45
MaxAmmo["weapon_ar2"]=30
MaxAmmo["weapon_crossbow"]=1
MaxAmmo["weapon_frag"]=-1
MaxAmmo["weapon_rpg"]=-1
MaxAmmo["weapon_shotgun"]=6
if client:GetActiveWeapon().Primarythen
client:GetActiveWeapon().Primary.ClipSize
else
MaxAmmo[client:GetActiveWeapon():GetClass()]
end[/lua]
It wouldn't be hard to adapt it for the HL2 weapons so it has not only max ammo which is listed, but also the type of ammo, etc..
Sorry, you need to Log In to post a reply to this thread.