[GM10] Making OnPlayerDeath run a programm on the player's / client's computer.

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?


Smells like warez.

-snip- If it’s warez I’ll not contribute… Confirm that you’re running legit copy?

I still call it GMod 10 ;X

Ok then, well here’s my post:

You can’t execute exe/programs on the client computer, the system functions were removed for security reasons.

Additionally, sv_allowcslua must be enabled if it isn’t your server to run code. PlayerDeath is a SERVER-side hook.

If you want to use a PlayerDeath type hook which works on the CLIENT use game-events:


entity_killed, the last one in the list is which one you’d need.


there’s no need to get that complicated unless op wants to add colors or something

you could just do
hook.Add( “PlayerDeath”, “MutePlayer”, function(victim, inflictor, attacker)
victim:ChatPrint(“Du bist gestorben”)

Yeah, but he said he wants it only client-side.

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

end );[/lua]

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!” );

what do i believe

I read this part:

Which led me to believe he wanted it client-side only to begin with :-/

But, yeah, if he wants it Server-side now, then he’d need to network something to reach the player to modify the team-speak module which would be client-side…

For that he’d need to understand networking - I have a tutorial on networking booleans however he would only need to send an empty flag: https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_booleans.lua

I do have a start of a tutorial using 1 message for both client/server in an “understanding realms” scenario. https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_understanding_realms.lua

I need to write in examples which cover the same thing as my net library: https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_realms.txt

Really? I only wanted to add that it’s about Garry’s Mod, didn’t think about which version it is.
(Ok, it might have been obvious because it’s in the Garry’s Mod thread… my fault ^^)

It’s not important for me if it is client-side or server-side, but loading it as a client-script didn’t work with the PlayerDeath-Hook I thought it had to be done server-side.

Since Acecool said that running programs on a client’s computer was removed for security reasons, I don’t think I’ll find a way to mute the client on TeamSpeak.

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?

This whole concept feels like a waste of time. Just ban the people ghosting when you figure it out. :l