Author Topic: Guided Missile  (Read 916 times)

Hi

I found this code somewhere in my archive. It does seem to work. The only problem is that the missile doesn't show up in the view and I can only turn left and right but I cannot go up or down. Could someone please debug this out?

Code: [Select]
//Guided Missile - it fires bots that are cloaked to look like missiles. You control the bot.
//////////
// item //
//////////
datablock ItemData(guidedrocketLauncherItem)
{
   category = "Weapon";  // Mission editor category
   className = "Weapon"; // For inventory system

    // Basic Item Properties
   shapeFile = "Add-Ons/Weapon_Rocket_Launcher/rocketLauncher.dts";
   rotate = false;
   mass = 1;
   density = 0.2;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   //gui stuff
   uiName = "Guided Missile";
   iconName = "./ItemIcons/rocketLauncher";
   doColorShift = true;
   colorShiftColor = "0.500 0.000 0.250 1.000";

    // Dynamic properties defined by the scripts
   image = guidedrocketLauncherImage;
   canDrop = true;
};

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(guidedrocketLauncherImage)
{
   // Basic Item properties
   shapeFile = "Add-Ons/Weapon_Rocket_Launcher/rocketLauncher.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
//   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = rocketLauncherProjectile;
   projectileType = Projectile;

   //casing = rocketLauncherShellDebris;
   shellExitDir        = "1.0 -1.3 1.0";
   shellExitOffset     = "0 0 0";
   shellExitVariance   = 15.0;   
   shellVelocity       = 7.0;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;
   minShotTime = 5000;   //minimum time allowed between shots (needed to prevent equip/dequip exploit)

   doColorShift = true;
   colorShiftColor = guidedrocketLauncherItem.colorShiftColor;//"0.400 0.196 0 1.000";

   //casing = " ";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
   stateName[0]                     = "Activate";
   stateTimeoutValue[0]             = 0.1;
   stateTransitionOnTimeout[0]       = "Ready";
   stateSound[0]              = weaponSwitchSound;

   stateName[1]                     = "Ready";
   stateTransitionOnTriggerDown[1]  = "Fire";
   stateAllowImageChange[1]         = true;
   stateTransitionOnNoAmmo[1]       = "NoAmmo";
   stateSequence[1]  = "Ready";

   stateName[2]                    = "Fire";
   stateTransitionOnTimeout[2]     = "Smoke";
   stateTimeoutValue[2]            = 0.1;
   stateFire[2]                    = true;
   stateAllowImageChange[2]        = false;
   stateSequence[2]                = "Fire";
   stateScript[2]                  = "onFire";
   stateWaitForTimeout[2]        = true;
   stateEmitter[2]               = rocketLauncherFlashEmitter;
   stateEmitterTime[2]           = 0.05;
   stateEmitterNode[2]           = tailNode;
   stateSound[2]              = rocketFireSound;
   stateSequence[2]                = "Fire";
   //stateEjectShell[2]       = true;

   stateName[3] = "Smoke";
   stateEmitter[3]               = rocketLauncherSmokeEmitter;
   stateEmitterTime[3]           = 0.05;
   stateEmitterNode[3]           = "muzzleNode";
   stateTimeoutValue[3]            = 0.1;
   stateSequence[3]                = "TrigDown";
   stateTransitionOnTimeout[3]     = "CoolDown";

   stateName[5] = "CoolDown";
   stateTimeoutValue[5]            = 12;
   stateTransitionOnTimeout[5]     = "Reload";
   stateSequence[5]                = "TrigDown";

   stateName[4]         = "Reload";
   stateTransitionOnTriggerUp[4]     = "Ready";
   stateSequence[4]  = "TrigDown";

   stateName[6]   = "NoAmmo";
   stateTransitionOnAmmo[6] = "Ready";

};

function guidedrocketLauncherImage::onFire(%this, %obj, %slot)
{
%pos = %obj.gettransform();
%forvec = %obj.getforwardvector();
%pos = VectorAdd(%pos, %forvec);
%pos = VectorAdd(%pos, %forvec); //Adds some stuff to the position so the missile starts in front of you not inside you
%allrot = %obj.gettransform();
%rot = getword(%allrot,3);
%rot = %rot SPC getword(%allrot,4);
%rot = %rot SPC getword(%allrot,5);
%rot = %rot SPC getword(%allrot,6); //Gets all the rots
%bot = new AIPlayer()
{
datablock="MissileBot";
position=%pos;
rotation=%rot;
};
clearallplayernodes(%bot); //Makes the bot invisible
%bot.mountimage(missileimage, 0); //Mounts a missile so it looks like its a missile
%obj.setcontrolobject(%bot); //Control the missile
%bot.settransform(%bot.getposition() SPC %rot); //Reset the rotation
//Need to find a way to set the bot to look where you were looking.
%bot.owner = %obj.client; //Set owner to you
%obj.client.bot = %bot; //Set your bot to the bot
pushbottopos(%bot); //Start the missile-pushing
}

