Author Topic: cloak and dagger duration  (Read 839 times)

the following script is to the invisible watch packs cloak and dagger item. What number on what lines would I have to change in order to increase the duration of the time being invisible and also the regeneration speed of the cloak energy


datablock AudioProfile(bknifeCloakStabSound)
{
   filename = "./bknife_cloakstab.wav";
   description = AudioClosest3d;
   preload = true;
};

datablock ItemData(SpyKnifeWatchItem)
{
   category = "Weapon";  // Mission editor category
   className = "Weapon"; // For inventory system

    // Basic Item Properties
   shapeFile = "./SpyWatchItem.dts";
   rotate = false;
   mass = 1;
   density = 0.2;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   //gui stuff
   uiName = "Cloak and Dagger";
   iconName = "./icon_iwatch";
   doColorShift = true;
   colorShiftColor = "1 0.78 0 1";

    // Dynamic properties defined by the scripts
   image = SpyKnifeWatchImage;
   canDrop = true;
   
   variableStore = "cloakEnergy";
   variableInitial = 100;
   variableReplace = 1;
};

datablock ShapeBaseImageData(SpyKnifeWatchImage)
{
   // Basic Item properties
   shapeFile = "./SpyWatchHand.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 -1000";
   eyeOffset = "0.8 0.65 -0.4";
   rotation = eulerToMatrix( "0 0 0" );
   eyeRotation = eulerToMatrix( "10 0 0" );

   className = "WeaponImage";
   item = SpyKnifeWatchItem;

   //raise your arm up or not
   armReady = false;
   
   //cloak stats
   isCloakWatch = 1;
   disableCloakActivate = 1;
   cloakDamageFlicker = 1;
   cloakChargeRate = 0.2;
   
   cloakSound = spyCloakSound;
   uncloakSound = spyUncloakSound;
   
   raycastWeaponRange = 3;
   raycastWeaponTargets = $TypeMasks::FxBrickObjectType |   //Targets the weapon can hit: Raycasting Bricks
               $TypeMasks::PlayerObjectType |   //AI/Players
               $TypeMasks::StaticObjectType |   //Static Shapes
               $TypeMasks::TerrainObjectType |   //Terrain
               $TypeMasks::VehicleObjectType;   //Vehicles
   raycastExplosionProjectile = bKnifeProjectile;
   raycastExplosionSound = "";
   raycastExplosionPlayerSound = "";
   raycastExplosionBrickSound = "";
   raycastDirectDamage = 1; //maxhp * 6
   raycastDirectDamageType = $DamageType::KnifeStab;

   doColorShift = true;
   colorShiftColor = SpyKnifeWatchItem.colorShiftC olor;

   // Initial start up state
   stateName[0]                     = "Activate";
   stateTimeoutValue[0]             = 0.2;
   stateTransitionOnTimeout[0]      = "CloakUse";
   stateSound[0]                    = weaponSwitchSound;
   
   //generic cloak + uncloak states
   
   stateName[1]                     = "CloakUse";
   stateScript[1]                   = "onCloakUse";
   stateTransitionOnAmmo[1]         = "Cloaking";
   stateTransitionOnTimeout[1]      = "CloakUse";
   stateWaitForTimeout[1]           = 0;
   stateTimeoutValue[1]             = "0.05";
   stateAllowImageChange[1]         = true;
   stateSequence[1]                 = "Ready";
   
   stateName[2]                     = "Cloaking";
   stateTransitionOnNoAmmo[2]       = "Uncloak";
   stateAllowImageChange[2]         = true;
   stateSequence[2]                 = "Cloaking";
   stateTimeoutValue[2]             = 1;
   stateTransitionOnTimeout[2]      = "Cloaked";
   
   stateName[3]                     = "Cloaked";
   stateTransitionOnTriggerDown[3]  = "KnifeStart";
   stateTransitionOnNoAmmo[3]       = "DeCloakCheckA";
   stateTransitionOnTimeout[3]      = "Cloaked";
   stateTimeoutValue[3]             = 0.05;
   stateWaitForTimeout[3]           = false;
   stateScript[3]                   = "onCloakCheck";
   stateAllowImageChange[3]         = true;
   stateSequence[3]                 = "FullyCloaked";
   
   stateName[4]                     = "Uncloak";
   stateTransitionOnAmmo[4]         = "Cloaking";
   stateAllowImageChange[4]         = true;
   stateSequence[4]                 = "Uncloaking";
   stateTimeoutValue[4]             = 1;
   stateTransitionOnTimeout[4]      = "CloakUse";
   
   //knife fire states
   
   stateName[5]                     = "KnifeStart";
   stateScript[5]                   = "onKnifeStart";
   stateTransitionOnTimeout[5]      = "KnifeLift";
   stateTimeoutValue[5]             = 0.4;
   
   stateName[6]                     = "KnifeLift";
   stateScript[6]                   = "onKnifeLift";
   stateTransitionOnTimeout[6]      = "KnifeFire";
   stateTimeoutValue[6]             = 0.7;
   
   stateName[7]                     = "KnifeFire";
   stateScript[7]                   = "onFire";
   stateTransitionOnTimeout[7]      = "KnifeEnd";
   stateTimeoutValue[7]             = 0.6;
   
   stateName[8]                     = "KnifeEnd";
   stateTransitionOnTimeout[8]      = "Cloaked";
   stateTimeoutValue[8]             = 0.1;
   stateWaitForTimeout[8]           = 0;
   stateScript[8]                   = "onKnifeEnd";
   
   //out of energy + decloak states
   
   stateName[9]                     = "DecloakCheckA";
   stateTransitionOnTimeout[9]      = "DecloakCheckB";
   stateTimeoutValue[9]             = 0.01;
   stateSequence[9]                 = "FullyCloaked";
   stateScript[9]                   = "onDecloakCheck";
   
   stateName[10]                    = "DecloakCheckB";
   stateSequence[10]                = "FullyCloaked";
   stateTransitionOnNoAmmo[10]      = "Decloaking";
   stateTransitionOnAmmo[10]        = "UncloakState";
   stateWaitForTimeout[10]          = 0;
   
   stateName[11]                    = "Decloaking";
   stateSequence[11]                = "Decloaking";
   stateTimeoutValue[11]            = 0.3;
   stateTransitionOnTriggerDown[11] = "KnifeStart";
   stateTransitionOnTimeout[11]     = "Decloaked";
   
   stateName[12]                    = "Decloaked";
   stateTransitionOnTriggerDown[12]  = "KnifeStart";
   stateTransitionOnAmmo[12]        = "Recloaking";
   stateTransitionOnTimeout[12]     = "DecloakedNext";
   stateTimeoutValue[12]            = 0.05;
   stateAllowImageChange[12]        = true;
   stateSequence[12]                = "Decloaked";
   stateScript[12]                  = "onCloakCheck";
   
   stateName[13]                    = "DecloakedNext";
   stateTransitionOnNoAmmo[13]      = "UncloakCheckA";
   
   stateName[14]                    = "Recloaking";
   stateSequence[14]                = "Recloaking";
   stateTransitionOnTriggerDown[14] = "KnifeStart";
   stateTimeoutValue[14]            = 0.3;
   stateTransitionOnTimeout[14]     = "Cloaked";
   
   stateName[15]                    = "UncloakState";
   stateScript[15]                  = "setNoAmmo";
   stateTimeoutValue[15]            = 0.01;
   stateTransitionOnTimeout[15]     = "Uncloak";
   
   stateName[16]                    = "UncloakCheckA";
   stateTransitionOnTimeout[16]     = "UncloakCheckB";
   stateTimeoutValue[16]            = 0.01;
   stateScript[16]                  = "onDecloakCheck";
   
   stateName[17]                    = "UncloakCheckB";
   stateTransitionOnAmmo[17]        = "UncloakState";
   stateTransitionOnNoAmmo[17]      = "Decloaked";
   stateWaitForTimeout[17]           = 0;
};

