Author Topic: Melee knockback?  (Read 446 times)

I'm editing a weapon and consider myself a novice coder. I've been looking at other tools or weapons such as the Push Broom to implement some sort of knockback for my weapon using:

impactImpulse
verticalImpulse


But after I implement the two lines starting at line 95, the vertical impulse works, but there's no horizontal impulse which is what I assumed the impactImpulse was? If you'd like to take a look at my weapon I edited, here's a download for the edited weapon. Or you can take a look at the .cs file instead.

https://drive.google.com/open?id=1ySILH-jxmucQE3Oaadm3y8KFvBmZ_cP-
« Last Edit: January 11, 2019, 03:27:01 PM by Spartan224 »

After extensive testing I've discovered that the problem is that there is a variable missing in CrowbarProjectile::onCollision. So just add a variable to that and the parent and it'll work. Apparently a lot of add-ons have the wrong number of variables for ::onCollision.

I've had this same problem before making some of my add-ons and I resorted to making my own pushback method. I never figured out why the default one wouldn't work until now.
« Last Edit: January 12, 2019, 09:31:24 AM by jes00 »

Sorry, I'm pretty new to coding. What should I add to that section?

Look up the server functions megadump on the forums (server commands.txt) and find projectile::oncollision and read what the fields are


Just change
function CrowbarProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
to
function CrowbarProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal, %rot)

and the line after it from
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
to
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal, %rot);

Alrighty, I'll keep you updated. I was trying to find the info PhantOS suggested but I had no luck. Either I didn't search correctly or it was hidden in a bunch of results.

EDIT: I tried that, Jes. It did work but I figured out that I have a conflicting add-on that somehow stops the vertical impulse. I'm investigating why.

EDIT2: Believe I found 2 culprits to this issue, Swollow's Sweps and the C4 Explosive. Besides the C4 which I don't need, is there a way I can add knockback without the impactImpulse line with OnCollision? I still can't find server functions post.
« Last Edit: January 12, 2019, 06:00:03 PM by Spartan224 »

i never experienced any issues without the lack of the 2 arguments so i didnt notice
I've updated the file but with 4000 downloads of the main file and multiple hacked variants of my mod floating around expect a lot of users to still have the bugged version, also I didn't update the file in my large addon dump because im lazy

can't be assed to figure out if this is the true culprit of all your issues but i added the two arguments into my code

consider just manually adding some code onto your projectile collision that applies the vertical impulse because im sure many many other addons break this functionality since I've very rarely seen anyone utilize or care about vertical impulse

Yeah, I believe that'd be the case for other add-ons, but those were the two weapon add-ons that messed with impact impulse.
I've also tried searching for the info PhantOS suggested again, but I still have no luck after many search terms.


Nevermind, the issue is solved. Thanks for fixing the Sweps base, Swollow. I'm sure there's going to be more add-ons that'll break the impactImpulse anyways. But just in case another add-on breaks something, I'm unsure how I can add velocity knockback in the OnCollision part of the code. Sorry for my cluelessness once again.
« Last Edit: January 13, 2019, 01:43:13 PM by Spartan224 »

Just do something like this:
Code: [Select]
package Crowbar
{
function armor::damage(%data, %player, %sourceObject, %pos, %damage, %type)
{
if(isObject(%attacker = %sourceObject.sourceObject))
{
if(%sourceObject.getDataBlock().getName() $= "CrowbarProjectile")
{
if(%attacker != %player && (%player.getClassName() $= "Player" || %player.getClassName() $= "AIPlayer"))
{
%impactImpulse = 2;
%verticalImpulse = 3;

%player.setVelocity(vectorAdd(%player.getVelocity(), vectorAdd(vectorScale(%attacker.getForwardVector(), %impactImpulse), "0 0" SPC %verticalImpulse)));
}
}
}

parent::damage(%data, %player, %sourceObject, %pos, %damage, %type);
}
};
activatePackage(Crowbar);

Alright, thanks for the help.