/
plabels.pwn
306 lines (247 loc) · 8.39 KB
/
plabels.pwn
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
// plabels.pwn - player labels
#include <a_samp>
#include <streamer>
#include <sscanf2>
#include <foreach>
#include <zcmd>
#define MAX_WEAPON_NAME 21
#define MAX_LABEL_STRING 256
#define LABEL_COLOR 0x20B2AAFF // light sea green
#define LABEL_DRAW_DISTANCE 20.0
#define LABEL_STREAM_DISTANCE 20.0
enum LabelMode {
MODE_DISABLED,
MODE_GLOBAL,
MODE_PLAYER
}
enum E_PLAYER_DATA {
Float:PLAYER_POS[3],
Float:PLAYER_ANGLE,
Float:PLAYER_HEALTH,
Float:PLAYER_ARMOUR,
PLAYER_INTERIOR,
PLAYER_VIRTUAL_WORLD,
PLAYER_SKIN,
PLAYER_PING,
PLAYER_MONEY,
PLAYER_WEAPON,
PLAYER_AMMO,
PLAYER_SCORE
}
new const WEAPON_NAMES[57][MAX_WEAPON_NAME] = {
"Fist", "Brass knuckles", "Golf club",
"Nightstick", "Knife", "Bat",
"Shovel", "Pool cue", "Katana",
"Chainsaw", "Purple dildo", "Dildo",
"Vibrator", "Vibrator", "Flowers",
"Cane", "Grenade", "Tear gas",
"Molotov", "Vehicle gun", "Vehicle gun",
"Unknown", "Colt 45", "Silenced pistol",
"Deagle", "Shotgun", "Sawn-off shotgun",
"Combat shotgun", "Mac-10", "MP5",
"AK-47", "M4", "Tec-9",
"Cuntgun", "Sniper", "Rocket launcher",
"Heat seeking RPG", "Flamethrower", "Minigun",
"Satchel", "Detonator", "Spraycan",
"Fire extinguisher","Camera", "Night vision goggles",
"Infrared goggles", "Parachute", "Fake pistol",
"Pistol whip", "Vehicle", "Helicopter blades",
"Explosion", "Car parking", "Drowning",
"Collisionh", "Splat", "Unknown"
};
new Text3D:playerLabels[MAX_PLAYERS][MAX_PLAYERS];
new LabelMode:playerLabelMode[MAX_PLAYERS];
new playerLabelTargetID[MAX_PLAYERS];
new playerData[MAX_PLAYERS][E_PLAYER_DATA];
GetLabelString(playerid, targetid, dest[], maxlength = sizeof(dest)) {
new Float:distance = GetPlayerDistanceFromPoint(playerid, playerData[targetid][PLAYER_POS][0], playerData[targetid][PLAYER_POS][1], playerData[targetid][PLAYER_POS][2]);
format(dest, maxlength,
"[id: %i, health: %0.2f, armour: %0.2f, ping: %i]\n\
skin: %i, money: $%i, score: %i\n\
distance: %0.2f\n\
weapon: %s, ammo: %i\n\
interior: %i, world: %i\n\
pos: %0.4f, %0.4f, %0.4f, %0.4f",
targetid, playerData[targetid][PLAYER_HEALTH], playerData[targetid][PLAYER_ARMOUR], playerData[targetid][PLAYER_PING],
playerData[targetid][PLAYER_SKIN], playerData[targetid][PLAYER_MONEY], playerData[targetid][PLAYER_SCORE],
distance,
WEAPON_NAMES[playerData[targetid][PLAYER_WEAPON]], playerData[targetid][PLAYER_AMMO],
playerData[targetid][PLAYER_INTERIOR], playerData[targetid][PLAYER_VIRTUAL_WORLD],
playerData[targetid][PLAYER_POS][0], playerData[targetid][PLAYER_POS][1], playerData[targetid][PLAYER_POS][2], playerData[targetid][PLAYER_ANGLE]
);
return 1;
}
CreatePlayerLabel(playerid, targetid) {
new string[MAX_LABEL_STRING];
GetLabelString(playerid, targetid, string);
playerLabels[playerid][targetid] = CreateDynamic3DTextLabel(string, LABEL_COLOR, 0.0, 0.0, 0.0, LABEL_DRAW_DISTANCE, targetid, _, _, _, _, playerid, LABEL_STREAM_DISTANCE);
return 1;
}
DestroyPlayerLabel(playerid) {
foreach (new i : Player) {
DestroyDynamic3DTextLabel(playerLabels[i][playerid]);
if (playerLabelMode[i] == MODE_PLAYER && playerLabelTargetID[i] == playerid) {
playerLabelMode[i] = MODE_DISABLED;
SendClientMessage(i, 0xFFFFFFFF, "SERVER: Player labels disabled");
}
}
return 1;
}
UpdatePlayerLabel(playerid, targetid) {
new string[MAX_LABEL_STRING];
if (playerLabelMode[playerid] == MODE_DISABLED)
return 0;
if (playerLabelMode[playerid] == MODE_PLAYER && playerLabelTargetID[playerid] != targetid)
return 0;
if (!IsPlayerInRangeOfPoint(playerid, LABEL_STREAM_DISTANCE, playerData[targetid][PLAYER_POS][0], playerData[targetid][PLAYER_POS][1], playerData[targetid][PLAYER_POS][2]))
return 0;
GetLabelString(playerid, targetid, string);
UpdateDynamic3DTextLabelText(playerLabels[playerid][targetid], LABEL_COLOR, string);
return 1;
}
public OnPlayerConnect(playerid) {
for (new i = 0; i < MAX_PLAYERS; i++) {
playerLabels[playerid][i] = Text3D:-1;
}
playerLabelMode[playerid] = MODE_DISABLED;
playerLabelTargetID[playerid] = INVALID_PLAYER_ID;
return 1;
}
public OnPlayerDisconnect(playerid, reason) {
foreach (new i : Player) {
DestroyDynamic3DTextLabel(playerLabels[i][playerid]);
if (playerLabelMode[i] == MODE_PLAYER && playerLabelTargetID[i] == playerid) {
playerLabelMode[i] = MODE_DISABLED;
SendClientMessage(i, 0xFFFFFFFF, "SERVER: Player labels disabled");
}
}
return 1;
}
public OnPlayerSpawn(playerid) {
foreach (new i : Player) {
if (i != playerid) {
CreatePlayerLabel(i, playerid);
}
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason) {
DestroyPlayerLabel(playerid);
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid) {
playerData[playerid][PLAYER_INTERIOR] = newinteriorid;
foreach (new i : Player) {
if (i != playerid) {
UpdatePlayerLabel(i, playerid);
}
}
return 1;
}
public OnPlayerUpdate(playerid) {
new worldid = GetPlayerVirtualWorld(playerid);
if (worldid != playerData[playerid][PLAYER_VIRTUAL_WORLD]) {
playerData[playerid][PLAYER_VIRTUAL_WORLD] = worldid;
goto Update;
}
new skinid = GetPlayerSkin(playerid);
if (skinid != playerData[playerid][PLAYER_SKIN]) {
playerData[playerid][PLAYER_SKIN] = skinid;
goto Update;
}
new score = GetPlayerScore(playerid);
if (score != playerData[playerid][PLAYER_SCORE]) {
playerData[playerid][PLAYER_SCORE] = score;
goto Update;
}
new money = GetPlayerMoney(playerid);
if (money != playerData[playerid][PLAYER_MONEY]) {
playerData[playerid][PLAYER_MONEY] = money;
goto Update;
}
new weapon = GetPlayerWeapon(playerid);
if (weapon != playerData[playerid][PLAYER_WEAPON]) {
playerData[playerid][PLAYER_WEAPON] = weapon;
playerData[playerid][PLAYER_AMMO] = GetPlayerAmmo(playerid);
goto Update;
}
new ammo = GetPlayerAmmo(playerid);
if (ammo != playerData[playerid][PLAYER_AMMO]) {
playerData[playerid][PLAYER_AMMO] = ammo;
goto Update;
}
new Float:health;
GetPlayerHealth(playerid, health);
if (health != playerData[playerid][PLAYER_HEALTH]) {
playerData[playerid][PLAYER_HEALTH] = health;
goto Update;
}
new Float:armour;
GetPlayerArmour(playerid, armour);
if (armour != playerData[playerid][PLAYER_ARMOUR]) {
playerData[playerid][PLAYER_ARMOUR] = armour;
goto Update;
}
new Float:angle;
GetPlayerFacingAngle(playerid, angle);
if (angle != playerData[playerid][PLAYER_ANGLE]) {
playerData[playerid][PLAYER_ANGLE] = angle;
goto Update;
}
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x != playerData[playerid][PLAYER_POS][0] || y != playerData[playerid][PLAYER_POS][1] || z != playerData[playerid][PLAYER_POS][2]) {
playerData[playerid][PLAYER_POS][0] = x;
playerData[playerid][PLAYER_POS][1] = y;
playerData[playerid][PLAYER_POS][2] = z;
goto Update;
}
new ping = GetPlayerPing(playerid);
if (ping != playerData[playerid][PLAYER_PING]) {
playerData[playerid][PLAYER_PING] = ping;
goto Update;
}
Update:
foreach (new i : Player) {
if (i != playerid) {
UpdatePlayerLabel(i, playerid);
}
}
return 1;
}
CMD:pl(playerid, params[]) {
if (playerLabelMode[playerid] != MODE_DISABLED) {
playerLabelMode[playerid] = MODE_DISABLED;
foreach (new i : Player) {
DestroyDynamic3DTextLabel(playerLabels[playerid][i]);
playerLabels[playerid][i] = Text3D:-1;
}
return SendClientMessage(playerid, 0xFFFFFFFF, "SERVER: Player labels disabled");
}
new targetid;
if (sscanf(params, "u", targetid)) {
targetid = INVALID_PLAYER_ID;
}
else {
if (!IsPlayerConnected(targetid))
return SendClientMessage(playerid, 0xAAAAAAFF, "SERVER: Player is not connected.");
if (targetid == playerid)
return SendClientMessage(playerid, 0xAAAAAAFF, "SERVER: The player entered is yourself!");
}
if (targetid == INVALID_PLAYER_ID) {
playerLabelMode[playerid] = MODE_GLOBAL;
playerLabelTargetID[playerid] = INVALID_PLAYER_ID;
foreach (new i : Player) {
if (i != playerid) {
CreatePlayerLabel(playerid, i);
}
}
}
else {
playerLabelMode[playerid] = MODE_PLAYER;
playerLabelTargetID[playerid] = targetid;
CreatePlayerLabel(playerid, targetid);
}
SendClientMessage(playerid, 0xFFFFFFFF, "SERVER: Player labels enabled");
return 1;
}