Forum

> > CS2D > Scripts > How to get player ID in variable ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to get player ID in variable ?

4 replies
To the start Previous 1 Next To the start

old How to get player ID in variable ?

SkullFace
User Off Offline

Quote
I was trying to get a player ID in a variable so I can easily kill the flag carrier after 60 seconds to prevent flag saving.
I feel like I'm doing this entirely wrong way but I can't imagine for myself any other way to do it.

Here's the code :
Spoiler >

old Re: How to get player ID in variable ?

Cure Pikachu
User Off Offline

Quote
Something like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
addhook("flagtake","no_bot_flag")
function no_bot_flag(id,team)
	if player(id,"bot") then
		return 1
	end
	-- Set bomb on carrier
	if team == 1 then
		timer(6000,"blueflagbomb",id)
	elseif team == 2 then
		timer(6000,"redflagbomb",id)
	end
end

-- Reset the "bomb" when round ends (that includes flag capture) or flag dropped on death
addhook("endround","resetflagbomb")
function resetflagbomb()
	freetimer("blueflagbomb")
	freetimer("redflagbomb")
end

addhook("die","resetflagbomb2")
function resetflagbomb2(id)
	-- not sure if this works
	if player(id,"flag") then
		local team = player(id,"team")
		if team == 1 then
			freetimer("blueflagbomb")
		elseif team == 2 then
			freetimer("redflagbomb")
		end
	end
end

function blueflagbomb(id)
	id = tonumber(id)
	if player(id,"flag") then
		parse("killplayer "..id)
		msg(player(id,"name").." didn't capture the blue flag in 60 seconds!")
	end
end

function redflagbomb(id)
	id = tonumber(id)
	if player(id,"flag") then
		parse("killplayer "..id)
		msg(player(id,"name").." didn't capture the red flag in 60 seconds!")
	end
end
The drawback is that using cs2d lua cmd timer means that if you want to implement a cs2d cmd hudtxt for this, it will be hard (at least to visualize).
edited 4×, last 23.07.18 01:30:00 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview