Tut by -Defender 4-26-2002 This tut will make a Cloaking Device, that has been tested, and will not lag out your server like the ones posted in the forums in the past... Thanks to BadShot for making the code so we could use it. this is all from his mass cloak tutorial... at http://www.mage-tower.com/BadShot/ First in inventoryhud.cs, add this to the appropriate(sp) arrays: Code: -------------------------------------------------------------------------------- Step# 1 $InvPack[38] = "Depl- Cloaking Device"; $NameToInv["Depl- Cloaking Device"] = "CloakingDeviceDeployable"; -------------------------------------------------------------------------------- Step# 2 Dont forget to increase or decrease the numbers. Now, in hud.cs, find the $BackpackHudData array and add this in : Code: -------------------------------------------------------------------------------- $BackpackHudData[34, itemDataName] = "CloakingDeviceDeployable"; $BackpackHudData[34, bitmapName] = "gui/hud_new_packinventory"; -------------------------------------------------------------------------------- Step# 3 Remember, don't forget to change the right numbers. In defaultgame.cs, add this to the right array : Code: -------------------------------------------------------------------------------- $TeamDeployedCount[%i, CloakingDeviceDeployable] = 0; -------------------------------------------------------------------------------- Step# 4 In player.cs, add this to your armor datablocks : max[CloakingDeviceDeployable] = 1; If you don't want that armor ot have it, change the one to a zero. In deployables.cs, add this: Code: -------------------------------------------------------------------------------- $TeamDeployableMax[CloakingDeviceDeployable] = 8; -------------------------------------------------------------------------------- Step# 5 copy and past all this code to the bottom of the deployables.cs -------------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Cloaking deployable Device made by Defender // // Cloaking code by BadShot.. //-------------------------------------- datablock SensorData(DeployCloakingDeviceObj) { detects = true; detectsUsingLOS = false; detectsActiveJammed = true; detectsPassiveJammed = true; detectsCloaked = true; detectionPings = true; detectMinVelocity = 0.5; detectRadius = 15; jams = true; jamsOnlyGroup = true; jamsUsingLOS = false; jamRadius = 15; }; datablock StaticShapeData(DeployedCloakingDevice) : StaticShapeDamageProfile { className = Sensor; shapeFile = "deploy_sensor_motion.dts"; maxDamage = 0.6; destroyedLevel = 0.6; disabledLevel = 0.6; explosion = DeployablesExplosion; dynamicType = $TypeMasks::SensorObjectType; deployedObject = true; cmdCategory = "DSupport"; cmdIcon = CMDSensorIcon; cmdMiniIconName = "commander/MiniIcons/com_deploymotionsensor"; targetNameTag = 'Cloaking Device>'; targetTypeTag = 'Code by: BadShot'; sensorData = DeployCloakingDeviceObj; sensorRadius = DeployCloakingDeviceObj.detectRadius; sensorColor = "255 0 255"; deployAmbientThread = true; debrisShapeName = "debris_generic_small.dts"; debris = DeployableDebris; heatSignature = 0; isShielded = true; energyPerDamagePoint = 75; maxEnergy = 25; rechargeRate = 0.45; doesRepair = true; beacon = true; BeaconType = friend; cloakOthers = true; // BadShot cloakRadius = 30; //adjust for radius you want }; datablock ShapeBaseImageData(CloakingDeviceImage) { shapeFile = "pack_deploy_sensor_motion.dts"; item = CloakingDeviceDeployable; mountPoint = 1; offset = "0 0 0"; deployed = DeployedCloakingDevice; stateName[0] = "Idle"; stateTransitionOnTriggerDown[0] = "Activate"; stateName[1] = "Activate"; stateScript[1] = "onActivate"; stateTransitionOnTriggerUp[1] = "Idle"; maxDepSlope = 360; deploySound = MotionSensorDeploySound; emap = true; heatSignature = 1; minDeployDis = 0.5; maxDeployDis = 5.0; //meters from body }; datablock ItemData(CloakingDeviceDeployable) { className = Pack; catagory = "Deployables"; shapeFile = "pack_deploy_sensor_motion.dts"; mass = 2.0; elasticity = 0.2; friction = 0.6; pickupRadius = 1; rotate = false; image = "CloakingDeviceImage"; pickUpName = "a cloaking device"; computeCRC = true; emap = true; heatSignature = 0; maxSensors = 1; }; //-------------------------------------------------------------------------- // Functions //-------------------------------------- function CloakingDeviceImage::onDeploy(%item, %plyr, %slot) { %searchRange = 5.0; %mask = $TypeMasks::StationObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::TurretObjectType | $TypeMasks::InteriorObjectType; %eyeVec = %plyr.getEyeVector(); %eyeTrans = %plyr.getEyeTransform(); %eyePos = posFromTransform(%eyeTrans); %nEyeVec = VectorNormalize(%eyeVec); %scEyeVec = VectorScale(%nEyeVec, %searchRange); %eyeEnd = VectorAdd(%eyePos, %scEyeVec); %searchResult = containerRayCast(%eyePos, %eyeEnd, %mask, 0); if(!%searchResult ) { messageClient(%plyr.client, 'MsgCDNoObj', 'cloaking device must place on an object.'); return 0; } %terrPt = posFromRaycast(%searchResult); %terrNrm = normalFromRaycast(%searchResult); %intAngle = getTerrainAngle(%terrNrm); %rotAxis = vectorNormalize(vectorCross(%terrNrm, "0 0 1")); if (getWord(%terrNrm, 2) == 1 || getWord(%terrNrm, 2) == -1) %rotAxis = vectorNormalize(vectorCross(%terrNrm, "0 1 0")); %rotation = %rotAxis @ " " @ %intAngle; %plyr.unmountImage(%slot); %plyr.decInventory(%item.item, 1); %deplObj = new StaticShape() { dataBlock = %item.deployed; position = VectorAdd(%terrPt, VectorScale(%terrNrm, 0.03)); rotation = %rotation; }; %deplObj.team = %plyr.client.team; %deplObj.owner = %plyr.client; %deplObj.setOwnerClient(%plyr.client); if(%deplObj.getTarget() != -1) setTargetSensorGroup(%deplObj.getTarget(), %plyr.client.team); addToDeployGroup(%deplObj); AIDeployObject(%plyr.client, %deplObj); serverPlay3D(%item.deploySound, %deplObj.getTransform()); $TeamDeployedCount[%plyr.team, %item.item]++; %deplObj.deploy(); %deplObj.playThread($AmbientThread, "ambient"); //%deplObj.schedule(1000, "setCloaked", true); MissionCleanup.add(%deplObj); //return %deplObj; //CloakAction(%deplObj); } function CloakingDeviceDeployable::onPickup(%this, %obj, %shape, %amount) { // created to prevent console errors } function DeployedCloakingDevice::onDestroyed(%this, %obj, %prevState) { Parent::onDestroyed(%this, %obj, %prevState); $TeamDeployedCount[%obj.team, CloakingDeviceDeployable]--; %obj.schedule(300, "delete"); } -------------------------------------------------------------------------------- Step# 6 Now we need to add this function, to the bottom of the CloakingPack, in the packs folder.. this is the code that cloaks- code by BadShot. in the next step we will need to add 2 things in the server.cs that set the CloakLoop.. and remove as the client drops.. if this is not added the CloakLoop will lag your mod.... This will change your cloaking pack from cloaking just self, to cloaking every player, deployable and vehicle within 30 meters of you while it's activated. It also allows for deployables or beacons to do the same. To make a deployable or beacon cloak others, add these two lines to its datablock: cloakOthers = true; cloakRadius = 30; //adjust for radius you want //**************************************************************************************** // function CloakLoop- code by -BadShot //**************************************************************************************** function CloakLoop() { %packradius = 5; //Radius of cloaking pack mass cloak if (!(isObject(MissionCleanup))) { schedule(10000, 0, "StartCloakLoop"); return; } %dep = nameToID("MissionCleanup/Deployables"); %count = ClientGroup.getCount(); %count2 = %dep.getCount(); %count3 = MissionCleanup.getCount(); for (%i=0;%i<%count;%i++) { ClientGroup.getObject(%i).shouldCloak = 0; } for (%i=0;%i<%count2;%i++) { %dep.getObject(%i).shouldCloak = 0; } for (%i=0;%i<%count3;%i++) { %obj = MissionCleanup.getObject(%i); if (%obj.getType() & $TypeMasks::VehicleObjectType) %obj.shouldCloak = 0; } for (%i=0;%i<%count;%i++) { %obj = ClientGroup.getObject(%i).player; if(%obj) { if ((%obj.getMountedImage($BackpackSlot) $= CloakingPackImage.getID()) && (%obj.getImageState($BackpackSlot) $= "activate")) { %obj.client.shouldCloak = 1; %pos = %obj.getPosition(); for(%i2=0;%i2<%count;%i2++) //Pack cloaks players { %obj2 = ClientGroup.getObject(%i2).player; if ((%obj2) && (%obj2 != %obj) && (%obj2.team == %obj.team)) { %pos2 = %obj2.getPosition(); if (VectorDist(%pos, %pos2) < %packradius) %obj2.client.shouldCloak = 1; } } for(%i2=0;%i2<%count2;%i2++) //Pack cloaks deployables { %obj2 = %dep.getObject(%i2); if ((%obj2) && (%obj2 != %obj) && (%obj2.team == %obj.team)) { %pos2 = posFromTransform(%obj2.getTransform()); if (VectorDist(%pos, %pos2) < %packradius) %obj2.shouldCloak = 1; } } for (%i2=0;%i2<%count3;%i2++) //Pack cloaks vehicles { %obj2 = MissionCleanup.getObject(%i2); if ((%obj2.getType() & $TypeMasks::VehicleObjectType) && (%obj2.team == %obj.team)) { %pos2 = posFromTransform(%obj2.getTransform()); if (VectorDist(%pos, %pos2) < %packradius) %obj2.shouldCloak = 1; } } } } } for (%i=0;%i<%count2;%i++) { %obj = %dep.getObject(%i); if (isObject(%obj)) { %data = %obj.getDataBlock(); if ((%data.cloakOthers) && (%obj.getDamageState() $= "Enabled")) { %pos = posFromTransform(%obj.getTransform()); for(%i2=0;%i2<%count;%i2++) //Deployables cloak players { %obj2 = ClientGroup.getObject(%i2).player; if ((%obj2) && (%obj2 != %obj) && (%obj2.team == %obj.team)) { %pos2 = %obj2.getPosition(); if (VectorDist(%pos, %pos2) < %data.cloakRadius) %obj2.client.shouldCloak = 1; } } for(%i2=0;%i2<%count2;%i2++) //Deployables cloak deployables { %obj2 = %dep.getObject(%i2); if ((%obj2) && (%obj2 != %obj) && (%obj2.team == %obj.team)) { %pos2 = posFromTransform(%obj2.getTransform()); if (VectorDist(%pos, %pos2) < %data.cloakRadius) %obj2.shouldCloak = 1; } } for (%i2=0;%i2<%count3;%i2++) //Deployables cloak vehicles { %obj2 = MissionCleanup.getObject(%i2); if ((%obj2.getType() & $TypeMasks::VehicleObjectType) && (%obj2.team == %obj.team)) { %pos2 = posFromTransform(%obj2.getTransform()); if (VectorDist(%pos, %pos2) < %data.cloakRadius) %obj2.shouldCloak = 1; } } } } } for (%i=0;%i<%count3;%i++) { %obj = MissionCleanup.getObject(%i); if (%obj.getType() & $TypeMasks::SensorObjectType) { %data = %obj.getDataBlock(); if ((%data.cloakOthers) && (%obj.getDamageState() $= "Enabled")) { %pos = posFromTransform(%obj.getTransform()); for(%i2=0;%i2<%count;%i2++) //Beacons cloak players { %obj2 = ClientGroup.getObject(%i2).player; if ((%obj2) && (%obj2 != %obj) && (%obj2.team == %obj.team)) { %pos2 = %obj2.getPosition(); if (VectorDist(%pos, %pos2) < %data.cloakRadius) %obj2.client.shouldCloak = 1; } } for(%i2=0;%i2<%count2;%i2++) //Beacons cloak deployables { %obj2 = %dep.getObject(%i2); if ((%obj2) && (%obj2 != %obj) && (%obj2.team == %obj.team)) { %pos2 = posFromTransform(%obj2.getTransform()); if (VectorDist(%pos, %pos2) < %data.cloakRadius) %obj2.shouldCloak = 1; } } for (%i2=0;%i2<%count3;%i2++) //Beacons cloak vehicles { %obj2 = MissionCleanup.getObject(%i2); if ((%obj2.getType() & $TypeMasks::VehicleObjectType) && (%obj2.team == %obj.team)) { %pos2 = posFromTransform(%obj2.getTransform()); if (VectorDist(%pos, %pos2) < %data.cloakRadius) %obj2.shouldCloak = 1; } } } } } for (%i=0;%i<%count;%i++) //Cloaks players { %client = ClientGroup.getObject(%i); %obj = %client.player; if (%obj) { if ((%client.shouldCloak) && (!%obj.isCloaked())) %obj.setCloaked(true); else if ((!%client.shouldCloak) && (%obj.isCloaked())) %obj.setCloaked(false); } } for (%i=0;%i<%count2;%i++) //Cloaks deployables { %obj = %dep.getObject(%i); if (isObject(%obj)) { %data = %obj.getDataBlock(); if (%data.cloakOthers) { if (%obj.isCloaked()) %obj.setCloaked(false); } else if ((%obj.shouldCloak) && (!%obj.isCloaked())) %obj.setCloaked(true); else if ((!%obj.shouldCloak) && (%obj.isCloaked())) %obj.setCloaked(false); } } for (%i=0;%i<%count3;%i++) //Cloaks vehicles { %obj = MissionCleanup.getObject(%i); if (%obj.getType() & $TypeMasks::VehicleObjectType) { if ((%obj.shouldCloak) && (!%obj.isCloaked())) %obj.setCloaked(true); else if ((!%obj.shouldCloak) && (%obj.isCloaked())) %obj.setCloaked(false); } } schedule(1000, 0, "cloakLoop"); } function StartCloakLoop() { $CloakLoop = 1; if (!(isObject(MissionCleanup))) { schedule(10000, 0, "StartCloakLoop"); return; } %depGroup = nameToID("MissionCleanup/Deployables"); if(%depGroup <= 0) { %depGroup = new SimGroup("Deployables"); MissionCleanup.add(%depGroup); } CloakLoop(); } -------------------------------------------------------------------------------- Step# 7 // ------------------------------------------ // Server.cs // ------------------------------------------ In function loadMissionStage2, line 965, under this line: new SimGroup (MissionCleanup); add this: if ($CloakLoop != 1) StartCloakLoop(); or use this section function loadMissionStage2() { // create the mission group off the ServerGroup echo("Stage 2 load"); $instantGroup = ServerGroup; new SimGroup (MissionCleanup); if ($CloakLoop != 1) //BadShot StartCloakLoop(); if($CurrentMissionType $= "") { new ScriptObject(Game) { class = DefaultGame; }; } else -------------------------------------------------------------------------------- -BadShot Function CloakLoop is a continous loop that is run every second, but when tested with 17 players and a couple dozen deployables, it still ran at <1ms. So, it shouldn't cause any lag. -------------------------------------------------------------------------------- Enjoy!