finding a special player id in timer function...
5 replies



01.08.22 10:38:32 am
I wanted to create a bot that automatically talk; so i writed this code...
the only problem im facing is the "id" thing in the timer! the bot is speaking in different "teamcolor" than the team he really is in...
Edit: sorry if i had some stupid scripting mistakes im still new to it, and sorry for my bad english.
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
49
50
51
52
53
54
55
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
49
50
51
52
53
54
55
teamcolor = {}
addhook("spawn" ,"playerspawn")
function playerspawn(id)
if player(id,"team") == 1 then
teamcolor[id] = "\169255025000"
else
teamcolor[id] = "\169050150255"
end
end
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
local playerlist = player(0,"tableliving")
for _,id in pairs(playerlist) do
local nahezspeaks = math.random(1,7)
if nahezspeaks == 1 then
msg(""..teamcolor[id].."nahez: hey")
return 1
else
if nahezspeaks == 2 then
msg(""..teamcolor[id].."nahez: hello")
return 1
else
if nahezspeaks == 3 then
msg(""..teamcolor[id].."nahez: test")
return 1
else
if nahezspeaks == 4 then
msg(""..teamcolor[id].."nahez: hhhh")
return 1
else
if nahezspeaks == 5 then
msg(""..teamcolor[id].."nahez: asfaf")
return 1
else
if nahezspeaks == 6 then
msg(""..teamcolor[id].."nahez: gfdgfd")
return 1
else
if nahezspeaks == 7 then
msg(""..teamcolor[id].."nahez: eyffdsa")
return 1
end
end
end
end
end
end
end
end
end
addhook("spawn" ,"playerspawn")
function playerspawn(id)
if player(id,"team") == 1 then
teamcolor[id] = "\169255025000"
else
teamcolor[id] = "\169050150255"
end
end
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
local playerlist = player(0,"tableliving")
for _,id in pairs(playerlist) do
local nahezspeaks = math.random(1,7)
if nahezspeaks == 1 then
msg(""..teamcolor[id].."nahez: hey")
return 1
else
if nahezspeaks == 2 then
msg(""..teamcolor[id].."nahez: hello")
return 1
else
if nahezspeaks == 3 then
msg(""..teamcolor[id].."nahez: test")
return 1
else
if nahezspeaks == 4 then
msg(""..teamcolor[id].."nahez: hhhh")
return 1
else
if nahezspeaks == 5 then
msg(""..teamcolor[id].."nahez: asfaf")
return 1
else
if nahezspeaks == 6 then
msg(""..teamcolor[id].."nahez: gfdgfd")
return 1
else
if nahezspeaks == 7 then
msg(""..teamcolor[id].."nahez: eyffdsa")
return 1
end
end
end
end
end
end
end
end
end
the only problem im facing is the "id" thing in the timer! the bot is speaking in different "teamcolor" than the team he really is in...
Edit: sorry if i had some stupid scripting mistakes im still new to it, and sorry for my bad english.
you have to find the id(s) of your bot(s) and save them, with your approach you will get <number of living player>-times a message, all in different colours (depending on the team of the players).
furthermore i cleaned your code a bit.
The code is untested!
edit: maybe you take a look into the awesome tutorial by
Starkkz:
[GUIDE] How to script
furthermore i cleaned your code a bit.
The code is untested!
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
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
botIDs = {}
teamcolor = {}
addhook("spawn" ,"playerspawn")
function playerspawn(id)
if player(id,"bot") == true then
table.insert(botIDs, id)
if player(id,"team") == 1 then
table.insert(teamcolor, "\169255025000")
else
table.insert(teamcolor, "\169050150255")
end
end
end
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
for index,id in ipairs(botIDs) do
if player(id,"health") > 0 then
local nahezspeaks = math.random(1,7)
if nahezspeaks == 1 then
msg(""..teamcolor[index].."nahez: hey")
elseif nahezspeaks == 2 then
msg(""..teamcolor[index].."nahez: hello")
elseif nahezspeaks == 3 then
msg(""..teamcolor[index].."nahez: test")
elseif nahezspeaks == 4 then
msg(""..teamcolor[index].."nahez: hhhh")
elseif nahezspeaks == 5 then
msg(""..teamcolor[index].."nahez: asfaf")
elseif nahezspeaks == 6 then
msg(""..teamcolor[index].."nahez: gfdgfd")
elseif nahezspeaks == 7 then
msg(""..teamcolor[index].."nahez: eyffdsa")
end
end
end
end
teamcolor = {}
addhook("spawn" ,"playerspawn")
function playerspawn(id)
if player(id,"bot") == true then
table.insert(botIDs, id)
if player(id,"team") == 1 then
table.insert(teamcolor, "\169255025000")
else
table.insert(teamcolor, "\169050150255")
end
end
end
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
for index,id in ipairs(botIDs) do
if player(id,"health") > 0 then
local nahezspeaks = math.random(1,7)
if nahezspeaks == 1 then
msg(""..teamcolor[index].."nahez: hey")
elseif nahezspeaks == 2 then
msg(""..teamcolor[index].."nahez: hello")
elseif nahezspeaks == 3 then
msg(""..teamcolor[index].."nahez: test")
elseif nahezspeaks == 4 then
msg(""..teamcolor[index].."nahez: hhhh")
elseif nahezspeaks == 5 then
msg(""..teamcolor[index].."nahez: asfaf")
elseif nahezspeaks == 6 then
msg(""..teamcolor[index].."nahez: gfdgfd")
elseif nahezspeaks == 7 then
msg(""..teamcolor[index].."nahez: eyffdsa")
end
end
end
end
edit: maybe you take a look into the awesome tutorial by



