Shield-Regen Beacon Tut By: Green Dragon -------------------------------------------------------------------------------- This tut will make a beacon that will shield and heal people within a radius. Thanks to Defender for posting the regen code so I could use it. This is my first tut, so, bear with me. =D Coming next: Cloak beacon. First in inventoryhud.cs, add this to the appropriate(sp) arrays: Code: -------------------------------------------------------------------------------- $InvPack[20] = "Defending Beacon"; $NameToInv["Defending Beacon"] = "RegenBeaconDeployable"; -------------------------------------------------------------------------------- Dont forget to increase or decrease the numbers. Now, in hud.cs, find the $BackpackHudData array and add this in : Code: -------------------------------------------------------------------------------- $BackpackHudData[23, itemDataName] = "RegenBeaconDeployable"; $BackpackHudData[23, bitmapName] = "gui/hud_new_packinventory"; -------------------------------------------------------------------------------- Remember, don't forget to change the right numbers. In defaultgame.cs, add this to the right array : Code: -------------------------------------------------------------------------------- $TeamDeployedCount[%i, RegenBeaconDeployable] = 0; -------------------------------------------------------------------------------- In player.cs, add this to your armor datablocks : max[RegenBeaconDeployable] = 1; If you don't want that armor ot have it, change the one to a zero. In deployables.cs, add this: Code: -------------------------------------------------------------------------------- $TeamDeployableMax[RegenBeaconDeployable] = 4; -------------------------------------------------------------------------------- At the end of the file, add this: exec("scripts/packs/regenbeacon.cs"); Now, make a file in your scripts/packs directory called regenbeacon.cs. Paste this in (options as to it's radius of effect are commented for the ease of changing them) : Code: -------------------------------------------------------------------------------- //Regen Beacon from RedSonja, code modified by Green Dragon. datablock SensorData(DeployRegenBeaconObj) { detects = true; detectsUsingLOS = false; detectsActiveJammed = true; detectsPassiveJammed = true; detectsCloaked = true; detectionPings = true; detectMinVelocity = 0.5; detectRadius = 60; //This is the area of effect for the shielding and healing. Trust me. Modify to your liking. jams = true; jamsOnlyGroup = true; jamsUsingLOS = false; jamRadius = 15; }; datablock StaticShapeData(DeployedRegenBeacon) : StaticShapeDamageProfile { className = Sensor; shapeFile = "repair_kit.dts"; rotate = true; 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 = 'Regeneration and Shielding'; targetTypeTag = 'Beacon'; sensorData = DeployRegenBeaconObj; sensorRadius = DeployRegenBeaconObj.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 }; //---------------- deployable pack and deployed image data -sb ----------------------------------------- datablock ShapeBaseImageData(RegenBeaconDeployableImage) { shapeFile = "repair_patch.dts"; item = RegenBeaconDeployable; mountPoint = 1; offset = "0 -0.15 0"; deployed = DeployedRegenBeacon; maxDepSlope = 360; minDeployDis = 0.5; maxDeployDis = 5.0; deploySound = MotionSensorDeploySound; emap = true; heatSignature = 0; stateName[0] = "Idle"; stateTransitionOnTriggerDown[0] = "Activate"; stateName[1] = "Activate"; stateScript[1] = "onActivate"; stateTransitionOnTriggerUp[1] = "Idle"; }; datablock ItemData(RegenBeaconDeployable) { className = Pack; catagory = "Deployables"; shapeFile = "repair_patch.dts"; mass = 2.0; elasticity = 0.2; friction = 0.6; pickupRadius = 1; rotate = false; image = "RegenBeaconDeployableImage"; pickUpName = "a deployable regeneration beacon pack"; computeCRC = true; emap = true; heatSignature = 0; maxSensors = 1; }; //----------------------------------------------------------------------------------------------------- //---------- DeployedRegenBeacon functions (onAdd, onDestroy) -sb ------------------------------------- //----------------------------------------------------------------------------------------------------- function DeployedRegenBeacon::onAdd(%this, %obj) { Parent::onAdd(%this, %obj); %obj.team = $team; %obj.rotation = $rot; %obj.owner = $owner; %obj.transform = $xform; %position = (getWord(%obj.transform, 0)) @ " " @ (getWord(%obj.transform, 1)) @ " " @ (getWord(%obj.transform, 2)); %radius = %obj.getDatablock().sensorRadius; CheckVicinity(%obj, %obj.team, %position, %radius, 0.095); } function DeployedRegenBeacon::onDestroyed(%this, %obj, %prevState) { Parent::onDestroyed(%this, %obj, %prevState); $TeamDeployedCount[%obj.team, RegenBeaconDeployable]--; %obj.schedule(500, "delete"); } //------------------------------------------------------------------------------------------------------ //---------- RegenBeaconDeployableImage functions -sb -------------------------------------------------- //------------------------------------------------------------------------------------------------------ function RegenBeaconDeployableImage::getInitialRotation(%item, %plyr) { $team = %plyr.client.team; $owner = %plyr.client; $xform = %item.deployed.getDeployTransform(%item.surfacePt, %item.surfaceNrm); $rot = %item.rotation; %rotAxis = vectorNormalize(vectorCross(%item.surfaceNrm, "0 0 1")); if (getWord(%item.surfaceNrm, 2) == 1 || getWord(%item.surfaceNrm, 2) == -1) %rotAxis = vectorNormalize(vectorCross(%item.surfaceNrm, "0 1 0")); return %rotAxis SPC mACos(vectorDot(%item.surfaceNrm, "0 0 1")); } function RegenBeaconDeployable::onPickup(%this, %pack, %player, %amount) { if(%pack.sensors $= "") { // assume that this is a pack that has been placed in a mission // this case was handled in ::onInventory below (max sensors); } else { // find out how many sensor were in the pack %player.deploySensors = %pack.sensors; %player.client.updateSensorPackText(%player.deploySensors); } } function RegenBeaconDeployable::onThrow(%this,%pack,%player) { %player.throwSensorPack = 1; %pack.sensors = %player.deploySensors; %player.deploySensors = 0; %player.client.updateSensorPackText(%player.deploySensors); serverPlay3D(ItemThrowSound, %player.getTransform()); %pack.schedulePop(); } function RegenBeaconDeployable::onInventory(%this,%player,%value) { if(%player.getClassName() $= "Player") { if(%value) { // player picked up or bought a motion sensor pack %player.deploySensors = %this.maxSensors; %player.client.updateSensorPackText(%player.deploySensors); } else { // player dropped or sold a motion sensor pack if(%player.throwSensorPack) { // player threw the pack %player.throwSensorPack = 0; // everything handled in ::onThrow above } else { %player.deploySensors = 0; %player.client.updateSensorPackText(%player.deploySensors); } } } Pack::onInventory(%this,%player,%value); } //------------------ functions -sb -------------------------------------------------------------- function CheckVicinity(%obj, %team, %position, %radius, %hRate) { if(%obj) { %masks = $TypeMasks::PlayerObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::TurretObjectType | $TypeMasks::ItemObjectType; InitContainerRadiusSearch(%position, %radius, %masks); %numTargets = 0; while((%target = containerSearchNext()) != 0) { %dist = containerSearchCurrRadDamageDist(); if (%dist > %radius) continue; %targets[%numTargets] = %target; %numTargets++; } for (%i = 0; %i < %numTargets; %i++) { %target = %targets[%i]; if(%target.team == %team) RadiusRegeneration(%target, %hRate); } } schedule(2000, %obj, "CheckVicinity", %obj, %team, %position, %radius, %hRate); } //Important part function RadiusRegeneration(%target, %hRate) { %damaged = %target.getDamageLevel(); if(%damaged) { %status = "Regeneration in Progress..."; %target.applyRepair(%hRate); %target.isShielded = true; } else %status = "No damage detected."; %target.isShielded = true; commandToClient( %target.client, 'BottomPrint', "You are in a regeneration and shielding field : " @ %status, 2, 1 ); } -------------------------------------------------------------------------------- Enjoy!