Author Topic: [SOLVED (fo reelz?)] Headshot that spawn an explosion on target's death?  (Read 6477 times)

I made a series of explosions spawned with a single projectile in a similar fashion to the gore mod, but i want it to spawn only when players die via headshot

My current script that spawns the explosions when a player dies in general
http://pastebin.com/raw.php?i=5MQ40UwB

Is it possible to have it work with the Support_HeadshotMod add-on since it affects all projectiles and also has a changeable value for headshot damage?
« Last Edit: November 09, 2014, 04:56:24 AM by Masterlegodude »

Someone could be way more specific, but try packaging the onHit function to check if the hit object is the head. I'd like to know more of this as well, so let's await that somebody.

Why not just use some of the code from Support_HeadShotMod, check if the damage is going to kill them, and if it will, spawn the explosion?

It'll actually be easier if you just download Support_HitBox then, on collision, you can call getHitbox(%player, %bullet, %collisionPosition) and check if striPos($headTest, %result) > -1 to see if it hit their head.

Alright, i got it to work, kinda
Code: [Select]
package BdayPartyDeath
{
function projectileData::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   if(matchBodyArea(getHitbox( %obj, %col, %pos ), $headTest ))
   {
         if(%col.getType() & $TypeMasks::PlayerObjectType)
         {
            if(%col.getDamagePercent() >= 0.8)
            {
               %proj = new Projectile()
               {
                  scale = %obj.getScale();
                  dataBlock = bdayDeathProjectile;
                  initialPosition = %obj.getPosition();
                  sourceObject = %obj;
                  sourceSlot = 0;
                  client = %obj.client;
               };
               MissionCleanup.add(%proj);
               serverPlay3D(BdayDeathSound,%obj.getTransform());
            }
         }
   }
   parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
}
};
activatePackage(BdayPartyDeath);

There's something about the 'if(striPos($headTest, %result) > -1)' it doesn't like, but it does work as intended, sort of

It's just that the hitbox for the headSkin is like, really glitchy, sometimes the face decal, and hardly even that, the default decal, where the eyes and mouth are, seem to be the only spot that causes the script to function, for some reason, randomly, the whole head is not counted, rather, a small portion of the front just...

So uh... what about that?

Also, getDamagePercent isn't very good, only as a placeholder, mostly because of the different amounts of damage that weapons do, so in most cases, the weapons won't bring a player to the specified amount of damage to activate the script

So if i raise the sensitivity of getDamagePercent, stronger weapons may skip the range in which the script activates while weaker weapons will activate the script  before killing the victim, so that's pretty problematic
« Last Edit: November 06, 2014, 10:15:57 PM by Masterlegodude »

Remove the ; on the line with ##s.

I edited my previous post, but anyway, i tried a method where the script checks if the collided object is dead, but that only works if you could still shoot players who are dead, not if the player died when they were shot, so that won't work

I don't know if it's possible to have a schedule activate after the projectile hits a live target and activate a function that checks if that player is now dead, but there's definitely gotta be a way to do this that isn't overly complicated, impossible, or has some kind of hacky or wonky method

I have getDamagePercent set to 1, however, the projectile only knows the damage percent prior to being killed, so if the player is shot and dies, it won't know because it gets the current damage percent

How can i make the projectile check if the player has died? Or is there some way to tie in the projectileData::onCollision script with a armor::onDisabled script?

Aagh, this feels hard and confusing, most likely because i only have half an idea of what i'm doing, but still ;___;
« Last Edit: November 07, 2014, 04:13:42 AM by Masterlegodude »

if(%player.getState() $= "Dead")

if(%player.getState() $= "Dead")
Tried it, still doesn't detect the player or bot being dead after they've been shot

There's no errors in the console and everything looks to be in order
http://pastebin.com/raw.php?i=mGbJhrDp

That's gonna be because both %player and %hBot are never defined. Just change %player to %col and I don't know where you got %hBot from but it seems like you can delete it all together.

edit: whoopsie, said %obj when I meant %col.
« Last Edit: November 07, 2014, 09:41:56 PM by $trinick »

I thought %hBot was what the hole bots used when a script references them? Like %hBot.whateverwhatever, or am i thinking of something else?

Anyway, i see what the problem is, and i actually said it before, the problem is that the projectile collides with a living player that then dies, i mean, it makes sense why %col.getState() $= "Dead" won't work, because you're shooting something that's alive and not dead

And adding a ! before $= will just make it so any time you shoot a player/bot in the head, it'll spawn the explosion, because they're not dead, but that's not how i want this to work

And thinking about it now, i don't know if this is even possible, the projectile can't tell if a player has died, i don't think there's way to have a projectile check if the player it collided with is now dead

And i don't think armor::onDisabled can be scripted to check if the player was killed with a headshot

And i keep saying "and" a lot...

Basically, my idea is to have it play out like this
« Last Edit: November 07, 2014, 11:40:56 PM by Masterlegodude »

Oh, duh, easy enough. Move the parent for on collision to the top of the function and return its result at the end.

http://pastebin.com/YCbWYppk

Oh, and just because %hBot is the variable name that's used in bot holes doesn't mean that it's defined everywhere -- all local variables need to be defined inside a function or in the function declaration to be used.
« Last Edit: November 08, 2014, 12:35:04 AM by $trinick »

Oh, and just because %hBot is the variable name that's used in bot holes doesn't mean that it's defined everywhere -- all local variables need to be defined inside a function or in the function declaration to be used.
Oh whoops, i thought it was one of those variables that could be used globally

Oh, duh, easy enough. Move the parent for on collision to the top of the function and return its result at the end.

http://pastebin.com/YCbWYppk
Not sure what that was supposed to do or how it's different from just moving the parent itself above the code, but it still didn't work

It makes it so the bullet kills the player before your code is ran rather than after. Add in a debug statement that announces the state of the player right before it checks it.