edited 1×, last 02.08.22 12:20:36 pm
loading...
@
Cebra: If we are talking "player" bots, honestly it'll be better to try and incorporate
ai_say into it, if it works outside the confines of AI scripting.
Might need to find a way to not make them all say their lines simutaneously though.


Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bottext = {
"hey",
"hello",
"test",
"hhhh",
"asfaf",
"gfdgfd",
"eyffdsa"
}
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
for index, id in pairs(player(0,"tableliving")) do
if player(id,"bot") then
ai_say(id,bottext[math.random(1,#bottext)])
end
end
end
"hey",
"hello",
"test",
"hhhh",
"asfaf",
"gfdgfd",
"eyffdsa"
}
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
for index, id in pairs(player(0,"tableliving")) do
if player(id,"bot") then
ai_say(id,bottext[math.random(1,#bottext)])
end
end
end
Might need to find a way to not make them all say their lines simutaneously though.
edited 1×, last 09.11.22 03:00:06 pm


@
Cure Pikachu: yes, you are right, didn't noticed this function and fixed only his code ^^'

loading...

@
Cebra: If we are talking "player" bots, honestly it'll be better to try and incorporate
ai_say into it, if it works outside the confines of AI scripting.
Might need to find a way to not make them all say their lines simutaneously though.


Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bottext = {
"hey",
"hello",
"test",
"hhhh",
"asfaf",
"gfdgfd",
"eyffdsa"
}
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
for index, id in pairs(player(0,"playerliving")) do
if player(id,"bot") then
ai_say(id,bottext[math.random(1,#bottext)])
end
end
end
"hey",
"hello",
"test",
"hhhh",
"asfaf",
"gfdgfd",
"eyffdsa"
}
timer(math.random(3000,5000),"naheztalking","",0)
function naheztalking()
for index, id in pairs(player(0,"playerliving")) do
if player(id,"bot") then
ai_say(id,bottext[math.random(1,#bottext)])
end
end
end
Might need to find a way to not make them all say their lines simutaneously though.
LUA ERROR: sys/lua/autorun/test.lua:14: bad argument #1 to 'pairs' (table expected, got boolean)
Replace
playerliving
in for index, id in pairs(player(0,"playerliving")) do
with tableliving
. Sorry I derped 
edited 1×, last 11.08.22 05:34:14 pm





