1+ const RustPlus = require ( '../rustplus' ) ;
2+ const Camera = require ( "../camera" ) ;
3+ var rustplus = new RustPlus ( 'ip' , 'port' , 'playerId' , 'playerToken' ) ;
4+
5+ function delay ( time ) {
6+ return new Promise ( resolve => setTimeout ( resolve , time ) ) ;
7+ }
8+
9+ rustplus . on ( 'connected' , async ( ) => {
10+
11+ console . log ( "connected" ) ;
12+
13+ // get a camera (should be an autoturret for this example)
14+ const turret = rustplus . getCamera ( "TURRET1" ) ;
15+
16+ // wait until subscribed to autoturret camera
17+ turret . on ( 'subscribed' , async ( ) => {
18+
19+ // check if camera is an auto turret
20+ if ( ! turret . isAutoTurret ( ) ) {
21+ console . log ( "Camera is not an auto turret!" ) ;
22+ await rustplus . disconnect ( ) ;
23+ return ;
24+ }
25+
26+ console . log ( "subscribed to autoturret camera" ) ;
27+ await delay ( 500 ) ;
28+
29+ const shootCount = 3 ;
30+ const shootDelay = 250 ;
31+ const moveDelay = 500 ;
32+ const moveAmount = 5 ;
33+
34+ // shoot autoturret
35+ console . log ( "shooting" ) ;
36+ for ( let i = 0 ; i < shootCount ; i ++ ) {
37+ await delay ( shootDelay ) ;
38+ await turret . shoot ( ) ;
39+ }
40+
41+ // move autoturret left
42+ console . log ( "moving left" ) ;
43+ await delay ( moveDelay ) ;
44+ await turret . move ( Camera . Buttons . NONE , - moveAmount , 0 ) ;
45+
46+ // shoot autoturret
47+ console . log ( "shooting" ) ;
48+ for ( let i = 0 ; i < shootCount ; i ++ ) {
49+ await delay ( shootDelay ) ;
50+ await turret . shoot ( ) ;
51+ }
52+
53+ // move autoturret up
54+ console . log ( "moving up" ) ;
55+ await delay ( moveDelay ) ;
56+ await turret . move ( Camera . Buttons . NONE , 0 , moveAmount ) ;
57+
58+ // shoot autoturret
59+ console . log ( "shooting" ) ;
60+ for ( let i = 0 ; i < shootCount ; i ++ ) {
61+ await delay ( shootDelay ) ;
62+ await turret . shoot ( ) ;
63+ }
64+
65+ // move autoturret right
66+ console . log ( "moving right" ) ;
67+ await delay ( moveDelay ) ;
68+ await turret . move ( Camera . Buttons . NONE , moveAmount , 0 ) ;
69+
70+ // shoot autoturret
71+ console . log ( "shooting" ) ;
72+ for ( let i = 0 ; i < shootCount ; i ++ ) {
73+ await delay ( shootDelay ) ;
74+ await turret . shoot ( ) ;
75+ }
76+
77+ // move autoturret down
78+ console . log ( "moving down" ) ;
79+ await delay ( moveDelay ) ;
80+ await turret . move ( Camera . Buttons . NONE , 0 , - moveAmount ) ;
81+
82+ // shoot autoturret
83+ console . log ( "shooting" ) ;
84+ for ( let i = 0 ; i < shootCount ; i ++ ) {
85+ await delay ( shootDelay ) ;
86+ await turret . shoot ( ) ;
87+ }
88+
89+ console . log ( "disconnecting" ) ;
90+ await rustplus . disconnect ( ) ;
91+
92+ } ) ;
93+
94+ // subscribe to autoturret camera
95+ await turret . subscribe ( ) ;
96+
97+ } ) ;
98+
99+ // connect to rust server
100+ rustplus . connect ( ) ;
0 commit comments