Author Topic: Pirate ship: Cannons  (Read 747 times)

I was working on a pirate ship and I needed the cannons to shoot. Each player controls their own cannon. But I cannot figure out how to make it so the player in mount1 fires it instead of mount0
Code: [Select]
function Shipvehicle::onTrigger(%this, %obj, %triggerNum, %val)
{
if(%triggerNum == 2 && %val && !iseventpending(%obj.rocketreload)){ //If they've pressed space bar and reloading isn't happening
%obj.client = %obj.getcontrollingclient(); //Find who's controlling the plane
%pos = %obj.getposition(); // Position stuff lol
%client = %obj.client; // More stuff
%pos = vectoradd(%pos,"-3 0 2"); // A little bit below the plane
%pos = vectoradd(%pos,%obj.getforwardvector()); // Make sure stuff's in front of the plane
%vel = "0 -90 0"; //Launch the bomb downwards so it hits something
%planevz = getword(%obj.getvelocity(),2);
if(%planevz < 0){
%vel = VectorAdd(%vel,"0 0 " @ %planevz);
}
%p = new Projectile() //Make the rocket
{
dataBlock = GunProjectile; //Could be any projectile, but it blows up on the vehicle if it's still in contact after half a second
initialVelocity = %vel;
initialPosition = %pos;
client = %obj.client;
sourceObject = %obj.client.player;
sourceClient = %obj.client;
};
MissionCleanup.add(%p); //Make sure stuff happens
%obj.rocketreload = schedule(500,0,""); //Reloads the rocket in one second
}
}

function untrigger(%obj, %trigger) //Makes the gun untrigger
{
%obj.setimagetrigger(%trigger,0);
}
Also, it fires the same direction no matter which way you face, how would I change that?

But I cannot figure out how to make it so the player in mount1 fires it instead of mount0
Your code doesn't specify that mount1 is the cannon. I think its
Code: [Select]
   numMountPoints = #;  // Replace # with the number of total mount points
   mountThread[#] = "sit";  // Replace # with the mount point number (mount0 would be 0) Keep sit if the player sits at that mount, replace it to be thread if he stands at that mountpoint

Your code doesn't specify that mount1 is the cannon. I think its
Code: [Select]
   numMountPoints = #;  // Replace # with the number of total mount points
   mountThread[#] = "sit";  // Replace # with the mount point number (mount0 would be 0) Keep sit if the player sits at that mount, replace it to be thread if he stands at that mountpoint
Obviously. Now how would I make it so you have to be in that slot to shoot.


Code: [Select]
//uiName = "Pirate Ship Cannon";
rideable = true;
   lookUpLimit = 0.5;  // How high you can aim Limit
   lookDownLimit = 0.3; // How low you can aim
   lookLeftLimit = 0.5 // How far left you can aim
   lookRightLimit = 0.5 // How far right you can aim

canRide = false;
showEnergyBar = false;
paintable = false;

brickImage = horseBrickImage; //the imageData to use for brick deployment

   numMountPoints = 1;
   mountThread[0] = "root";

function Shipvehicle::onTrigger(%this, %obj, %triggerNum, %val)
{
if(%triggerNum == 2 && %val && !iseventpending(%obj.rocketreload)){ //If they've pressed space bar and reloading isn't happening
%obj.client = %obj.getcontrollingclient(); //Find who's controlling the plane
%pos = %obj.getposition(); // Position stuff lol
%client = %obj.client; // More stuff
%pos = vectoradd(%pos,"-3 0 2"); // A little bit below the plane
%pos = vectoradd(%pos,%obj.getforwardvector()); // Make sure stuff's in front of the plane
%vel = "0 -90 0"; //Launch the bomb downwards so it hits something
%planevz = getword(%obj.getvelocity(),2);
if(%planevz < 0){
%vel = VectorAdd(%vel,"0 0 " @ %planevz);
}
%p = new Projectile() //Make the rocket
{
dataBlock = GunProjectile; //Could be any projectile, but it blows up on the vehicle if it's still in contact after half a second
initialVelocity = %vel;
initialPosition = %pos;
client = %obj.client;
sourceObject = %obj.client.player;
sourceClient = %obj.client;
};
MissionCleanup.add(%p); //Make sure stuff happens
%obj.rocketreload = schedule(500,0,""); //Reloads the rocket in one second
}
}

function untrigger(%obj, %trigger) //Makes the gun untrigger
{
%obj.setimagetrigger(%trigger,0);
}

That should do it.

Code: [Select]
//uiName = "Pirate Ship Cannon";
rideable = true;
   lookUpLimit = 0.5;  // How high you can aim Limit
   lookDownLimit = 0.3; // How low you can aim
   lookLeftLimit = 0.5 // How far left you can aim
   lookRightLimit = 0.5 // How far right you can aim

canRide = false;
showEnergyBar = false;
paintable = false;

brickImage = horseBrickImage; //the imageData to use for brick deployment

   numMountPoints = 1;
   mountThread[0] = "root";

function Shipvehicle::onTrigger(%this, %obj, %triggerNum, %val)
{
if(%triggerNum == 2 && %val && !iseventpending(%obj.rocketreload)){ //If they've pressed space bar and reloading isn't happening
%obj.client = %obj.getcontrollingclient(); //Find who's controlling the plane
%pos = %obj.getposition(); // Position stuff lol
%client = %obj.client; // More stuff
%pos = vectoradd(%pos,"-3 0 2"); // A little bit below the plane
%pos = vectoradd(%pos,%obj.getforwardvector()); // Make sure stuff's in front of the plane
%vel = "0 -90 0"; //Launch the bomb downwards so it hits something
%planevz = getword(%obj.getvelocity(),2);
if(%planevz < 0){
%vel = VectorAdd(%vel,"0 0 " @ %planevz);
}
%p = new Projectile() //Make the rocket
{
dataBlock = GunProjectile; //Could be any projectile, but it blows up on the vehicle if it's still in contact after half a second
initialVelocity = %vel;
initialPosition = %pos;
client = %obj.client;
sourceObject = %obj.client.player;
sourceClient = %obj.client;
};
MissionCleanup.add(%p); //Make sure stuff happens
%obj.rocketreload = schedule(500,0,""); //Reloads the rocket in one second
}
}

function untrigger(%obj, %trigger) //Makes the gun untrigger
{
%obj.setimagetrigger(%trigger,0);
}

That should do it.
I only pasted the code that needed editing, not the whole thing

I know, but that pretty much sloves all your problems. Add that to your script and it should work properly.