datablock ShapeBaseImageData(SpyKnifeWatchStabImage)
{
   // Basic Item properties
   shapeFile = ($TF2Knife::AltModels ? "Add-Ons/Weapon_ButterflyKnife/bknife2.dts" : "Add-Ons/Weapon_TF2ButterflyKnife/knife.dts");
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0.1 0.05";
   eyeOffset = "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 = false;
   
   eyeOffset = "";
   
   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";
   
   // Projectile && Ammo.
   item = bKnifeItem;
   ammo = " ";
   projectile = bKnifeProjectile;
   projectileType = Projectile;
   
   //melee particles shoot from eye node for consistancy
   melee = true;
   doRetraction = false;
   //raise your arm up or not
   armReady = false;
   
   //casing = " ";
   doColorShift = true;
   colorShiftColor = ($TF2Knife::AltModels ? "0.400 0.196 0 0.5" : "0.3 0.3 0.3 0.5");
   
   // 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";
   stateSequence[0]      = "ready";
   
   stateName[1]         = "Ready";
};

datablock ShapeBaseImageData(SpyKnifeWatchHiddenImage : SpyKnifeWatchStabImage)
{
   armReady = false;
   
   doColorShift = true;
   colorShiftColor = "0.3 0.3 0.3 0.2";
   
   stateSequence[0]      = "activate";
   
   offset = "0 0 -1000";
   eyeOffset = "0.5 0.8 -0.5";
};

