PDA

View Full Version : weapon projectile variables



legacy-snoguy24
07-06-2003, 07:22 PM
Hi im new to the board and scripting, but not programming. I was wonder how to set up a projectile, lets say a rocket so it could be influenced by the player. Not like the redeemer but just the ablitity to detonate it with alt fire or something like that. Been trying to go threw the code in the trans locator, but can't get as much out of it as i want since im new the the language.

legacy-monkeycircus
07-07-2003, 05:46 AM
The way I would go about it is only allowing a player to fire one rocket, then using a boolean variable to stop players firing the weapon more than once (for now...). Then, i would 'tag' each rocket as it is spawned, so that in the weapon class, i would have in spawnprojectile() something like:

MyProj = Rocket; just before the return rocket at the bottom.
bHasFiredAlready = True;
return rocket;

MyProj would be declared as a variable such that
var RocketProj MyProj; Where RocketProj is the classname of your projectile. and bHasFiredAlready is a boolean variable.

Then, when the alt-fire is called, you could have something like;

if (MyProj != None)
{
MyProj.BlowUp(); (or explode, or whatever).
bHasFiredAlready = False; (you might want to set this in destroyed() of the projectile instead)
}

Then, when the primary fire is called, you would just simply put in your bHasFiredAlready value to stop it firing if there is already a rocket spawned (so you cant have more than 1 rocket on the screen at any one time)

if (bHasFiredAlready == True)
return;

I don't know if that would actually work, sounds ok to me though. It gets alittle more complicated when you start trying to do it with multiple rockets. If you wanted multiple rockets to be fired, i would put a variable in teh projectile that tags teh weapon. For example;
var MyWeapon WeaponThatFiredMe;

and then set WeaponThatFiredMe in spawn projectile;
Rocket.WeaponThatFiredMe = Self;

Then, when you click alt fire, you could go thru every rocket actor in the game, and if WeaponThatFiredMe = Self, destroy it.

Foreach Object('RocketProj',Rocket)
{
if (Rocket.WEaponthatfiredme == Self)
rocket.blowup(); (or explode and such).
}

Im pretty sure there are better ways of doing that, but that should still get the desired effect.

legacy-snoguy24
07-07-2003, 02:35 PM
thanks, I think i will be sticking to just one rocket as of now. I was thinking something along those lines just didn't know how to apply it.