I'm using a custom Jailbreak plugin for my server which when a Guard/Prisoner dies they drop everything they have. As this isn't something I want due to it been a little to OP in my opinion, I want one gun to drop by random or just the gun they're holding out at the time of death. This is the current code which I believe it needs to be near:
[CODE]function GM:PlayerDeath(victim, weapon, killer)
--self.BaseClass:PlayerDeath(victim, weapon, killer);
if ( DEATH_SOUNDS[ victim:Team()] ) then
victim:EmitSound( table.Random( DEATH_SOUNDS[ victim:Team() ] ), 130 );
end;
for k, v in pairs( victim:GetWeapons() ) do
local class = v:GetClass();
if ( !table.HasValue(PREVENT_DROP, class) ) then
self:CreateGun( class, v:GetPos() );
end;
end;[/CODE]
What do I need to add? Could someone please help, thanks in advance.
You could create a table with all the possible weapons they can drop, and then create that weapon on death with table.Random
Would that work? Because they don't always have every single gun? If you don't mind what would that look like? I'm not the best coder.
100% untested and more than likely wrong but it would look something like this:
[CODE]function GM:PlayerDeath(victim, weapon, killer)
--self.BaseClass:PlayerDeath(victim, weapon, killer);
if ( DEATH_SOUNDS[ victim:Team()] ) then
victim:EmitSound( table.Random( DEATH_SOUNDS[ victim:Team() ] ), 130 );
end;
local weapon = {victim:GetWeapons()}
self:CreateGun(table.Random(weapon:GetClass()), victim:GetPos())
end;
[/CODE]
[QUOTE=Fortune11709;43375645]100% untested and more than likely wrong but it would look something like this:
[CODE]function GM:PlayerDeath(victim, weapon, killer)
--self.BaseClass:PlayerDeath(victim, weapon, killer);
if ( DEATH_SOUNDS[ victim:Team()] ) then
victim:EmitSound( table.Random( DEATH_SOUNDS[ victim:Team() ] ), 130 );
end;
local weapon = {victim:GetWeapons()}
self:CreateGun(table.Random(weapon:GetClass()), victim:GetPos())
end;
[/CODE][/QUOTE]
GetWeapons() already returns a table. Also you're trying to do table.Random after doing the GetClass(). You should be doing table.Random(victim:GetWeapons()):GetClass()
One other concern is that I'm sure there is a reason that this bit of code exists in the OPs code chunk: !table.HasValue(PREVENT_DROP, class). Seems to me like there is a table of weapons (PREVENT_DROP) that shouldn't be dropped for some reason or another.
Probably should do something like this
[CODE]
local droppableWeapons = {}
for k, v in pairs( victim:GetWeapons() ) do
local class = v:GetClass()
if ( !table.HasValue(PREVENT_DROP, class) ) then
table.insert(droppableWeapons, class)
end
end
self.CreateGun(table.Random(droppableWeapons), victim:GetPos())
[/CODE]
Thanks for the help, then I'd put all the weapons in after that bit of code? What if a person doesn't have a certain weapon? does the code automatically find that and then not attempt to drop it?
Not too sure what you mean.
victim:GetWeapons() will get a table of every weapon that the victim is holding, so if a person doesn't have a certain weapon, then the GetWeapons() function will not return it.
The for loop will go through each weapon that the victim currently has and sees if it is in the PREVENT_DROP table. If it is NOT in that table, then that means we are able to drop it. So I add it into the droppableWeapons table. Then once the for loop is finished, the droppableWeapons table will contain every weapon that the victim was carrying that is allowed to be dropped. Finally, I get a random weapon from the droppableWeapons table and create it at the victims position.
Ah so it's the exact code you made for me? Thanks a lot, as you can tell I know little to no Lua.
It didn't work and I got errors, heres the code [url]http://pastebin.com/TDNpXfTJ[/url] (it's mainly the top part)
I should add that the guards drop nothing due to this. Is it also possible to stop them picking up Grenades? so they actually get a gun other than a one time use thing?
It works now, however the end of round slow motion doesnt work, and the bodies dis-appear upon death.
Thanks for the above fix, is there anything I could do to stop this? by disabling the code it all works again.
How do I do that? The file i'm using for this code is sv_hook.lua and I'm only overwriting
[CODE]for k, v in pairs( victim:GetWeapons() ) do
local class = v:GetClass();
if ( !table.HasValue(PREVENT_DROP, class) ) then
self:CreateGun( class, v:GetPos() );
end;
end;[/CODE]
Also this is a full gamemode, not just an addon.
I'm not making two functions though, I'm adding to the same function?
[CODE]function GM:PlayerDeath(victim, weapon, killer)
--self.BaseClass:PlayerDeath(victim, weapon, killer);
if ( DEATH_SOUNDS[ victim:Team()] ) then
victim:EmitSound( table.Random( DEATH_SOUNDS[ victim:Team() ] ), 130 );
end;
local droppableWeapons = {}
for k, v in pairs( victim:GetWeapons() ) do
local class = v:GetClass()
if ( !table.HasValue(PREVENT_DROP, class) ) then
table.insert(droppableWeapons, class)
// self:CreateGun( class, v:GetPos() );
end;
end;
self:CreateGun(table.Random(droppableWeapons), victim:GetPos())
/* for k, v in pairs( victim:GetWeapons() ) do
local class = v:GetClass();
if ( !table.HasValue(PREVENT_DROP, class) ) then
self:CreateGun( class, v:GetPos() );
end;
end;*/[/CODE]
It's something to do with removing the bottom code, the only thing different was this self:CreateGun( class, v:GetPos() ); not been in the code given to me, I tried to add it as displayed above but I don't think it worked. I'll search all my folders for this "GM:PlayerDeath"
Sorry, you need to Log In to post a reply to this thread.