Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The problem with the code is that for some reason when the VTOL moves back, it does so way too fast not matter what I try.
- //Now it doesn't even do it when it enters its' "BackOff" state, it does it when it enters the state where fire its' plasma gun!
- Class StealthCraft : Actor
- {
- Default
- {
- Health 5000;
- Radius 128;
- Height 100;
- Mass 7000;
- DamageFactor 0.9;
- Gravity 0.5;
- Friction 0.05;
- FloatBobStrength 0.5;
- Species "MarineAlly";
- Obituary "%o was killed by a VTOL";
- Monster;
- +NoGravity;
- +MissileEvenMore;
- +Float;
- +AvoidMelee;
- +Telestomp;
- +FloatBob;
- +NoBlood;
- +PuffOnActors;
- }
- Static Vector3 GetLocalVel(Actor a) //Function by Cherno, I know fuck all about math.
- {
- double relativeVelX = (sin(a.angle) * a.vel.y) + (cos(a.angle) * a.vel.x);
- double relativeVelY = ((cos(a.angle) * a.vel.y) - (sin(a.angle) * (a.vel.x))) * -1;
- return (relativeVelX,relativeVelY,a.vel.z);
- }
- static bool AreTherePlayersAround(double dist, actor source) //Function by Agent_Ash, this code is so alien to me that I don't even know how to fix the formatting without breaking it.
- {
- for (int pn = 0; pn < MAXPLAYERS; pn++)
- {
- if (!players[pn].mo || !playerInGame[pn])
- continue;
- PlayerPawn plr = players[pn].mo;
- if (!plr)
- continue;
- if (source.Distance3D(plr) <= dist)
- {
- return true;
- break;
- }
- }
- return false;
- }
- Vector3 ForwardVel; //Used to store the crafts' forward velocity, to make it visual lean forward or back if this vector is too low or high.
- Int MayBackAway; //A variable used to determine the chance of the craft to move away from its' target.
- Int MayThrustUp; //A variable used to determine the chance of the craft to go up.
- Int MayThrustDown; //A variable used to determine the chance of the craft to go down.
- Int RandomSwerve; //A variable used to give the VTOL a random delay before swerving when attacking instead of standing still.
- Int VerticalMovementCooldown; //A variable used as a cooldown so the craft doesn't move up the immediately go down or vice versa.
- Int MissileFiringChance; //This variable determines if the VTOL should launch its' missiles instead of firing its' plasma gun, it is used for the DecideAttack state.
- enum AircraftSoundChannels
- {
- CHAN_ENGINE = 18273
- }
- Override Void PostBeginPlay()
- {
- Super.PostBeginPlay();
- RandomSwerve = RandomPick (35*1,35*2,35*3,35*4,35*5); //Initializes the first random delay before the VTOL swerves.
- }
- Override Void Tick()
- {
- Super.Tick();
- //If it's moving forward too fast, then produce a counterforce to slow it down.
- If (Self.ForwardVel.x >= 24) {A_ChangeVelocity (-1,flags:CVF_RELATIVE); a_log ("IS THIS FUCKING LINE THE ISSUE ? JUST TELL ME WHAT IT FUCKING IS");}
- //If moving up too fast up, then slow down.
- If (Self.Vel.z >= 12) {A_ChangeVelocity (z:-1,flags:CVF_RELATIVE);}
- If (Target)
- {
- If (CheckIfTargetInLOS (140,JLOSF_CLOSENOJUMP,dist_close:512) && InStateSequence (CurState, ResolveState ("See")))
- {Return;}
- Else //If the target isn't in the LOS while chased, slow down to not fly away uncontrollably and face it faster.
- {
- MayBackAway = Random (0,256);
- A_FaceTarget (16);
- A_ChangeVelocity (-3,flags:CVF_RELATIVE);
- //A random chance for the craft to enter its' back off state where it backs away.
- If (MayBackAway == 27 && InStateSequence (CurState, ResolveState ("See"))) {SetStateLabel ("BackOff");}
- }
- }
- //If the VTOL is attacking with its' plasma gun, then have a random chance of moving left or right not avoid being hit.
- If (InStateSequence (CurState,ResolveState ("FirePlasma")))
- {
- A_ChangeVelocity (0,flags:CVF_REPLACE);
- RandomSwerve--;
- If (RandomSwerve <= 0)
- {
- A_LOG ("STOP FLYING BACK YOU STUPID PIECE OF SHIT");
- A_ChangeVelocity (y:RandomPick (-32,32),flags:CVF_RELATIVE);
- RandomSwerve = RandomPick (35*1,35*2,35*3,35*4,35*5); //Pick another delay before thje next swerve.
- }
- }
- }
- Private Void A_LeanTowardsMovementDirection()
- {
- ForwardVel = StealthCraft.GetLocalVel (Self);
- //If it's moving forward too fast, change the sprite sheet to the forwards leaning one.
- If (ForwardVel.x >= 16) {Sprite = GetSpriteIndex ("FLFM");}
- //If it's moving backwards too fast, change the sprite sheet to the backwards leaning one.
- If (ForwardVel.x <= -16) {Sprite = GetSpriteIndex ("FLBM"); a_log ("leaning back");}
- //If its' speed is in between both of the above, change the sheet back to the idle flying one.
- If (ForwardVel.x <= 16 && ForwardVel.x >= 16) {Sprite = GetSpriteIndex ("FLSA");}
- }
- States
- {
- Spawn:
- TNT1 A 0 NoDelay A_StartSound ("StealthCraft/EngineOn",CHAN_ENGINE,CHANF_LOOPING,attenuation:0.75);
- Goto IdleFly;
- IdleFly:
- FLSA AB 8 A_LookEx (maxheardist:3072);
- Loop;
- See:
- FLSA AB 8
- {
- //If the VTOL is stuck on the ground, then leap up.
- If (pos.z - FloorZ <= 0) {a_log ("way too low");A_ChangeVelocity (z:4,flags:CVF_RELATIVE);}
- A_Chase(null,"DecideAttack");
- A_ChangeVelocity (2,flags:CVF_RELATIVE);
- A_LeanTowardsMovementDirection();
- A_FaceTarget (4);
- VerticalMovementCooldown--; //Decrements the cooldown every time the functions here are executed.
- MayThrustUp = Random (0,128);
- MayThrustDown = Random (0,128);
- //A random chance for the VTOL to thrust down, must also be at least 48 or more MU above the ground for it to thrust down.
- If (MayThrustDown >= 126 && VerticalMovementCooldown <= 0 && pos.z - GetZAt () >= 48)
- {
- A_ChangeVelocity (z:FRandom (-4.0,-12.0),CVF_RELATIVE);
- a_log ("going down");
- MayThrustUp = 0; //Reset the variable to 0 so if it does decide to fly down, it won't immediately fly back up.
- VerticalMovementCooldown = 12;
- }
- //May randomly decide to fly upwards, to not just stick on the same height.
- If (MayThrustUp >= 127 && VerticalMovementCooldown <= 0)
- {
- a_log ("going up");
- A_ChangeVelocity (z:FRandom (4.0,10.0),CVF_RELATIVE);
- VerticalMovementCooldown = 12;
- }
- }
- Goto See+1;
- BackOff:
- FLBM ABABAB 8
- {
- vel.x = vel.x * cos(angle) + vel.y * sin(angle) -0.2;
- console.printf ("the velocity is %d", vel);
- A_FaceTarget (24);
- }
- Goto See;
- DecideAttack:
- TNT1 A 0 {If (Target == Null) {SetStateLabel ("See");}} //If there's no target, go back to looking for one.
- TNT1 A 0
- {
- MissileFiringChance = Random (0,384); //Randomize the chance of firing missiles.
- Console.PrintF ("The initial RNG for MissileFiringChance is %d", MissileFiringChance);
- //In short, this checks the actors around the VTOL's target, and increases its' chance of
- //firing a missile slightly for every nearby actor that meets the following conditions:
- //The actor is a monster.
- //The actor has 20 HP or more.
- //The actor is hostile. (If the VTOL is friendly it'll count non-friendly NPCs, if it is NOT friendly, it'll count friendly NPCs.)
- BlockThingsIterator CheckAroundTarget = BlockThingsIterator.Create (Target,512);
- Actor FoundActor;
- While (CheckAroundTarget.Next())
- {
- FoundActor = CheckAroundTarget.Thing;
- If (FoundActor && bIsMonster == True && FoundActor.Health >= 20 && IsHostile (FoundActor))
- {
- MissileFiringChance += Random (1,3);
- }
- }
- Console.PrintF ("MissileFiringChance after the first calculation of the amount of enemies around the target is %d", MissileFiringChance);
- //In theory at least, this should further increase the chance of the VTOL firing a missile based on how high the targets' own health is.
- MissileFiringChance += Target.Health/5;
- Console.PrintF ("The RNG for MissileFiringChance after also being calculated based on the actors' health is %d", MissileFiringChance);
- If (self.bFriendly == True && AreTherePlayersAround (512,target) == True) {a_log ("player is too close to the missiles' blast radius");SetStateLabel ("FirePlasma");} //If there's a player near the target and the VTOL is friendly, then fire the plasma gun instead.
- If (MissileFiringChance >= 370) {SetStateLabel ("FireMissiles");}
- }
- TNT1 A 0;
- Goto FirePlasmaGun; //If the above checks' conditions are not met, fire the plasma gun instead.
- FirePlasmaGun:
- tnt1 a 0 a_log ("you dun goofed");
- //FLSA A 0 A_Jump (2,"FireMissiles"); //A small chance for the VTOL to fire its' missiles anyway, even if the check on DecideAttack decided to not do so.
- FLSA A 8 A_StartSound ("StealthCraft/PlasmaCharge",CHAN_WEAPON,attenuation:/*0.8*/0,starttime:0.474);
- FLSA BABABABABABABABABABAB 8; //This is perfectly timed so the VTOL begins firing right when the charging sound ends.
- FLFP ABABABABABABABABABABABABABABABABABABABAB 8
- {
- A_SpawnProjectile ("StealthCraftPlasma",4,angle:FRandom (0.5,-0.5),CMF_TRACKOWNER|CMF_OFFSETPITCH,FRandom (0.5,-0.5));
- A_SpawnProjectile ("StealthCraftPlasma",4,angle:FRandom (0.5,-0.5),CMF_TRACKOWNER|CMF_OFFSETPITCH,FRandom (0.5,-0.5));
- }
- Goto See;
- FireMissiles:
- tnt1 a 0 a_log ("missile placeholder");
- stop;
- }
- }
- Class StealthCraftPlasma : Actor
- {
- Default
- {
- Height 12;
- Radius 6;
- DamageFunction RandomPick (8,12); //Either 8 or 12 damage is dealt.
- Speed 32;
- FastSpeed 64;
- Alpha 0.80;
- Decal "PlasmaScorch";
- Translation "194:207=193:200", "241:241=194:194";
- Obituary "%o was pulverized by a VTOL's plasma !";
- DamageType "Plasma";
- RenderStyle "Add";
- DeathSound "Weapons/PlasmaX";
- Projectile;
- +Randomize;
- }
- Override Void PostBeginPlay()
- {
- Super.PostBeginPlay();
- A_StartSound ("StealthCraft/PlasmaFired");
- A_AttachLight ("PlasmaLight",DynamicLight.PulseLight,"6B63FF",32,36,DynamicLight.LF_Attenuate,param:0.25);
- }
- States
- {
- Spawn:
- PLSS AB 4 Bright;
- Loop;
- Death: //Implement several lights that get increasingly smaller on these death frames.
- TNT1 A 0 A_RemoveLight ("PlasmaLight");
- PLSE ABCDE 6 Bright;
- Stop;
- }
- }
- Class StealthCraftMissile : Actor
- {
- Default
- {
- Height 24;
- Radius 16;
- Damage 120;
- Speed 64;
- FastSpeed 128;
- Mass 50;
- SeeSound "StealthCraft/MissileFired";
- Obituary "%o was blown up by a VTOL's missile";
- Translation "96:111=#[0,255,128]", "89:95=#[0,255,128]";
- Projectile;
- +RocketTrail;
- +SeekerMissile;
- +ScreenSeeker;
- +ExtremeDeath;
- +SpawnSoundSource;
- }
- Double TrailXVel;
- Double TrailYVel;
- Double TrailZVel;
- Double RandMult; //Random multiplier
- Override Void Tick()
- {
- Super.Tick();
- //Don't spawn particles and play the missile sound if the game is frozen or the missile is exploding.
- If (IsFrozen() || InStateSequence (CurState,ResolveState ("Death")) || InStateSequence (CurState,ResolveState ("Death.Air"))) {A_StopSound (17263); Return;}
- TrailXVel = FRandom (0.0,-4.0); TrailYVel = FRandom (4.0,-4.0); TrailZVel = FRandom (4.0,-4.0); //Random velocity for all 3 axes.
- A_SpawnItemEx ("StealthCraftMissileParticle",64,xvel:TrailXVel,TrailYVel,TrailZVel,Self.Angle-180+Random (8,-8),SXF_SETMASTER|SXF_ABSOLUTEANGLE|SXF_ORIGINATOR);
- TrailXVel = FRandom (0.0,-4.0); TrailYVel = FRandom (4.0,-4.0); TrailZVel = FRandom (4.0,-4.0);
- RandMult = FRandom (2.0,8.0);
- A_SpawnItemEx ("StealthCraftMissileParticle",64+24,xvel:TrailXVel*RandMult,TrailYVel*RandMult,TrailZVel,Self.Angle-180+Random (8,-8),SXF_SETMASTER|SXF_ABSOLUTEANGLE|SXF_ORIGINATOR);
- }
- States
- {
- Spawn:
- TNT1 A 0 NoDelay A_StartSound ("StealthCraft/MissileMoving",17263,CHANF_LOOPING,attenuation:0.75);
- FLMI A 4 Bright Light ("StealthCraftMissileLight") A_SeekerMissile (0,2,SMF_PRECISE);
- Goto Spawn+1;
- Death:
- TNT1 A 0
- {
- A_StopSound (17263);
- If ((pos.z - FloorZ) >= 128) //If the missile impacted away from the floor, use the air explosion sprites instead.
- {
- SetStateLabel ("Death.Air");
- }
- }
- tnt1 a 0 a_log ("died near the floor");
- MISL B 4 A_Explode (Random(500,600),512,alert:True,100);
- MISC C 4;
- MISL D 4;
- Stop;
- Death.Air:
- tnt1 a 0 a_log ("died far from the floor");
- MISL B 4 A_Explode (Random(500,600),512,alert:True,100);
- MISL C 4;
- MISL D 4;
- Stop;
- }
- }
- Class StealthCraftMissileParticle : Actor
- {
- Default
- {
- RenderStyle "Add";
- Alpha 0.75;
- +NoInteraction;
- }
- States
- {
- Spawn:
- FLMS ABCDEFGHIJKL 1 Bright;
- Stop;
- }
- }
- Class StealthCraftSprites : Actor
- {
- States
- {
- Spawn:
- FLFM AB 0; //VTOL is leaning forward
- FLBM AB 0; //VTOL is leaning backwards
- Stop;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement