scripting question

Post Reply
User avatar
LM|RCMP*
Posts: 127
Joined: Thu Apr 24, 2014 9:07 pm
Location: London, Ontario, Canada

scripting question

Post 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?
LM|| RCMP*
Head of Security
Image
User avatar
Maniac
Posts: 42
Joined: Thu Feb 17, 2022 9:39 pm
Location: Olympia, WA

Re: scripting question

Post by Maniac »

C U N ACTION!
AnniDv6
Posts: 1031
Joined: Mon Dec 12, 2011 3:25 pm

Re: scripting question

Post 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.
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: scripting question

Post 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.
Image
Post Reply