So for awhile now I’ve been trying to get an entity to give a player a whole clip of their active weapon. I figured this would be really easy and simple but I’ve run in to a few problems. I’ve been told to use Clip1 but that would end up returning what ever is in the clip at the time and I need the max clip. There is also the challenge with custom weapons, so I figured I would create some kind of ConVar:GetInt that returns the ClipSize/DefaultClip of the active weapon. But I have no idea how.
This is what I have so far.
function ENT:Touch( activator, caller ) if ( activator:IsNPC() ) then return end if ( activator:IsPlayer() ) then -- If a player, not an NPC or prop or anything, activates it self:Remove() -- Remove the entity. activator:ChatPrint('You recieved ammo for your held weapon.') -- Chat prints so you know you reciveved ammo. activator:EmitSound('items/smallmedkit1.wav') -- Sound plays so you know you recivevd ammo. local ammoconvar = -- ??? local clipcount = activator:GetActiveWeapon():ammoconvar() -- Defines local variable to get active weapon max ammo magazine/clip. local ammotype = activator:GetActiveWeapon():GetPrimaryAmmoType() -- Defines local variable to get active weapon ammo type. print( ammotype ) -- Ammo type test. print( clipcount ) -- Max magazine/clip count test. activator:GiveAmmo( clipcount, ammotype, true ) -- Gives correct ammo and ammount in regards of active weapon to player. end end
I’m still fairly new to lua but I really want to get the hang of it and learn other coding languages. Can someone help me out?