function SpyKnifeWatchImage::onMount(%this,%obj,%slot)
{
   Parent::onMount(%this,%obj,%slot);
   
   %obj.setImageAmmo(%slot,0);
   %obj.currKnifeSlot = %obj.currTool;
   
   if(!%obj.isCloaking)
   {
      %obj.cloakEnergy = %obj.cloakEnergy + 20*%this.cloakChargeRate*(getSimTime()-%obj.lastUnCloakTime)/1000;
      %obj.lastUnCloakTime = getSimTime();
   }
   
   if(%obj.cloakEnergy > 100) %obj.cloakEnergy = 100;
   if(%obj.cloakEnergy < 0) %obj.cloakEnergy = 0;
   
   if(isObject(%obj.client))
   {
      %a = %obj.cloakEnergy;
      %b = 100;
      %start = "<color:FFFFFF>";
      %sep = "<color:111111>";
      %done = (%a >= %b) || (%a == 0);
      %end = (%a / %b) * 25;
      %str = (%a == 0 ? %sep : %start);
     
      for(%i=0;%i<25;%i++)
      {
         if(%i > %end && !%done)
         {
            %str = %str @ %sep;
            %done = 1;
         }
         %str = %str @ "|";
      }
      bottomprint(%obj.client, "<just:center>" @ %str, 2, 1);
   }
}

function SpyKnifeWatchImage::onUnMount(%this,%obj,%slot)
{
   Parent::onUnMount(%this,%obj,%slot);
   
   %obj.unMountImage(1);
   
   if(%obj.usingKnife)
   {
      if(isObject(%obj.client))
         %obj.client.setControlObject(%obj);
      %obj.noChangeTools = 0;
      %obj.usingKnife = 0;
   }
}

function SpyKnifeWatchImage::onCloakUse(%this,%obj,%slot)
{
   //put arm down since it's invisible from outside
   //
   %obj.playThread(1, armReadyRight);
   
   if(!%obj.isCloaked && !%obj.isCloaking)
   {
      %obj.beginCloak(%this);
      if(isObject(%obj.client))
         %obj.client.play2d(bKnifeUseSound);
      %obj.mountImage(SpyKnifeWatchHiddenImage, 1);
      %obj.cloakShowing = 0;
      cancel(%obj.cloakSched);
   }
}

function SpyKnifeWatchImage::onCloakCheck(%this,%obj,%slot)
{
   if(%obj.getState() $= "Dead")
      return;
   
   if(%obj.cloakEnergy <= 0.5)
   {
      if(isObject(%obj.client))
      {
         if(isObject(%obj.client.minigame) && %obj.client.tdmTeam != -1 && %obj.client.tdmteam !$= "")
            %col = getColorIDTable(%obj.client.minigame.teamCol[%obj.client.tdmTeam]);
         else
            %col = %obj.client.chestColor;
      }
      else
         %col = "1 1 1 1";
     
      %obj.cloakShowing = 1;
      %obj.unHideNode("ALL");
      %obj.setImageAmmo(%slot,0);
     
      if(isObject(%obj.client))
      {
         %obj.client.applyBodyParts();
         %obj.client.applyBodyColors();
      }
      else
         applyDefaultCharacterPrefs(%obj);
     
      %obj.setNodeColor("ALL",getWords(%col,0,2) SPC 0.5);
   }
   else
   {
      if(%obj.cloakShowing)
         %obj.hideNode("ALL");
      %obj.cloakShowing = 0;
      %obj.setImageAmmo(%slot,1);
   }
   
   %l = vectorLen(%obj.getVelocity());
   if(%l <= 0.1)
      %obj.cloakEnergy += 0.3;
   else
      %obj.cloakEnergy -= 0.25*%l/1.5;
   
   if(%obj.cloakEnergy > 100) %obj.cloakEnergy = 100;
   if(%obj.cloakEnergy < 0) %obj.cloakEnergy = 0;
   
   if(isObject(%obj.client))
   {
      %a = %obj.cloakEnergy;
      %b = 100;
      %start = "<color:FFFFFF>";
      %sep = "<color:111111>";
      %done = (%a >= %b) || (%a == 0);
      %end = (%a / %b) * 25;
      %str = (%a == 0 ? %sep : %start);
     
      for(%i=0;%i<25;%i++)
      {
         if(%i > %end && !%done)
         {
            %str = %str @ %sep;
            %done = 1;
         }
         %str = %str @ "|";
      }
      bottomprint(%obj.client, "<just:center>" @ %str, 2, 1);
   }
}
function SpyKnifeWatchImage::onKnifeStart(%this,%obj,%slot)
{
   %obj.noChangeTools = 1;
   %obj.usingKnife = 1;
   if(%obj.cloakEnergy <= 0.5)
      %obj.cloakEnergy = 1;
   else
   {
      %obj.unHideNode("ALL");
      if(isObject(%obj.client))
      {
         %obj.client.applyBodyParts();
         %obj.client.applyBodyColors();
         if(isObject(%obj.client.minigame) && %obj.client.tdmTeam != -1 && %obj.client.tdmTeam !$= "")
            %col = getColorIDTable(%obj.client.minigame.teamCol[%obj.client.tdmTeam]);
         else
            %col = %obj.client.chestColor;
      }
      else
      {
         %col = "1 1 1 1";
         applyDefaultCharacterPrefs(%obj);
      }
      %hand = (%obj.isNodeVisible(rhand));
      %obj.hideNode("ALL");
   
      if(%hand)
      {
         %obj.unHideNode(rhand);
         %obj.setNodeColor(rhand,getWords(%col,0,2) SPC 0.3);
      }
      else
      {
         %obj.unHideNode(rhook);
         %obj.setNodeColor(rhook,getWords(%col,0,2) SPC 0.3);
      }
   }
   if(isObject(%obj.client))
   {
      if(isObject(%obj.client.camera) && %obj.client.getcontrolobject() == %obj)
      {
         %transform = %obj.getTransform();
         %obj.client.camera.setOrbitMode(%obj, %transform, 0.5, 8, 8, 1);
         %obj.client.camera.mode = "Orbit";
         %obj.client.setControlObject(%obj.client.camera);
      }
   }

   %obj.setImageAmmo(%slot,1);
   
   %obj.mountImage(SpyKnifeWatchStabImage, 1);
}

