by apolluwn » Fri Sep 23, 2011 12:36 am
I didn't mean for that to be code that was good to go and just copy-pasted...
It was just an example of what you might need to do... this is why I put all the prints and comments in there so you could see where it was in the code had you copied it into a clean source or similar to see how it worked or were just reading it...
If you really want weapons that need to activate after a certain time period/do some conditional animation/etc then you'll really want to consider revamping the weapon system itself. Particularly if you want to have animations before firing and after firing. It really will just be a pain in the ass the way it is set up right now (mostly if you are planning on having more weapons that need "special functionality") since it runs through W_WeaponFrame which then calls W_Attack to find what weapon is currently being used then calls the function that triggers the animation before a weapon state could be set.
This is fine for the standard quake weapons, but not for what you are wanting to do...
You can see that in the above code it forces the weaponframe to be 0 whenever it is warming up, overheated/ing, etc. This is because it is always trying to run the animation function (player_nail1) to increment the weapon frame before it calls W_FireSuperSpikes (within the animation function).
For the super nailgun it goes something like W_WeaponFrame (impulse commands and catches firing) -> W_Attack (see which weapon is being used call animation function) -> player_nail1 (animation/etc) -> W_FireSpikes (this is the nailgun code called from animation to play sounds, modify ammo count, and several other things) -> W_FireSuperSpikes (called from W_FireSpikes if the weapon is the super nailgun and not the nailgun) -> launch_spike (creates the entity projectile gives it a model etc).
I think you can see how this could be troublesome for what you are trying to do.
Quake wants to increment the weapon frame and create a muzzle flash before it even tries to actually "fire" the weapon.
You should probably call the animation from the weapons function rather than before it... This would allow you to get/set/pass the state so it plays the correct animations, effects, etc. You could probably make a generic animation function to pass the weapon state and the current weapon to. Then you could use the weapon state to pass the frames you wanted played to the actual animation function and the animation speed(s) into the weapon animation think function.
There would be a lot more to it than that, but if you were up to it you'd have a much better way of making weapons do what you wanted them to if they need additional capabilities beyond the standard behavior.
The only reason the above code would "work" is because it either constantly sets the weaponframe back to 0 and removes the muzzleflash or just allows the animation to go without ever playing the sound or running launch_spike. It's basically crapping all over the way it naturally works...