Two problems: Activate map event, and detect when SWEP is fired without editing base code

Hello.

I’m working on my Jailbreak gamemode, and I have a question. I have a command system i’ve done, and I can make a command such as “/cells open” and “/cells close”. All of it works, except for the main thing. How can I control the cells via script? Is there something I can activate on the entity or what?

Also, second,

How would I be able to detect when a player fires their SWEP without editing any weapon code? Thanks a lot!

It depends on your cell doors. You could make a list of entities in your code and fire an output on all of them.

And you can’t really detect when a weapon shoots without editing the code.

Why not do something like:

[lua]
for k, v in pairs( weapons.GetList() ) do
local old_func = v.PrimaryAttack
function v:PrimaryAttack()
– do things before
old_func( self )
– do things after
end
end
[/lua]

Because it is not applicable for HL2 weapons and SWEP:PrimaryAttack being called does not mean the weapon has shot.

If the weapon shoots bullets, you could potentially capture it with GM:EntityFireBullets but that doesn’t report the inflictor, so you can’t be certain that the player has fired a gun instead of, say, a turret, a grenade that shoots bullets for the player, or anything like that, so it shouldn’t be treated as completely reliable.

You could always hope they use mouse1 and check for that :v: (That’s actually a really bad idea I advise you not to,)

Why would you do that if you could just detour it in the weapon metatable?

This worked for what I wanted, I just wanted to make a simple script to give a player a bullet after another shoots, this is what I did.



	hook.Add( "EntityFireBullets", "GiveNextBullet", function(ent, data)
		if ( ent:IsPlayer() ) and ( ( ent == jb.lrParticipant1 ) or ( ent == jb.lrParticipant2 ) ) then
			if ( ent == jb.lrParticipant1 ) then -- Prisoner shot
				jb.lrParticipant2:SetAmmo(1, "CombineCannon");
			elseif ( ent == jb.lrParticipant2 ) then -- Guard shot
				jb.lrParticipant1:SetAmmo(1, "CombineCannon");
			end
		end
	end)