• Changing reload code
    7 replies, posted
I'm trying to code a way to handle ammunition in a custom way, but I don't understand how reloading in Source works. I look at the swep I downloaded and the only thing the Reload function is send a state to the model, and when the model is finished it refills the clip and subtracts from the ammo pool. Is there anyway I can hijack this process and re-code it? Is it built into the model?
I have been messing with the reload on a weapon myself. I've modified the SWEP:Reload function: [lua] function SWEP:Reload() self:DefaultReload( ACT_VM_RELOAD ) end [/lua] to do what I want to happen when a player needs to reload.
That just sends an animation and state to the weapon, I'm trying to figure out how to control what happens when the animation is finished.
[QUOTE=Bobv2;24628272]That just sends an animation and state to the weapon, I'm trying to figure out how to control what happens when the animation is finished.[/QUOTE][LUA]function SWEP:Reload() self:DefaultReload(ACT_VM_RELOAD) timer.Simple(self.Owner:GetViewModel():SequenceDuration(), function() //Code when act_vm_reload animation finishes end) end[/LUA]Here you go. I can write a simple code that it doesn't restore your clip1 if you want.
[QUOTE=freemmaann;24633076][LUA]function SWEP:Reload() self:DefaultReload(ACT_VM_RELOAD) timer.Simple(self.Owner:GetViewModel():SequenceDuration(), function() //Code when act_vm_reload animation finishes end) end[/LUA]Here you go. I can write a simple code that it doesn't restore your clip1 if you want.[/QUOTE] That would be nice.
[QUOTE=Bobv2;24634850]That would be nice.[/QUOTE]Here you go:[LUA]function SWEP:Reload() if !self.Reloading then self.Weapon:SendWeaponAnim(ACT_VM_RELOAD) self.Owner:SetAnimation(PLAYER_RELOAD) << Code when act_vm_reload animation starts >> self.Reloading = true timer.Simple(self.Owner:GetViewModel():SequenceDuration(), function() << Code when act_vm_reload animation finishes >> self.Reloading = false end) end end[/LUA]
That covers everything that self:DefaultReload(ACT_VM_RELOAD) does except for the refilling, right? And thanks.
[QUOTE=Bobv2;24647463]That covers everything that self:DefaultReload(ACT_VM_RELOAD) does except for the refilling, right? And thanks.[/QUOTE]Yeah, should work exactly the same, except no ammo refill.
Sorry, you need to Log In to post a reply to this thread.