Page 1 of 1

scripting question

Posted: Thu Feb 17, 2022 8:08 pm
by LM|RCMP*
So, I've downloaded an older anni script, and I'm trying to do a little scripting, but I'm a bit confused.

What my goal is, is to create a vehicle using the "fighter" as the base, and replace the normal rocket launchers on it with the stinger missile functionality.

Looking through the code of the stinger.cs file, I think I've located the bit of code I would need, but I'm not sure. Basically I'm trying to find the section that locks on to the target

Code: Select all

function StingerImage::onFire(%player,%slot)
{		
	if($debug)
		echo("?? EVENT fire "@Player::getMountedItem(%player,0)@ " player "@ %player @" cl# "@ Player::getclient(%player));		

	%AmmoCount = Player::getItemCount(%player, $WeaponAmmo[Stinger]);
	if(%AmmoCount)
	{	
		%client = GameBase::getOwnerClient(%player);
		%clientName = Player::getClient(%player);
		%clientId = Client::getName(%client);
		%trans = GameBase::getMuzzleTransform(%player);
		%vel = Item::getVelocity(%player);
		if(GameBase::getLOSInfo(%player,1500))
		{
			%object = getObjectType($los::object);
			%targeted = GameBase::getOwnerClient($los::object);
			if(%object == "Player" || %object == "Flier")
			{
				%targetP = Client::getName(%targeted);
				Client::sendMessage(%client,0,"Stinger lock acquired "@ %targetP @ "~wmine_act.wav");
				Client::sendMessage(%targeted,0,"Stinger lock detected - " @ %clientId @ "~wono.wav");
				Projectile::spawnProjectile("StingerMissile",%trans,%player,%vel,$los::object);
				Annihilation::decItemCount(%player,$WeaponAmmo[Stinger],1);
			}
			else
			{
				Projectile::spawnProjectile("StingerRocket",%trans,%player,%vel,%player);
				Annihilation::decItemCount(%player,$WeaponAmmo[Stinger],1);
			}
		}
		else
		{
			Projectile::spawnProjectile("StingerRocket",%trans,%player,%vel,$los::object);
			Annihilation::decItemCount(%player,$WeaponAmmo[Stinger],1);
		}
	}
	else 
		Client::sendMessage(Player::getClient(%player),0,"Stinger out of ammo.~waccess_denied.wav");
}		
Now the one thing I want to make sure, is that instead of locking onto a player, it will only lock on to a vehicle. To do this, I'm guessing I change this line:

Code: Select all

if(%object == "Player" || %object == "Flier")
to this:

Code: Select all

if(%object == "Flier")
.

If that is the case, would I simply have to change line 36:

Code: Select all

projectileType = ScoutMissile;
to

Code: Select all

projectileType = StingerAmmo
? Or would I need to add the above section of code to 1Fighter.cs?

Re: scripting question

Posted: Fri Feb 18, 2022 10:51 am
by Maniac

Re: scripting question

Posted: Fri Feb 18, 2022 11:01 am
by AnniDv6
Pretty sure you would need to edit the actual fighter.cs. Your best bet might be finding a mod that did something similar and using it for reference. I remember there used to be mods where you could use the switch weapon bind while in a vehicle to cycle between a few weapons. There were also ones where you could buy the different weapons to install on the fighter at the vehicle pad.

Re: scripting question

Posted: Tue Jun 28, 2022 8:19 am
by perrinoia
Close, Ghost.

Code: Select all

function Scount::onFire(%this)
{
	deleteVariables("LOS::*");						//	Deletes all variables that start with "$LOS::"
	GameBase::LOSInfo(%this, 1500);					//	Sets $LOS::Normal, $LOS::Object, and $LOS::Position.
	
	%trans = GameBase::getMuzzleTransform(%this);	//	Location, orientation, and momentum of the gun barrel.
	%type = getObjectType($LOS::Object);			//	Type of object in crosshairs.
	%vel = Item::getVelocity(%this);				//	Momentum of gun barrel again for redundancy.
	
	if (%type != "Flier" && %type != "Player")		//	Straight shooter.
		Projectile::spawnProjectile("StingerRocket", %trans, %this, %vel, %this);
	else											//	Shoot'n straight for dat ass.
		Projectile::spawnProjectile("StingerMissile", %trans, %this, %vel, $los::object);
}
Might need to add a few lines for sound effects and energy usage if those aren't automatically handled elsewhere.
Oh, and you'll need to delete or comment out the projectile line in the Flier Scout datablock so that the game engine defers to the onFire event script.