Forum

> > CS2D > Scripts > Player kill himself
Forums overviewCS2D overview Scripts overviewLog in to reply

English Player kill himself

9 replies
To the start Previous 1 Next To the start

old Player kill himself

RebornDuck
User Off Offline

Quote
Hi!

How can you check if a player killed himself (with /kill, gas grenade, molotov, etc)?

Thanks.

old Re: Player kill himself

WinterPwnd
User Off Offline

Quote
It should say <player name> died.
In most of the cases this will be a death from a deadly tile etc. but if there arent such on the map, then he suicided.

old Re: Player kill himself

RebornDuck
User Off Offline

Quote
I know that but I mean with lua, a code that returns if the player killed him self or someone else killed him.
That's why I put it in script forum!

old Re: Player kill himself

Avo
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
lastKill = {}
for i = 1, 32 do
	lastKill[i] = 0
end

addhook("kill","onKill")
onKill = function(killer,victim)
	lastKill[victim] = killer
end
addhook("join","onJoin")
onJoin = function(id)
	lastKill[id] = 0
end
selfKill = function(id)
	if lastKill[id] = id then return true else return false end
end

And in your script use:

1
2
3
if selfKill(id) then
	--// your code here
end

EDITED typo.
edited 1×, last 07.03.13 05:47:26 pm

old Re: Player kill himself

Alistaire
User Off Offline

Quote
First, you could try this lua and see what it prints in the console;

1
2
3
4
5
6
addhook('die', 'dieHook')

function dieHook(id, source)
	print('Killer id: '..source)
	print('Victim id: '..id)
end

If those two are the same, we could do something. Else, it's not possible with the die hook. You could use the sayhook, prolly.

old Re: Player kill himself

RebornDuck
User Off Offline

Quote
It printed the same and I tried to fix it, and so I did.
Here's the code:

1
2
3
4
5
6
addhook('die', 'dieHook')
function dieHook(id,killer,victim)
     if player(id,"killer") == player(id,"victim") then
		msg("This is a test!@C")
	end
end

Thank you for the tip!

old Re: Player kill himself

Cure Pikachu
User Off Offline

Quote
Seriously your knowledge of CS2D Lua scripting is very poor.
1
2
3
4
5
6
addhook('die','dieHook')
function dieHook(killer,victim)
	if killer == victim then
		msg("This is a test!@C")
	end
end

old Re: Player kill himself

Alistaire
User Off Offline

Quote
user Cure Pikachu has written
Seriously your knowledge of CS2D Lua scripting is very poor.
1
2
3
4
5
6
addhook('die','dieHook')
function dieHook(killer,victim)
	if killer == victim then
		msg("This is a test!@C")
	end
end


You understand the killer is the same as the victim, if the player kills himself with grenades, right?

To be entirely sure about it, I'd double check the weapon returned upon death by /kill. It's prolly 0 or something.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview