Bolt Shotgun

I’m trying to script a shotgun that shoots crossbow bolts (XBowBolt). I can’t seem to make it shoot the bolts like the crossbow does. Can someone write me a shared.lua script for a bolt shotgun? Thanks in advance! :smiley:

This goes in requests.

Actually, I’m interested in knowing how to fire bolts myself, I couldn’t find anything on the valve wiki, I assume its just spawning them, setting an angle and set the velocity, but I could be wrong.,

Does anyone know something more about that?

It’s probably how most projectiles are coded. Entity spawns, changes it’s model to the crossbow bolt, then flies off. Code accordingly to match the crossbow.

If a pre-coded project exists, it doesn’t exist in GMod Lua, rather in the C++ of Half Life 2.

[cpp]// Create a new entity with CCrossbowBolt private data
CCrossbowBolt *pBolt = (CCrossbowBolt *)CreateEntityByName( “crossbow_bolt” );
UTIL_SetOrigin( pBolt, vecOrigin );
pBolt->SetAbsAngles( angAngles );
pBolt->Spawn();
pBolt->SetOwnerEntity( pentOwner );
[/cpp]

In Lua:
[lua]local owner = self:GetOwner() – for a SWEP.
local bolt = ents.Create(“crossbow_bolt”)
bolt:SetPos(owner:GetShootPos())
bolt:SetAngles(owner:EyeAngles())
bolt:Spawn()
bolt:SetOwner(owner)[/lua]

isn’t it EyeAngles()?

Oops :v:

can someone write me the full lua file? I’m at a loss here. thanks :slight_smile:

You actually have to set the velocity otherwise it will just fall down.
Standard velocity would be bolt:SetVelocity(ply:EyeAngles():Forward()*2000)

To make it a shot gun you will need to add a small random angle to the eye angles, or else they will just get stuck inside each other and not have a spread.