-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path10_shoot_autoturret.js
100 lines (78 loc) · 2.67 KB
/
10_shoot_autoturret.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const RustPlus = require('../rustplus');
const Camera = require("../camera");
var rustplus = new RustPlus('ip', 'port', 'playerId', 'playerToken');
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
rustplus.on('connected', async () => {
console.log("connected");
// get a camera (should be an autoturret for this example)
const turret = rustplus.getCamera("TURRET1");
// wait until subscribed to autoturret camera
turret.on('subscribed', async () => {
// check if camera is an auto turret
if(!turret.isAutoTurret()){
console.log("Camera is not an auto turret!");
await rustplus.disconnect();
return;
}
console.log("subscribed to autoturret camera");
await delay(500);
const shootCount = 3;
const shootDelay = 250;
const moveDelay = 500;
const moveAmount = 5;
// shoot autoturret
console.log("shooting");
for(let i = 0; i < shootCount; i++){
await delay(shootDelay);
await turret.shoot();
}
// move autoturret left
console.log("moving left");
await delay(moveDelay);
await turret.move(Camera.Buttons.NONE, -moveAmount, 0);
// shoot autoturret
console.log("shooting");
for(let i = 0; i < shootCount; i++){
await delay(shootDelay);
await turret.shoot();
}
// move autoturret up
console.log("moving up");
await delay(moveDelay);
await turret.move(Camera.Buttons.NONE, 0, moveAmount);
// shoot autoturret
console.log("shooting");
for(let i = 0; i < shootCount; i++){
await delay(shootDelay);
await turret.shoot();
}
// move autoturret right
console.log("moving right");
await delay(moveDelay);
await turret.move(Camera.Buttons.NONE, moveAmount, 0);
// shoot autoturret
console.log("shooting");
for(let i = 0; i < shootCount; i++){
await delay(shootDelay);
await turret.shoot();
}
// move autoturret down
console.log("moving down");
await delay(moveDelay);
await turret.move(Camera.Buttons.NONE, 0, -moveAmount);
// shoot autoturret
console.log("shooting");
for(let i = 0; i < shootCount; i++){
await delay(shootDelay);
await turret.shoot();
}
console.log("disconnecting");
await rustplus.disconnect();
});
// subscribe to autoturret camera
await turret.subscribe();
});
// connect to rust server
rustplus.connect();