English How to get player ID in variable ?

4 replies
Goto Page
To the start Previous 1 Next To the start
Up
SkullFace
User
Offline Off
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 >
IMG:https://i.imgur.com/kZBVkjM.gif
22.07.18 11:05:13 am
Up
Cure Pikachu
User
Offline Off
Something like this?
Code:
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
IMG:https://i.imgur.com/DeSeUxC.png
IMG:https://i.imgur.com/xpsyQRX.png
23.07.18 01:23:43 am
Up
SkullFace
User
Offline Off
Hey, it works! Thanks

EDIT : What does
id = tonumber(id)
stand for ?
edited 2×, last 23.07.18 01:22:49 pm
IMG:https://i.imgur.com/kZBVkjM.gif
23.07.18 01:28:25 pm
Up
Yates
Reviewer
Offline Off
@user SkullFace:
id
when sent using cs2d lua cmd timer is converted to a string,
tonumber
converts it back to an integer.
23.07.18 01:29:16 pm
Up
Cure Pikachu
User
Offline Off
@user SkullFace:
id = tonumber(id)
is just a line that converts the type of
id
from string (cause of cs2d lua cmd timer) to number, so that you can use it in cs2d lua cmd player.
user DC, thread cs2d Spawn function has written:
cs2d lua cmd timer parameter is always a string. If you're already passing the player ID in correctly make sure to cast it

Yeah, ninja'd.
IMG:https://i.imgur.com/DeSeUxC.png
IMG:https://i.imgur.com/xpsyQRX.png
To the start Previous 1 Next To the start