Make landing ontop of enemy kills them?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Make landing ontop of enemy kills them?

Post by Graaicko »

I have been playing the early Splinter Cell, love the series so much. Playing it has summoned me with some ideas how to make Shadow Elite, my mod more like it. Anyways currently I am wondering what kind of code I would be looking at to make it where if the player lands on an enemy from above, it kills them, would be a perfect stealth kill element for me as my maps are extremely dynamic and there will be areas where you have elevation over the opposition. Perfer if it was just a normal death in regards to the enemies dying, as them exploding when you land on them seems a bit excessive.
User avatar
comet1337
Posts: 876
Joined: Fri Sep 25, 2015 3:48 am
Location: elsewhere

Re: Make landing ontop of enemy kills them?

Post by comet1337 »

TestMObjZ can get any actor another might be standing on top of
then check if Vel.Z was negative the previous ticand zero the current to detect landing from the air
then inflict damage from there
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: Make landing ontop of enemy kills them?

Post by Graaicko »

How do I use this and where is this suspose to go?
User avatar
Caligari87
Admin
Posts: 6236
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Make landing ontop of enemy kills them?

Post by Caligari87 »

The short answer: In ZScript as part of some script that manages or monitors the player's movement.

The longer version:
There's two paths here. The first is if you're okay using custom zscripted player classes, then you can add a few lines to your MovePlayer() override. The second is more compatible for non-customized player classes, and involves using an invisible zscripted inventory item with a DoEffect() override to monitor the player's movement (by referencing the item's owner).

Either way, your script needs to have a variable for the player's old Z-vel. Each tic, you check if TestMObjZ on the player returns true, and if so whether there's also a returned actor. This indicates the player is currently standing on another actor. Next you compare the player's current z velocity to their old z velocity. If it's less than zero (maybe by some threshold), then the player was moving downwards the previous tic. Then damage or kill the returned actor the player is standing on, however that needs to be managed. Finally, regardless of all the previous checks, set the "old" z velocity variable to the current z velocity, so it can be rechecked next loop.

If most of the above sounds like greek gibberish, then your first order of business is to start trying to learn ZScript, as this is a slightly more advanced application than simply making DECORATE monsters.

8-)
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Make landing ontop of enemy kills them?

Post by Matt »

A really crude, simple way to do this, should be doable without ZScript but I don't know how:


Every tick, see if the player's (or whatever's) Z velocity is lower than a certain negative value.

If it is, spawn a projectile that lasts for 2 ticks, has a radius equal to the player's and a height of like 2 or something, starts at 2 units immediately below the player, and starts with the same velocity as the player.

That projectile will proceed to hit whatever the player lands on, and inflict damage accordingly.


The downside of this method is that you're spawning actors every single tick while falling and that's not very nice from an optimization point of view (and will be much worse if you're doing this for monsters as well as players). But given how often anything's going to be falling fast enough, this would be one of the less serious cases.
Viper
Posts: 30
Joined: Tue Oct 08, 2019 12:54 pm

Re: Make landing ontop of enemy kills them?

Post by Viper »

Last edited by Viper on Wed Oct 30, 2019 11:50 pm, edited 17 times in total.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Make landing ontop of enemy kills them?

Post by Void Weaver »

Matt, seems that's better to use short-ranged hitscan attack with lethal puff instead of missile.

Viper, AFAIK bouncing works only for actor with MISSILE flag or MBFBOUNCER. And even if it will work correct for player (that's doubtely) then player will jump into "Bounce.Actor" just when touch actor. Not good idea, I guess. Also _Explode isn't good solution too if mechanics purposes only single kill.
If (GetActorZ(0) != GetActorFloorZ(0))
As option for deco\anon:

Code: Select all

If(GetZAt(0,0,0)!=floorz){Return state("killing_state");}
Viper
Posts: 30
Joined: Tue Oct 08, 2019 12:54 pm

Re: Make landing ontop of enemy kills them?

Post by Viper »

The player's actor can be set to bounce. There's a few edits there now however it doesn't seem to work by just jumping on top of a zombieman (tested) . May need to have some velocity from a higher floor possibly, or perhaps try A_RadiusGive instead of A_Explode.. Bounce state confirmed working by setting the bounce count to 1 and dying after one bounce..

However if you cannot get the bounce to work as desired, then use a continuous running script which first asks if vertical velocity is 0 to prevent anything from happening while idle.

ACS:

Code: Select all

Script "NewScript" (void)
If (GetActorVelY(0) != 0.0) 
{
  If (GetActorZ(0) >= (GetActorFloorZ(0)+32.0)) 
  {
    Do stuff;
  }
delay(1);
restart;
}
I'd call this in the player spawn state, and use a bool to prevent it from re-executing.

---------
Tested further using a jetpack, Player definitely bounces on monsters, just the killing them part seems to be ineffective.. I will test another attack yet..
Viper
Posts: 30
Joined: Tue Oct 08, 2019 12:54 pm

Re: Make landing ontop of enemy kills them?

Post by Viper »

Scratch that last message, I forgot the Flag +USEBOUNCESTATE. :roll:

This method works perfectly.. Just need a high enough jump..
Viper wrote:Give the player a "BOUNCEONACTORS" flag and the "USEBOUNCESTATE" flag, and set the bounce count to ....
There's a lot more you can do to fancy it up but that's the base for it. One thing you may want is to make the kill only happen if the player is holding the crouch button.

Code: Select all

if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_CROUCH)
{

}
Last edited by Viper on Sat Oct 19, 2019 10:40 pm, edited 1 time in total.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Make landing ontop of enemy kills them?

Post by Void Weaver »

Thank you Viper, it's really interesting solution. :D I didn't know before that bouncing will work with player.
But the missile solution seems to me a bit easier, and it can take into account player input too:

Code: Select all

ACTOR CrusherGuy : DoomPlayer
{
var int user_heightMult;
States
{
Spawn:
PLAY A 1 NoDelay A_Overlay(3,"LandingKill",1)
Loop

LandingKill:
TNT1 A 1
{
If(VelZ<0
//&&GetPlayerInput(MODINPUT_OLDBUTTONS)&BT_CROUCH //Open it to make landing kill work only while crouch button holded
){user_heightMult++;A_SpawnItemEx("LandingKiller",0,0,-5,0,0,-5,0,SXF_SETMASTER);A_GiveToChildren("HeightCounter",user_heightMult);Return state("");}
Else{user_heightMult=0;Return state("");}
}
Loop
}
}

ACTOR LandingKiller
{
Height 4
Radius 4
Projectile
Damage (0)
+HITTRACER
States
{
Spawn:
BAL1 AA 1
Death:
TNT1 A 0 A_CheckFlag("ISMONSTER","CheckFurther",AAPTR_TRACER) //Harmless for objects
Goto SafeEnd
CheckFurther:
TNT1 A 0 A_CheckFlag("FRIENDLY","SafeEnd",AAPTR_TRACER) //Harmless for friends
TNT1 A 0 A_KillTracer //Instakill. Close it and...
//TNT1 A 0 A_DamageTracer(CountInv("HeightCounter"),"LandingDmg",0,"None","None",AAPTR_TARGET) //... and open it to inflict falling height correlated damage instead of instakill
SafeEnd:
TNT1 A 0
Stop
}
}

ACTOR HeightCounter : Inventory{Inventory.MaxAmount 0x7FFFFFFF}
EDIT: Also added a bit different extended way: now it can deal a some damage which depends on falling height, instead of instakill.
Last edited by Void Weaver on Sat Oct 19, 2019 4:24 pm, edited 5 times in total.
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: Make landing ontop of enemy kills them?

Post by Graaicko »

Hmm. some interesting stuff here. I will try all these out when I get back from my trip. Anyways, would it be possible to only make this eliminate enemies and not "All actors" (for instence, I have destroyable objects, such as eplosives, trashcans with items inside and such) Would seem weird if you landed on top of an explosive and it blows up.
Viper
Posts: 30
Joined: Tue Oct 08, 2019 12:54 pm

Re: Make landing ontop of enemy kills them?

Post by Viper »

Actors that aren't to be hurt get the property : DamageFactor "PlayerStomp", 0.0

Revision of above. BounceType isn't wanted and the custom flags do the work it seems. Also A_Explode is unreliable when called from the player during bounce so spawning an actor that drops and explodes works 100% better.

Code: Select all

BounceCount 99999
BounceFactor 2.0
+BOUNCEONACTORS
+ALLOWBOUNCEONACTORS
+USEBOUNCESTATE
  States
    {
  Bounce:
  Bounce.Actor: 
	TNT1 A 0 ACS_NamedExecute("playerStomp",0)
	Goto See
  BounceKill:
	TNT1 A 0 A_SpawnItem("DropAttack")

Code: Select all

ACTOR DropAttack
{	
  +INVULNERABLE
  +GHOST
  +THRUACTORS
  +NEVERTARGET
  +NOBLOCKMAP
  +ALWAYSTELEFRAG
  DamageType PlayerStomp
  Obituary "YOU WERE FLATTENED"
  States
  {
  Spawn:
	TNT1 A 0
	TNT1 AA 1 A_Explode(100,48)
	Stop	
  }
}

Code: Select all

Plus the "Script" Above
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: Make landing ontop of enemy kills them?

Post by Graaicko »

Viper wrote:Actors that aren't to be hurt get the property : DamageFactor "PlayerStomp", 0.0
Assuming this is all ZScript?
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: Make landing ontop of enemy kills them?

Post by Graaicko »

Well, thanks Void, and everbody else that has come to help me. I got everything working, Made the projectile invisible, and added a hit sound that sounds like the enemies neck it breaking when you land on them. Very cool.
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: Make landing ontop of enemy kills them?

Post by Graaicko »

Void Weaver wrote:Thank you Viper, it's really interesting solution. :D I didn't know before that bouncing will work with player.
But the missile solution seems to me a bit easier, and it can take into account player input too
Real quick, I am noticing that the enemies are alerted when you are well away from them, about to land on them. Don't know if its the projectile under the player that is alerting them or not, but they get alerted when your close to them. Even if you have elevation over them...
Post Reply

Return to “Scripting”