The problem with using [URL="http://wiki.garrysmod.com/page/Player/SetAllowWeaponsInVehicle"]Player:SetAllowWeaponsInVehicle[/URL], is that you can't really shoot out of the car without killing yourself, because it just shoots the car, which ends up killing you. Is there a way to fix this? Like maybe edit bullet collision groups, or something? I'd love to get this to work properly.
You need a custom weapon base that handles this.
You can prevent the damage in the EntityTakeDamage hook, but it'd be better if the vehicle itself had a proper physics object that allowed that, like the Jalopy does, or the seats themselves.
After about 30 minutes of looking through pages of the "Next Update" thread, I found what i was looking for:
[URL="http://facepunch.com/showthread.php?t=1374457&p=44921124&viewfull=1#post44921124"]http://facepunch.com/showthread.php?t=1374457&p=44921124&viewfull=1#post44921124[/URL]
Read that and _Kilburn's reply.
[QUOTE=G4MB!T;45395441]After about 30 minutes of looking through pages of the "Next Update" thread, I found what i was looking for:
[URL="http://facepunch.com/showthread.php?t=1374457&p=44921124&viewfull=1#post44921124"]http://facepunch.com/showthread.php?t=1374457&p=44921124&viewfull=1#post44921124[/URL]
Read that and _Kilburn's reply.[/QUOTE]
I already knew this had to be setup by the users, but how would you do this in a weapon base? I have one already made, what do I need to do?
This is the code i added to my Mad Cows Weapons to account for this:
[code]
local source = self.Owner:GetShootPos();
if (self.Owner:InVehicle()) then
// first we trace from where we are to where we are shooting
local tr1 = {}
tr1.start = self.Owner:GetShootPos();
tr1.endpos = self.Owner:GetShootPos() + (self.Owner:GetAimVector() * (4096 * 8));
tr1.filter = {self.Owner, self.Owner:GetVehicle()};
if (IsValid(self.Owner:GetVehicle())) then
table.insert(tr1.filter, self.Owner:GetVehicle():GetParent());
end
local trace1 = util.TraceLine(tr1);
// then we trace from the hitpos of trace1 BACK to where we were shooting from with no vehicle filters
local tr2 = {}
tr2.start = trace1.HitPos;
tr2.endpos = tr1.start;
tr2.filter = {self.Owner, trace1.Entity};
local trace2 = util.TraceLine(tr2);
if (IsValid(trace2.Entity)) then
source = trace2.HitPos - (trace2.Normal * 8);
end
end
[/code]
This is great code, thank you so much.
[URL="http://wiki.garrysmod.com/page/util/TraceLine"]util.TraceLine[/URL]
Sorry, you need to Log In to post a reply to this thread.