-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPlayer.simba
451 lines (395 loc) · 10.2 KB
/
Player.simba
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
{$include_once Internal/Reflection.simba}
{$include_once Constants.simba}
{$include_once Mainscreen.simba}
{$include_once Worlds.simba}
(*
PLAYER
======
Functions for your player and other visible players.
*)
type
RPlayer = record
LoginName: String;
Password: String;
BankPin: String;
isMember: Boolean;
isActive: Boolean;
World: Int32; // if not defined, will use random world using the filter
Data: Pointer;
end;
TRSPlayer = record
Name: String;
Tile: TPoint;
Destination: TPoint;
CombatLevel: Int32;
Equipment: Array of Int32;
AnimationId: Int32;
Health: Int32;
Orientation: Int32;
end;
TCameraHeight = (
MIN_HEIGHT = 0,
MAX_HEIGHT = 100);
TCameraZoom = (
MIN_ZOOM = 0,
HALF_ZOOM = 50,
MAX_ZOOM = 100);
const
//PITCH UTILITY
PITCH_MIN = 128;
PITCH_MAX = 383;
//YAW UTILITY
YAW_MIN = 0;
YAW_MAX = 2047;
//VARBITS
VARBIT_IS_POISONED = 102;
VARBIT_IS_ATTACKING_PLAYER = 1075;
VARBIT_IN_WILDERNESS = 5963;
(*
TRSPlayer Functions
===================
In-game functions for your player and other visible players.
*)
{*
R_GetMe
~~~~~~~
Returns a TRSPlayer containing information about the signed in account.
Example:
Me := R_GetMe;
*}
Function R_GetMe: TRSPlayer;
var
LocalPlayer: RSPlayer;
Definition: RSPlayerDefinition;
begin
LocalPlayer := RSPlayer.Me;
Definition := LocalPlayer.Definition;
Result.Name := LocalPlayer.Name;
Result.Tile := LocalPlayer.Tile;
Result.Destination := LocalPlayer.Destination;
Result.CombatLevel := LocalPlayer.CombatLevel;
Result.Equipment := Definition.Equipment;
Result.AnimationId := LocalPlayer.AnimationId;
Result.Health := LocalPlayer.Health;
Result.Orientation := LocalPlayer.Orientation;
Definition.Free;
LocalPlayer.Free;
end;
{*
R_GetPlayers
~~~~~~~~~~~~
Returns an array of TRSPlayer containing all visible players.
Example:
AllPlayers := R_GetPlayers;
*}
Function R_GetPlayers: Array of TRSPlayer;
var
I: Int32;
Players: Array of RSPlayer;
Definition: RSPlayerDefinition;
begin
Players := RSPlayer.AllPlayers;
SetLength(Result, Length(Players));
for I := 0 to high(Players) do
begin
Definition := Players[I].Definition;
Result[I].Name := Players[I].Name;
Result[I].Tile := Players[I].Tile;
Result[I].Destination := Players[I].Destination;
Result[I].CombatLevel := Players[I].CombatLevel;
Result[I].Equipment := [];
Result[I].AnimationId := Players[I].AnimationId;
Result[I].Health := Players[I].Health;
Result[I].Orientation := Players[I].Orientation;
Definition.Free;
end;
RSTypeArray(Players).Free;
end;
{*
R_GetAnimation
~~~~~~~~~~~~~~
Returns the Animation ID of your player.
Example:
MyAnimation := R_GetAnimation;
*}
Function R_GetAnimation: Int32;
var
Me: RSPlayer;
begin
Me := RSPlayer.Me;
Result := Me.AnimationId;
Me.Free;
end;
{*
R_IsMoving
~~~~~~~~~~
Returns true if the player is moving.
Example:
if R_IsMoving then
...
*}
Function R_IsMoving: Boolean;
var
Me: RSPlayer;
begin
Me := RSPlayer.Me;
Result := Me.IsMoving;
Me.Free;
end;
{*
R_GetDestination
~~~~~~~~~~~~~~~~
Returns the destination tile of the player.
Example:
if (R_GetMe.Tile.DistanceTo(R_GetDestination) < 9) then
...
*}
Function R_GetDestination: RSTile;
var
Me: RSPlayer;
begin
Me := RSPlayer.Me;
Result := Me.Destination;
Me.Free;
end;
{*
R_IsPoisoned
~~~~~~~~~~~~
Returns true if the player is poisoned.
Example:
if R_IsPoisoned then
...
*}
Function R_IsPoisoned: Boolean;
begin
Result := RSVarps.VarpMain(VARBIT_IS_POISONED) = 1;
end;
{*
R_IsAttackingPlayer
~~~~~~~~~~~~~~~~~~~
Returns true if the player is attacking another player.
Example:
if R_IsAttackingPlayer then
...
*}
Function R_IsAttackingPlayer: Boolean;
begin
Result := RSVarps.VarpMain(VARBIT_IS_ATTACKING_PLAYER) <> -1;
end;
{*
R_IsInWilderness
~~~~~~~~~~~~~~~~
Returns true if the player is in the wilderness.
Example:
if R_IsInWilderness then
...
*}
Function R_IsInWilderness: Boolean;
begin
Result := RSVarps.VarpMain(VARBIT_IN_WILDERNESS) = 1;
end;
{*
R_GetDirectionToMove - Utility Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Returns the direction to turn camera based off current camera position and
the desired point.
Results:
0: Left
1: Right
*}
Function R_GetDirectionToMove(DesiredPoint: Int32): Int32;
var
Val1, Val2, MiddlePoint: Integer;
begin
Val1 := RSCamera.Yaw + Round(YAW_MAX / 2);
Val2 := RSCamera.Yaw - Round(YAW_MAX / 2);
if (Val1 <= YAW_MAX) and (Val1 >= YAW_MIN) then
begin
MiddlePoint := Val1;
if (DesiredPoint <= MiddlePoint) and (DesiredPoint >= RSCamera.Yaw) then
Result := 1
else Result := 0;
end else if (Val2 <= YAW_MAX) and (Val2 >= YAW_MIN) then
begin
MiddlePoint := Val2;
if (DesiredPoint >= MiddlePoint) and (DesiredPoint <= RSCamera.Yaw) then
Result := 0
else Result := 1;
end else
Result := -1;
end;
Function R_CameraAngle: Int32;
begin
//UNIT := (PI / 1024.0); //Number of RS Units in a Circle.
//Result := Round(RSCamera.Yaw * (PI / 1024.0) * (180.0 / PI));
Result := Round(RSCamera.Yaw * (45.0 / 256.0));
end;
{*
R_SetCameraAngle
~~~~~~~~~~~~~~~~
Returns true if the camera height is set to the specified height as a percentage.
Accepts a value from 0 -> 360.
Example:
if R_SetCameraAngle(160) then
...
*}
Function R_SetCameraAngle(Degrees: Int32): Boolean;
var
DesiredAngle, AngleEdge1, AngleEdge2: Integer;
RandomizedRange: Int32;
begin
If (Degrees < 0) or (Degrees > 360) then
Exit(False);
DesiredAngle := Round(Degrees * (256 / 45));
RandomizedRange := RandomRange(35, 75);
AngleEdge1 := DesiredAngle - RandomizedRange;
AngleEdge2 := DesiredAngle + RandomizedRange;
if (AngleEdge1 < 0) then
AngleEdge1 := AngleEdge1 + YAW_MAX
else if (AngleEdge2 > YAW_MAX) then
AngleEdge2 := AngleEdge2 - YAW_MAX;
//Special Case
if (Min(AngleEdge1, AngleEdge2) = AngleEdge2) then
begin
While InRange(RSCamera.Yaw, AngleEdge2, AngleEdge1) do
begin
if (R_GetDirectionToMove(DesiredAngle) = 0)then
begin
if Keyboard.IsKeyDown(VK_RIGHT) then
Keyboard.KeyUp(VK_RIGHT);
if not Keyboard.IsKeyDown(VK_LEFT) then
Keyboard.KeyDown(VK_LEFT);
end else if (R_GetDirectionToMove(DesiredAngle) = 1) then
begin
if Keyboard.IsKeyDown(VK_LEFT) then
Keyboard.KeyUp(VK_LEFT);
if not Keyboard.IsKeyDown(VK_RIGHT) then
Keyboard.KeyDown(VK_RIGHT);
end;
Wait(25, RandomRange(50, 75));
end;
Result := Not InRange(RSCamera.Yaw, AngleEdge2, AngleEdge1);
end else
begin
While not InRange(RSCamera.Yaw, AngleEdge1, AngleEdge2) do
begin
if (R_GetDirectionToMove(DesiredAngle) = 0)then
begin
if Keyboard.IsKeyDown(VK_RIGHT) then
Keyboard.KeyUp(VK_RIGHT);
if not Keyboard.IsKeyDown(VK_LEFT) then
Keyboard.KeyDown(VK_LEFT);
end else if (R_GetDirectionToMove(DesiredAngle) = 1) then
begin
if Keyboard.IsKeyDown(VK_LEFT) then
Keyboard.KeyUp(VK_LEFT);
if not Keyboard.IsKeyDown(VK_RIGHT) then
Keyboard.KeyDown(VK_RIGHT);
end;
Wait(25, RandomRange(50, 75));
end;
Result := InRange(RSCamera.Yaw, AngleEdge1, AngleEdge2);
end;
if Keyboard.IsKeyDown(VK_RIGHT) then
Keyboard.KeyUp(VK_RIGHT)
else if Keyboard.IsKeyDown(VK_LEFT) then
Keyboard.KeyUp(VK_LEFT);
end;
{*
R_SetCameraHeightPercent
~~~~~~~~~~~~~~~~~~~~~~~~
Returns true if the camera height is set to the specified height as a percentage.
Accepts a value from 0 -> 100.
Example:
if R_SetCameraHeightPercent(100) then
...
*}
Function R_SetCameraHeightPercent(Height: Int32): Boolean;
var
DesiredPitch: Extended;
RandomizedRange: Int32;
begin
If (Height < Ord(MIN_HEIGHT)) or (Height > Ord(MAX_HEIGHT)) then
Exit(False);
DesiredPitch := ((PITCH_MAX - PITCH_MIN) * (Height / 100)) + PITCH_MIN;
RandomizedRange := RandomRange(5, 30);
While (not InRange(RSCamera.Pitch, DesiredPitch - RandomizedRange, DesiredPitch + RandomizedRange)) do
begin
if (RSCamera.Pitch > DesiredPitch) then
begin
if Keyboard.IsKeyDown(VK_UP) then
Keyboard.KeyUp(VK_UP);
if not Keyboard.IsKeyDown(VK_DOWN) then
Keyboard.KeyDown(VK_DOWN);
end else if (RSCamera.Pitch < DesiredPitch) then
begin
if Keyboard.IsKeyDown(VK_DOWN) then
Keyboard.KeyUp(VK_DOWN);
if not Keyboard.IsKeyDown(VK_UP) then
Keyboard.KeyDown(VK_UP);
end;
Wait(25, RandomRange(50, 75));
end;
if Keyboard.IsKeyDown(VK_DOWN) then
Keyboard.KeyUp(VK_DOWN)
else if Keyboard.IsKeyDown(VK_UP) then
Keyboard.KeyUp(VK_UP);
Result := InRange(RSCamera.Pitch, DesiredPitch - RandomizedRange, DesiredPitch + RandomizedRange);
end;
{*
R_SetCameraHeight
~~~~~~~~~~~~~~~~~
Returns true if the camera height was set to the specified height.
Acceptable Inputs:
- MAX_HEIGHT
- MIN_HEIGHT
Example:
if R_SetCameraHeight(MAX_HEIGHT) then
...
*}
Function R_SetCameraHeight(Height: TCameraHeight): Boolean;
begin
Result := R_SetCameraHeightPercent(Ord(Height));
end;
{*
R_SetCameraZoomPercent
~~~~~~~~~~~~~~~~~
Returns true if the camera zoom was set to the specified zoom.
Example:
if R_SetCameraZoomPercent(75) then
...
*}
Function R_SetCameraZoomPercent(Zoom: Int32): Boolean;
var
Widget: RSWidget;
RandomizedRange: Int32;
begin
Widget := RSWidget.Get(R_SETTINGS_DISPLAY_ZOOM_SLIDER.Group, R_SETTINGS_DISPLAY_ZOOM_SLIDER.Child);
RandomizedRange := RandomRange(7, 20);
Mouse.Move(R_MainscreenBounds, False);
While (not InRange(Widget.RelativeX, Zoom - RandomizedRange, Zoom + RandomizedRange)) do
begin
if (Widget.RelativeX > Zoom) then
Mouse.Scroll(RandomRange(1, 3), False)
else if (Widget.RelativeX < Zoom) then
Mouse.Scroll(RandomRange(1, 3), True);
end;
Result := InRange(Widget.RelativeX, Zoom - RandomizedRange, Zoom + RandomizedRange);
Widget.Free;
end;
{*
R_SetCameraZoom
~~~~~~~~~~~~~~~~~
Returns true if the camera zoom was set to the specified zoom.
Acceptable Inputs:
- MAX_ZOOM
- HALF_ZOOM
- MIN_ZOOM
Example:
if R_SetCameraZoom(MAX_ZOOM) then
...
*}
Function R_SetCameraZoom(Zoom: TCameraZoom): Boolean;
begin
Result := R_SetCameraZoomPercent(Ord(Zoom));
end;