-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathside_step_shoot.py
81 lines (66 loc) · 1.93 KB
/
side_step_shoot.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Program to have a remote controlled player tap and strafe
import sys
import telnetlib
from time import sleep
import yaml
import requests
import random
config = yaml.safe_load(open('config.yaml'))
available_weapons = config['available_weapons']
HOST = config['host']
PORT = config['port']
welcome = "CSGO Remote Console Online"
endl = "\n"
# Runs commands on the csgo console
# Sleeps after for rate limiting but does not block
def run(command):
print "running: ", command
tn.write("echo Remote Command: " + command + endl)
tn.write(command + endl)
sleep(0.05)
def choose_weapon():
r = requests.get(url='http://twitch-chat:3000/words')
weapons = r.json()
if len(weapons) == 0:
return str(random.choice(available_weapons))
words = []
# shamelessly stolen from:
# https://www.saltycrane.com/blog/2007/09/how-to-sort-python-dictionary-by-keys/
for key, value in sorted(weapons.iteritems(), key=lambda (k,v): (v,k)):
print "%s: %s" % (key, value)
words.append(key)
result = "{0}".format(words[-1])
return result
def reinitialize():
r = requests.delete(url='http://twitch-chat:3000/reinitialize')
# Initialize csgo telnet connection
tn = telnetlib.Telnet(HOST, PORT)
tn.write("echo " + welcome + endl)
tn.read_until("Online")
print("Successfully Connected")
# Loop, waiting for signal that round has restarted
# Example: 0: Reinitialized 4 predictable entities
# Note: only seems to happen when I die, not when I live
#while True:
# tn.read_until("Reinitialized ")
# print "Round start"
# sleep(1.0)
# weapon = choose_weapon()
# run("buy " + weapon)
# reinitialize()
print "Start side shooting"
for i in [1,2,3]:
sleep(0.5)
run("+moveleft")
sleep(0.1)
run("-moveleft")
run("+attack")
run("-attack")
run("+attack")
run("-attack")
run("+moveright")
sleep(0.1)
run("-moveright")
sleep(0.1)
run("+reload")
run("-reload")