function pushbottopos(%bot)
{
if (!isObject(%bot)) return;
%ppos = %bot.geteyevector(); //Sets to move to where your aiming
%vec = %ppos;
%vec = VectorNormalize(%vec);
%vec = VectorScale(%vec, 45);
%bot.setVelocity(%vec); //Throws it to where its looking
%bot.pbtoTick = schedule(100, 0, "pushbottopos", %bot); //Repeats it
}

function ServerCmdSelfDestruct(%client)
{
schedule(100,0,"Deletebot",%client.bot); //Deletes bot
%client.player.setcontrolobject(%client.player); //Switches control to you again
}

//Another datablock, same as nojet player, made so I can change its onimpact.
datablock PlayerData(MissileBot : PlayerStandardArmor)
{
minJetEnergy = 0;
jetEnergyDrain = 0;
canJet = 0;
showEnergyBar = false;
thirdpersononly = 1;

uiName = "";
};

function MissileBot::onImpact(%this, %obj, %collidedObject, %vec, %vecLen)
{
%obj.owner.player.setwhiteout(0.55);
MissileExplode(%obj.getposition());
if(miniGameCanDamage(%obj.owner.player, %collidedObject) && %collidedobject.getclassname() $= "Player"){ //Checks if you can damage it through minigame
if(%collidedobject.getclassname() $= "Player"){
if(isObject(%obj.owner.minigame)){
messageall("","" @ %obj.owner.player.client.name @ " missiled " @ %collidedobject.client.name @ "!"); //Tell everyone
%collidedObject.kill(); //Kill the collision
}
}
}
if(MiniGameCanDamage(%obj.owner.player.client.player, %collidedobject) && %collidedobject.getclassname() $= "WheeledVehicle"){
%collidedobject.damage(1000,1000,1000,1000, 1000); //Kills a vehicle if it is there
}
if(MiniGameCanDamage(%obj.owner.player, %ollidedobject) && %collidedobject.getclassname() $= "FlyingVehicle"){
%collidedobject.damage(1000,1000,1000,1000, 1000); //Kills a vehicle if it is there
}
echo(MiniGameCanDamage(%obj.owner.player, %collidedobject));
if(MiniGameCanDamage(%obj.owner.player, %collidedobject) && collidedobject.getclassname() $= "AIPlayer"){
%collidedobject.damage(1000,1000,1000,1000, 1000); //Kills a vehicle if it is there
%collidedobject.kill();
}
MissileRadius(%obj,  %obj.getposition(), "24", "0", "Missile", "1500", %obj.owner);
%obj.owner.player.setcontrolobject(%obj.owner.player); //Switches control back to you
schedule(100,0,"Deletebot",%obj); //Deletes bot because sometimes you control it till it disappears O_o
}

function Deletebot(%obj)
{
%obj.delete();
}

datablock ShapeBaseImageData(MissileImage)
{
   // Basic Item properties
   shapeFile = "Add-Ons/Weapon_Rocket_Launcher/RocketProjectile.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 2;
   offset = "0 0 0";
   rotation = eulerToMatrix("0 0 0");
   eyeOffset = "0 0 0";
   eyeRotation = eulerToMatrix("0 0 0");

   doColorShift = false;
   colorShiftColor = MissileItem.colorShiftColor;
   

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = false;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "ToolImage";

   // Projectile && Ammo.
   item = MissileItem;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = false;

   doColorShift = false;
   //colorShiftColor = MissileItem.colorShiftColor; //"0.200 0.200 0.200 1.000";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.5;
stateTransitionOnTimeout[0]       = "Ready";

stateName[1]                     = "Ready";
};

function clearAllPlayerNodes(%player)
{
%player.hideNode("headSkin");
%player.hideNode("LSki");
%player.hideNode("RSki");
%player.hideNode("skirtTrimLeft");
%player.hideNode("skirtTrimRight");
clearplayernodes(%player);
}

function clearPlayerNodes(%player)
{
if (isObject(%player))
{
for (%i = 0; $accent[%i] !$= ""; %i++) %player.hideNode($accent[%i]);
for (%i = 0; $chest[%i] !$= ""; %i++) %player.hideNode($chest[%i]);
for (%i = 0; $hat[%i] !$= ""; %i++) %player.hideNode($hat[%i]);
for (%i = 0; $hip[%i] !$= ""; %i++) %player.hideNode($hip[%i]);
for (%i = 0; $LArm[%i] !$= ""; %i++) %player.hideNode($LArm[%i]);
for (%i = 0; $LHand[%i] !$= ""; %i++) %player.hideNode($LHand[%i]);
for (%i = 0; $LLeg[%i] !$= ""; %i++) %player.hideNode($LLeg[%i]);
for (%i = 0; $pack[%i] !$= ""; %i++) %player.hideNode($pack[%i]);
for (%i = 0; $RArm[%i] !$= ""; %i++) %player.hideNode($RArm[%i]);
for (%i = 0; $RHand[%i] !$= ""; %i++) %player.hideNode($RHand[%i]);
for (%i = 0; $RLeg[%i] !$= ""; %i++) %player.hideNode($RLeg[%i]);
for (%i = 0; $secondPack[%i] !$= ""; %i++) %player.hideNode($secondPack[%i]);
}
}

