Forum

> > CS2D > Scripts > Player kill himself
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Player kill himself

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Player kill himself

RebornDuck
User Off Offline

Zitieren
Hi!

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

Thanks.

alt Re: Player kill himself

WinterPwnd
User Off Offline

Zitieren
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.

alt Re: Player kill himself

RebornDuck
User Off Offline

Zitieren
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!

alt Re: Player kill himself

Avo
User Off Offline

Zitieren
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.
1× editiert, zuletzt 07.03.13 17:47:26

alt Re: Player kill himself

Alistaire
User Off Offline

Zitieren
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.

alt Re: Player kill himself

RebornDuck
User Off Offline

Zitieren
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!

alt Re: Player kill himself

Cure Pikachu
User Off Offline

Zitieren
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

alt Re: Player kill himself

Alistaire
User Off Offline

Zitieren
user Cure Pikachu hat geschrieben
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht