I’m trying to make a lua-script for Trouble In Terrorist town. (It’s only for a private server)
It is supposed to execute a programm on the computer, which mutes the player’s teamspeak (This is not the problem).
I tried to make it a client-side script, so that it’s executed on the clients computer, but it seems like the PlayerDeath hook doesn’t work when it’s opened as a client script via lua_openscript_cl (This is the problem >.<).
hook.Add( "PlayerDeath", "MutePlayer", function(victim, inflictor, attacker)
if ( victim == LocalPlayer()) then
LocalPlayer():ChatPrint("Du bist gestorben") <-- kept it like this for now
When I open it via lua_openscript, the hook does work but LocalPlayer() does not, which means that I can’t check if the dead player is the local player.
How can I run the script server-side and still make it affect one client only?
This is shared, so it’s called on the client and server:
// This is a basic template for creating game_event listeners/hooks with the purpose of including all
// arguments / table variables for each game-event to make it easily known which values can be accessed
// and when: entity_killed. entity_killed is triggered when the player or entity dies.
// SHARED-REALM – Both the CLIENT and SERVER can receive this hook.
hook.Add( “entity_killed”, “entity_killed:Example”, function( _data )
local _inflictor_index = _data.entindex_inflictor; // Same as Weapon:EntIndex( ); / weapon used to kill victim
local _attacker_index = _data.entindex_attacker; // Same as Player/Entity:EntIndex( ); / person or entity who did the damage
local _damagebits = _data.damagebits; // DAMAGE_TYPE…
local _victim_index = _data.entindex_killed; // Same as Victim:EntIndex( ); / the entity / player victim
// Called when a Player or Entity is killed
Using that, he can determine which player died, and then do what he needs to do. Because the EntIndex is included, he only needs to add: [lua]local _victim = Entity( _victim_index );[/lua] under the // Called when a Player or Entity is killed;
then, he needs to check various things such as:
[lua]// If the Entity isn’t valid, or if the entity is not a player, or if the entity is not the local player, return;
if ( !IsValid( _victim ) || !_victim:IsPlayer( ) || _victim != LocalPlayer( ) ) then return; end
// Now that the above check has passed, we know that the inverse is true: _victim is a VALID Entity, _victim is a PLAYER, and _victim is the LocalPlayer( ) – These are the conditions specified above.
// Add text telling the player that they are dead. Additionally, you can use _attacker_index to get who killed you, whether it’s a player or worldspawn, and also use _inflictor_index the same way as _victim to see what weapon / object killed you
chat.AddText( Color( 255, 0, 0, 255 ), “Sie sind tot!” );
TeamSpeak does inject some code into games for their overlay program. If you can find a Lua binding for that, then it could be possible. If not, you’d need to write a .dll for that, and distribute it to all users that play on the server and want the feature.
If you’re doing that to prevent ghosting, it’ll be impossible to ensure all clients have the DLL, unless you kick them if they don’t have it. If you do that, people will go to other servers.
Giving the .dll to all players wouldn’t be a problem because it’s only for a server that I use to play with my friends.
And it’s not even about “real” ghosting, the problem is just that we usually mute us when we’re dead but sometimes players still make a noise before they mute themselves (just because they didn’t see it comming) and
then everyone knows that someone got killed - this often leaked the traitor’s identity.
Using ingame voice would solve the problem, but TeamSpeak has a better quality and using ingame voice is quite annoying
Does anyone know another way to do this? Any way to get an external program (which all players would have) to notice a player’s death?