function MissileRadius(%sourceObject, %position, %radius, %damage, %damageType, %impulse, %rigger)
{
%pos = VectorAdd(%position, "0 0" SPC 0.2);
new Projectile()
{
dataBlock        = "BrickdestroyerProjectile";
initialPosition  = %pos;
initialVelocity  = "0 0 -500";
sourceObject     = %rigger.player;
client = %rigger;
};
InitContainerRadiusSearch(%position, %radius, $TypeMasks::PlayerObjectType);
while ((%targetObject = containerSearchNext()) != 0) {
        %halfradius = %radius / 2;
%dist = containerSearchCurrRadiusDist();
  %distScale = (%dist < %halfRadius)? 1.0:
         1.0 - ((%dist - %halfRadius) / %halfRadius);
if(minigamecandamage(%rigger.player, %targetobject)){
        %impulseVec = VectorSub(%targetObject.getWorldBoxCenter(), %position);
          %impulseVec = VectorNormalize(%impulseVec);
          %impulseVec = VectorScale(%impulseVec, %impulse * %distScale);
          %targetObject.applyImpulse(%position, %impulseVec);
          if(%targetobject != %rigger.player){
          %targetobject.setwhiteout(1.022);
          }
}

    }
}

datablock ProjectileData(BrickdestroyerProjectile)
{
 //projectileShapeName = "./shapes/RocketProjectile.dts";
   directDamage        = 0;
   directDamageType    = $DamageType::ArrowDirect;
   radiusDamage        = 0;
   damageRadius        = 0;
   radiusDamageType    = $DamageType::ArrowDirect;
   muzzleVelocity      = 0.1;
   velInheritFactor    = 1;
   armingDelay         = 0;
   lifetime            = 200;
   fadeDelay           = 170;
   bounceElasticity    = 0;
   bounceFriction      = 0;
   isBallistic         = false;
   gravityMod = 1.0;
   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 0 0.5";
   brickExplosionRadius = 6;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 30;             
   brickExplosionMaxVolume = 30;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 60;
};

function MissileExplode(%pos)
{
new Explosion(1){
scale = "2.5 2.5 2.5";
position = %pos;
datablock = "gravityRocketExplosion";
};
new Explosion(2){
scale = "2.5 2.5 2.5";
position = %pos;
datablock = "gravityRocketExplosion";
};
}

Eew schedules, this doesn't need a schedule at all.

Eew schedules, this doesn't need a schedule at all.
Okay, so what's the code to make a projectile change direction without schedules?
Oh and also, the game itself uses plenty of schedules, and on top of that, events also use schedules.

Quote
Code: [Select]
function clearAllPlayerNodes(%player)
{
%player.hideNode("headSkin");
%player.hideNode("LSki");
%player.hideNode("RSki");
%player.hideNode("skirtTrimLeft");
%player.hideNode("skirtTrimRight");
clearplayernodes(%player);
}

function clearPlayerNodes(%player)
{
if (isObject(%player))
{
for (%i = 0; $accent[%i] !$= ""; %i++) %player.hideNode($accent[%i]);
for (%i = 0; $chest[%i] !$= ""; %i++) %player.hideNode($chest[%i]);
for (%i = 0; $hat[%i] !$= ""; %i++) %player.hideNode($hat[%i]);
for (%i = 0; $hip[%i] !$= ""; %i++) %player.hideNode($hip[%i]);
for (%i = 0; $LArm[%i] !$= ""; %i++) %player.hideNode($LArm[%i]);
for (%i = 0; $LHand[%i] !$= ""; %i++) %player.hideNode($LHand[%i]);
for (%i = 0; $LLeg[%i] !$= ""; %i++) %player.hideNode($LLeg[%i]);
for (%i = 0; $pack[%i] !$= ""; %i++) %player.hideNode($pack[%i]);
for (%i = 0; $RArm[%i] !$= ""; %i++) %player.hideNode($RArm[%i]);
for (%i = 0; $RHand[%i] !$= ""; %i++) %player.hideNode($RHand[%i]);
for (%i = 0; $RLeg[%i] !$= ""; %i++) %player.hideNode($RLeg[%i]);
for (%i = 0; $secondPack[%i] !$= ""; %i++) %player.hideNode($secondPack[%i]);
}
}

How old is this again...?

I am not a very advanced scripter, but how did you make it work, so that a playertype can go up or down at all?
I mean, you don't want to see a missile use jets, so yeah.
I couldn't find it that fast in the code.

Okay, so what's the code to make a projectile change direction without schedules?
Oh and also, the game itself uses plenty of schedules, and on top of that, events also use schedules.
He could set the client control object to a vehicle/plane that's fired as a projectile.

How old is this again...?

Aloshi's.

Yeah, I should fix some points in it, like making it simpler: hideNode("ALL")

Anyway, anyone cared to find out why it can't go up/down?

It can go up/down in first person, but it can't do left/right. On the other hand, when its in third person, it can go left/right, but it can't go up/down.

Also, the projectile image doesn't show up. I can only see the shadow.


Okay, so what's the code to make a projectile change direction without schedules?
Use a vehicle instead of a bot or standard projectile.