Cinematic Knockback for a weapon

Hello!

I’m new to the forums :slight_smile:
I am creating a GMOD weapon that has a cinematic knockback, which means the knockback has to be SO strong, that the NPC-s ragdoll would be flying back with arms and legs flying on the front, but sadly I have no idea, how to do so :frowning:
So, I need help, how do I do that?
What codes should I use?

Regards,
Kristjan :slight_smile:

You can increase the amount of force that the bullets impart onto the NPC. Change this in the table you are using to fire the bullets. [lua]bullet.Force=1000[/lua]

Thank you! I’ll try it out! :slight_smile:

[editline]4th September 2011[/editline]

When I add it to my shared.lua file and open up GMOD, the gun doesn’t show up on the weapon list :frowning:

Any help?

Do you know any lua? It helps if you do :U

He means in the FireBullets table, change the bullet force to 1000, not just appending “bullet.force=1000” to the end of your script.

If you post the code it makes this ordeal easier.

Anything?

[lua]
barrel=ents.create(“prop_physics”)
barrel:SetModel(“models/props_c17/oildrum001.mdl”)
barrel:SetPos(Vector(0,0,0))
barrel:Spawn()

bullet = {}
bullet.Num=1
bullet.Src=barrel:GetPos()
bullet.Dir=barrel:GetAngles():Forward()
bullet.Spread=Vector(0.01,0.01,0)
bullet.Tracer=1
bullet.Force=4000
bullet.Damage=1

barrel:FireBullets(bullet)
[/lua]

Should be:

[lua]
function SWEP:PrimaryAttack()
local barrel = ents.create(“prop_physics”);
barrel:SetModel(“models/props_c17/oildrum001.mdl”);
barrel:SetPos( Vector(0, 0, 0) );
barrel:Spawn();

    local bullet = {};
    bullet.Num = 1;
    bullet.Src = barrel:GetPos();
    bullet.Dir = barrel:GetAngles():Forward();
    bullet.Spread = Vector(0.01, 0.01, 0);
    bullet.Tracer = 1;
    bullet.Force = 4000;
    bullet.Damage = 1;

    barrel:FireBullets(bullet);

end;
[/lua]

Bullet and barrel doesn’t need to be global either. Neatened the code also.

Also try this: http://wiki.garrysmod.com/?title=Lua_Tutorial_Series

After adding that to a swep (Shared.lua) i get this error while firing.

[ERROR] gamemodes/darkrp/entities/weapons/weapon_pumpshotgun3/shared.lua:113: attempt to call field ‘Create’ (a nil value)

  1. unknown - gamemodes/darkrp/entities/weapons/weapon_pumpshotgun3/shared.lua:113

[GonTar|45|STEAM_0:0:20325228] Lua Error:

[ERROR] gamemodes/darkrp/entities/weapons/weapon_pumpshotgun3/shared.lua:113: attempt to call field ‘Create’ (a nil value)

  1. unknown - gamemodes/darkrp/entities/weapons/weapon_pumpshotgun3/shared.lua:113

Any Solution?

Put that code in a “if SERVER then” statement. That code needs to be serverside only


[ERROR] gamemodes/darkrp/entities/weapons/weapon_pumpshotgun3/shared.lua:114: attempt to call field 'create' (a nil value)
  1. unknown - gamemodes/darkrp/entities/weapons/weapon_pumpshotgun3/shared.lua:114

now that error is stopping the swep from working :s

thanks in advance, i also wanted to give the damaged player a “camera shake” or “flash” effect, how to implement that into code for a Swep?

Also this is how its looking atm:


if SERVER then function SWEP:PrimaryAttack()
        local barrel = ents.create("prop_physics");
        barrel:SetModel("models/props_c17/oildrum001.mdl");
        barrel:SetPos( Vector(0, 0, 0) );
        barrel:Spawn();

        local bullet = {};
        bullet.Num = 4;
        bullet.Src = barrel:GetPos();
        bullet.Dir = barrel:GetAngles():Forward();
        bullet.Spread = Vector(0.01, 0.01, 0);
        bullet.Tracer = 1;
        bullet.Force = 4000;
        bullet.Damage = 1;

        barrel:FireBullets(bullet);
		end 
end

And i want to make it check damage dealt to the player, and make it shake its screen or flash is if hit with X or greater ammount of damage. Its been years sinse i coded anything and im rly having a rough time coming back Xd

Check that out and look into implementing it.

Thx 4 the link (y)

Edit: Can you help me with the Code for the swep im trying to create?

Well, can anyone help me? :slight_smile:

ents.create should be ents.Create.

100% True, i can’t believe i didn’t see it! Thanks 4 the correction.
Now i have a swep that spawns a barrel on the center of the map, i didn’t expect that to be honest Xd

Still Can’t use it to push a player (knockback) and shake its screen :blush:

Do you want the “bullet” to be a barrel or was that for testing purposes?

That was the 1ºst comment guy, im scripting a swep and i need the bullets to check for damaged targets to deal knockback n screen shaking. Im stuck at this part cause i never used this coding language :blush:

thats why im asking 4 help of good willed Coders :slight_smile:

[editline]26th November 2014[/editline]

If you could help me find the right hooks / codes to check and get the damaged player to do something like this:

If damage is dealt Then
get damaged player and apply “X” KnockBack with bullet dicertion vector
And Apply Screen Shaking FX during “X” ammount of time xD