Cloaking Mine Tutorial by: --Drumstix42 ____________________________________________________________ ------------------------------------------------------------ Note: Much credit goes to Ivo Robotnik for creating the code for this mine. Tutorial created by me. ------------------------------------------------------------ This tut is pretty easy. Not much editing needed. Only need to add things. I always recommend to use Tribal IDE. ____________________________________________________________ Step #1: First in your scripts/weapons folder create a file called cloakmine.cs , You will then need to copy all this code into the your newly creat cloakmine file.- //---------------------------------------- // Cloak Mine Code by Ivo Robotnik // Robotnik: The mine items themselves. //---------------------------------------- datablock ItemData(CloakMineDeployed) { className = Weapon; shapeFile = "mine.dts"; mass = 0.75; elasticity = 0.2; friction = 0.6; pickupRadius = 3; maxDamage = 0.2; explosion = MineExplosion; underwaterExplosion = UnderwaterMineExplosion; indirectDamage = 0.55; damageRadius = 6.0; radiusDamageType = $DamageType::Mine; kickBackStrength = 1500; aiAvoidThis = false; dynamicType = $TypeMasks::DamagableItemObjectType; spacing = 6.0; // how close together mines can be proximity = 2.5; // how close causes a detonation (by player/vehicle) armTime = 2200; // 2.2 seconds to arm a mine after it comes to rest maxDepCount = 9; // try to deploy this many times before detonating computeCRC = true; }; datablock ItemData(CloakMine) { className = HandInventory; catagory = "Handheld"; shapeFile = "ammo_mine.dts"; mass = 1; elasticity = 0.2; friction = 0.7; pickupRadius = 2; thrownItem = CloakMineDeployed; pickUpName = "some cloaking mines"; computeCRC = true; }; //------------------------------------------ // Code that drives the mines. //------------------------------------------- function cloakMine(%mine) { %mine.setCloaked(true); } function CloakMineDeployed::onThrow(%this, %mine, %thrower) { %mine.armed = false; %mine.damaged = 0; %mine.detonated = false; %mine.depCount = 0; %mine.theClient = %thrower.client; schedule(1500, %mine, "cloakMine", %mine, %thrower); schedule(1500, %mine, "deployMineCheck", %mine, %thrower); } function CloakMineDeployed::onDestroyed(%data, %obj, %lastState) { %obj.boom = true; %mineTeam = %obj.team; $TeamDeployedCount[%mineTeam, MineDeployed]--; // %noDamage is a boolean flag -- don't want to set off all other mines in // vicinity if there's a "mine overload", so apply no damage/impulse if true if(!%obj.noDamage) RadiusExplosion(%obj, %obj.getPosition(), %data.damageRadius, %data.indirectDamage, %data.kickBackStrength, %obj.sourceObject, %data.radiusDamageType); %obj.schedule(600, "delete"); } function CloakMineDeployed::damageObject(%data, %targetObject, %sourceObject, %position, %amount, %damageType) { if(!%targetObject.armed) return; if(%targetObject.boom) return; %targetObject.damaged += %amount; if(%targetObject.damaged >= %data.maxDamage) { %targetObject.setDamageState(Destroyed); } } function CloakMineDeployed::onCollision(%data, %obj, %col) { // don't detonate if mine isn't armed yet if(!%obj.armed) return; // don't detonate if mine is already detonating if(%obj.boom) return; //check to see what it is that collided with the mine %struck = %col.getClassName(); if(%struck $= "Player" || %struck $= "WheeledVehicle" || %struck $= "FlyingVehicle") { //error("Mine detonated due to collision with #"@%col@" ("@%struck@"); armed = "@%obj.armed); explodeMine(%obj, false); } } //End of File ------------------------------------------------------------------------------------ Step #2 Now in your scripts folder, open up the Hud.cs file. Now do a search for $InventoryHudData and scroll down to the bottom of the list. 2a) Now add this too the list (rember to change number to fit correctly) : $InventoryHudData[8, bitmapName] = "gui/hud_mine"; $InventoryHudData[8, itemDataName] = CloakMine; $InventoryHudData[8, ammoDataName] = CloakMine; $InventoryHudData[8, slot] = 1; 2b) Now change the $InventoryHudCount to the correct number (i.e.-If you left the other number at 8 in the $InventoryHudData list then you would change the $InventoryHudCount to look like this: $InventoryHudCount = 9; ------------------------------------------------------------------------------------ Step #3 Now open up your Inventory.cs script file. 3a) First do a search for- function ShapeBase::clearInventory(%this) You should then get something that starts out like this: function ShapeBase::clearInventory(%this) { %this.setInventory(RepairKit,0); %this.setInventory(Mine,0); //%this.setInventory(MineAir,0); //%this.setInventory(MineLand,0); //%this.setInventory(MineSticky,0); %this.setInventory(Grenade,0); %this.setInventory(FlashGrenade,0); %this.setInventory(ConcussionGrenade,0); %this.setInventory(FlareGrenade,0); %this.setInventory(CameraGrenade, 0); 3b) Now look at where it says- %this.setInventory(Mine,0); (which is located near the top of the function) You need to add this directly below that: %this.setInventory(CloakMine,0); So, you should turn out with your code looking like this: function ShapeBase::clearInventory(%this) { %this.setInventory(RepairKit,0); %this.setInventory(Mine,0); %this.setInventory(CloakMine,0); //%this.setInventory(MineAir,0); //%this.setInventory(MineLand,0); //%this.setInventory(MineSticky,0); %this.setInventory(Grenade,0); %this.setInventory(FlashGrenade,0); %this.setInventory(ConcussionGrenade,0); %this.setInventory(FlareGrenade,0); %this.setInventory(CameraGrenade, 0); 3c) Now we need to do the same thing for another function. Search for this- function serverCmdGiveAll(%client) Now add this directly under %player.setInventory(Mine,999); near the top of function. %player.setInventory(CloakMine,999); You should end up with something like this: function serverCmdGiveAll(%client) { if($TestCheats) { %player = %client.player; %player.setInventory(RepairKit,999); %player.setInventory(Mine,999); %player.setInventory(CloakMine,999); //%player.setInventory(MineAir,999); //%player.setInventory(MineLand,999); //%player.setInventory(MineSticky,999); %player.setInventory(Grenade,999); %player.setInventory(FlashGrenade,999); %player.setInventory(FlareGrenade,999); %player.setInventory(ConcussionGrenade,999); %player.setInventory(CameraGrenade, 999); ------------------------------------------------------------------------------------ Step #4 Open up your inventoryHud.cs script. Add this code to the corresponding list for mines: $InvMine[1] = "Cloaking Mine"; Then add this to the list right below that: $NameToInv["Cloaking Mine"] = "CloakMine"; Remember to set numbers correctly... ------------------------------------------------------------------------------------ Step #5 (almost done) Now open up your player.cs script. Now add this code to each armor you would like to be able to cary cloaking mines. max[CloakMine] = 3; I suggest to place this directly under max[Mine] in the //inventory restrictions. You may also change the number to what ever you desire. If you do not want an armor to have it. Use this: max[CloakMine] = 0; Next, do a search for %player.mineTimer = 0; You'll find this: { %player.use(Mine); %player.mineTimer = 0; } Now replace it with this: { if (%player.getInventory("CloakMine") > 0) { %player.use(CloakMine); } else %player.use(Mine); %player.mineTimer = 0; } After you add the code you'll end up with the script looking like this: // Bad throw for some reason } else { if (%player.getInventory("CloakMine") > 0) // These lines { // make the %player.use(CloakMine); // game think } // cloakmines else // are normal %player.use(Mine); // mines %player.mineTimer = 0; } } } I also showed surrounding code so you could make sure you put it in the correct place. ------------------------------------------------------------------------------------ Step #6 Now open up StationSetInv When you open this up you'll see list of basically the same thing for each armor. For each armor you'll need to add code directly under this: %player.setInventory(Mine,3); The code you need to add is this: %player.setInventory(CloakMine,3); So it will look like this all together for the first occurence: %player.setInventory(RepairKit,1); %player.setInventory(Mine,3); %player.setInventory(CloakMine,3); %player.setInventory(Grenade,6); %player.setInventory(Blaster,1); %player.setInventory(Plasma,1); %player.setInventory(Disc,1); %player.setInventory(Chaingun, 1); %player.setInventory(GrenadeLauncher, 1); %player.setInventory(GrenadeLauncherAmmo, 25); %player.setInventory(PlasmaAmmo,20); %player.setInventory(ChaingunAmmo, 100); %player.setInventory(DiscAmmo, 20); You'll need to add the code 9 times in total. ------------------------------------------------------------------------------------ Step #7 (The final step) Woohoo! Open up your weapons scripts. 7a)Search for- $AmmoIncrement[Mine] = 3; You'll get an ammoincreasment list. Add this code directly under the mine array: $AmmoIncrement[CloakMine] = 3; So when added, the list will look like this: $AmmoIncrement[PlasmaAmmo] = 10; $AmmoIncrement[ChaingunAmmo] = 25; $AmmoIncrement[DiscAmmo] = 5; $AmmoIncrement[GrenadeLauncherAmmo] = 5; $AmmoIncrement[MortarAmmo] = 5; $AmmoIncrement[MissileLauncherAmmo] = 2; $AmmoIncrement[Mine] = 3; $AmmoIncrement[CloakMine] = 3; $AmmoIncrement[Grenade] = 5; $AmmoIncrement[FlashGrenade] = 5; $AmmoIncrement[FlareGrenade] = 5; $AmmoIncrement[ConcussionGrenade] = 5; $AmmoIncrement[RepairKit] = 1; 7b) Now search for: // --- Throwing weapons You should get a list of exec files. Add this under the mine one: exec("scripts/weapons/cloakmine.cs"); After code is added, you should have this: // --- Throwing weapons exec("scripts/weapons/mine.cs"); exec("scripts/weapons/cloakmine.cs"); exec("scripts/weapons/grenade.cs"); exec("scripts/weapons/flashGrenade.cs"); exec("scripts/weapons/flareGrenade.cs"); exec("scripts/weapons/concussionGrenade.cs"); exec("scripts/weapons/cameraGrenade.cs"); ------------------------------------------------------------------ Congratulations! You have reached the end of this tutorial and hopefully suceeded in adding a cloaking mine to your mod. Woohoo! If you have any question or are uncertain about something e-mail me at Drumstix42@aol.com I hope you enjoy your cloaking mine. And dont for get: Credit goes to : Ivo Robotnik -for a great, working cloaking mine!