function SpyKnifeWatchImage::onKnifeLift(%this,%obj,%slot)
{
   %obj.playThread(2, spearReady);
}

function SpyKnifeWatchImage::onFire(%this,%obj,%slot)
{
   %obj.playThread(2, spearThrow);
   Parent::onFire(%this,%obj,%slot);
   serverPlay3d(bknifeCloakStabSound,%obj.getPosition());
}

function SpyKnifeWatchImage::onKnifeEnd(%this,%obj,%slot)
{
   //fixArmReady(%obj);
   %obj.hideNode(rhand);
   %obj.hideNode(rhook);
   %obj.mountImage(SpyKnifeWatchHiddenImage, 1);
   if(isObject(%obj.client))
      %obj.client.setControlObject(%obj);
   %obj.noChangeTools = 0;
   %obj.usingKnife = 0;
   
   if(%obj.currTool != %obj.currKnifeSlot)
   {
      if(%obj.currTool != -1)
         servercmdUseTool(%obj.client,%obj.currTool);
      else
         servercmdUnUseTool(%obj.client);
   }
}

function SpyKnifeWatchImage::onRaycastDamage(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
   %damageType = $DamageType::Direct;
   if(%this.raycastDirectDamageType)
      %damageType = %this.raycastDirectDamageType;
   
   %scale = getWord(%obj.getScale(), 2);
   %colscale = getWord(%col.getScale(),2);
   
   %directDamage = %colScale * %col.dataBlock.maxDamage * 6;
   %col.spawnExplosion(critProjectile,%colscale);
   if(isObject(%col.client))
      %col.client.play2d(critRecieveSound);
   
   if(isObject(%obj.client))
      %obj.client.play2d(critHitSound);
     
   %col.setVelocity(vectorAdd(%col.getVelocity(),vectorAdd(vectorScale(%obj.getForwardVector(),20),"0 0 10")));
   %col.schedule(0,damage,%obj, %pos, %directDamage, %damageType);
}

function SpyKnifeWatchImage::onDecloakCheck(%this,%obj,%slot)
{
   %obj.setImageAmmo(%slot,%obj.isCloaking);
}

function SpyKnifeWatchImage::setNoAmmo(%this,%obj,%slot)
{
   %obj.setImageAmmo(%slot,0);
}

Let me know when you find out, I've been trying to find this too...


Changing
Code: [Select]
   if(%l <= 0.1)
      %obj.cloakEnergy += 0.3;
   else
      %obj.cloakEnergy -= 0.25*%l/1.5;
to
Code: [Select]
   if(%l <= 0.1)
      %obj.cloakEnergy += 0.5;
   else
      %obj.cloakEnergy -= 0.1*%l/1.5;
would increase the rate of cloak energy recovery, and decrease the rate of cloak energy loss when cloaked. These aren't exemplar values, you should probably fine-tune them to your liking.