View difference between Paste ID: i7anjDbE and ZTNqy1Dq
SHOW: | | - or go back to the newest paste.
1-
//Per-player functions by Nexius v1.1
1+
//Per-player functions by Nexius v1.2
2
3
#if defined _perplayer_included
4
	#endinput
5
#endif
6
#define _perplayer_included
7
8
#include <a_samp>
9
#include <Pawn.Raknet>
10
11-
#define PERPLAYER_VERSION		"1.1"
11+
#define PERPLAYER_VERSION		"1.2"
12
13
native pp_IsValidVehicle(vehicleid) = IsValidVehicle;
14
15
stock SetPlayerGravity(playerid, Float:gravity)
16
{
17
	if(!IsPlayerConnected(playerid) || !(-50.0 <= gravity <= 50.0)) return 0;
18
	new BitStream:bs = BS_New();
19
	BS_WriteFloat(bs, gravity);
20-
	#if defined BS_SendRPC
20+
	#if defined PR_SendRPC
21-
		BS_SendRPC(bs, playerid, 146);
21+
		PR_SendRPC(bs, playerid, 146);
22
	#else
23
		BS_RPC(bs, playerid, 146);
24
	#endif
25
	BS_Delete(bs);
26
	return 1;
27
}
28
29
stock SetPlayerNameForPlayer(playerid, forplayerid, const name[])
30
{
31
	new namelen = strlen(name);
32
	if(!(1 <= namelen <= MAX_PLAYER_NAME) || ContainsInvalidNickChars(name)) return -1;
33
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid) || IsNicknameUsed(name)) return 0;
34
	new BitStream:bs = BS_New();
35
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT8, namelen, PR_STRING, name, PR_UINT8, 1);
36-
	#if defined BS_SendRPC
36+
	#if defined PR_SendRPC
37-
		BS_SendRPC(bs, forplayerid, 11);
37+
		PR_SendRPC(bs, forplayerid, 11);
38
	#else
39
		BS_RPC(bs, forplayerid, 11);
40
	#endif
41
	BS_Delete(bs);
42
	return 1;
43
}
44
45
stock SetPlayerSkillLevelForPlayer(playerid, forplayerid, skill, level)
46
{
47
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid) || !(WEAPONSKILL_PISTOL <= skill <= WEAPONSKILL_SNIPERRIFLE)) return 0;
48
	new BitStream:bs = BS_New();
49
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT32, skill, PR_UINT16, level);
50-
	#if defined BS_SendRPC
50+
	#if defined PR_SendRPC
51-
		BS_SendRPC(bs, forplayerid, 34);
51+
		PR_SendRPC(bs, forplayerid, 34);
52
	#else
53
		BS_RPC(bs, forplayerid, 34);
54
	#endif
55
	BS_Delete(bs);
56
	return 1;
57
}
58
59
stock SetPlayerFightingStyleForPlayer(playerid, forplayerid, style)
60
{
61
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid) || !(FIGHT_STYLE_NORMAL <= style <= FIGHT_STYLE_KNEEHEAD || FIGHT_STYLE_GRABKICK <= style <= FIGHT_STYLE_ELBOW)) return 0;
62
	new BitStream:bs = BS_New();
63
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT8, style);
64-
	#if defined BS_SendRPC
64+
	#if defined PR_SendRPC
65-
		BS_SendRPC(bs, forplayerid, 89);
65+
		PR_SendRPC(bs, forplayerid, 89);
66
	#else
67
		BS_RPC(bs, forplayerid, 89);
68
	#endif
69
	BS_Delete(bs);
70
	return 1;
71
}
72
73
stock SetPlayerTeamForPlayer(playerid, forplayerid, teamid)
74
{
75
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid)) return 0;
76
	new BitStream:bs = BS_New();
77
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT8, teamid);
78-
	#if defined BS_SendRPC
78+
	#if defined PR_SendRPC
79-
		BS_SendRPC(bs, forplayerid, 69);
79+
		PR_SendRPC(bs, forplayerid, 69);
80
	#else
81
		BS_RPC(bs, forplayerid, 69);
82
	#endif
83
	BS_Delete(bs);
84
	return 1;
85
}
86
87
stock SetPlayerSkinForPlayer(playerid, forplayerid, skinid)
88
{
89
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid)) return 0;
90
	new BitStream:bs = BS_New();
91
	BS_WriteValue(bs, PR_UINT32, playerid, PR_UINT32, skinid);
92-
	#if defined BS_SendRPC
92+
	#if defined PR_SendRPC
93-
		BS_SendRPC(bs, forplayerid, 153);
93+
		PR_SendRPC(bs, forplayerid, 153);
94
	#else
95
		BS_RPC(bs, forplayerid, 153);
96
	#endif
97
	BS_Delete(bs);
98
	return 1;
99
}
100
101
stock ApplyAnimationForPlayer(playerid, forplayerid, const animlib[], const animname[], Float:fDelta, loop, lockx, locky, freeze, time)
102
{
103
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid)) return 0;
104
	new BitStream:bs = BS_New(), animliblen = strlen(animlib), animnamelen = strlen(animname);
105
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT8, animliblen, PR_STRING, animlib, PR_UINT8, animnamelen, PR_STRING, animname, PR_FLOAT, fDelta, PR_BOOL, loop, PR_BOOL, lockx, PR_BOOL, locky, PR_BOOL, freeze, PR_UINT32, time);
106-
	#if defined BS_SendRPC
106+
	#if defined PR_SendRPC
107-
		BS_SendRPC(bs, forplayerid, 86);
107+
		PR_SendRPC(bs, forplayerid, 86);
108
	#else
109
		BS_RPC(bs, forplayerid, 86);
110
	#endif
111
	BS_Delete(bs);
112
	return 1;
113
}
114
115
stock ClearAnimationsForPlayer(playerid, forplayerid)
116
{
117
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid)) return 0;
118
	new BitStream:bs = BS_New();
119
	BS_WriteUint16(bs, playerid);
120-
	#if defined BS_SendRPC
120+
	#if defined PR_SendRPC
121-
		BS_SendRPC(bs, forplayerid, 87);
121+
		PR_SendRPC(bs, forplayerid, 87);
122
	#else
123
		BS_RPC(bs, forplayerid, 87);
124
	#endif
125
	BS_Delete(bs);
126
	return 1;
127
}
128
129
stock SetPlayerChatBubbleForPlayer(playerid, forplayerid, const text[], color, Float:drawdistance, expiretime)
130
{
131
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid)) return 0;
132
	new BitStream:bs = BS_New(), textlen = strlen(text);
133
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT32, color, PR_FLOAT, drawdistance, PR_UINT32, expiretime, PR_UINT8, textlen, PR_STRING, text);
134-
	#if defined BS_SendRPC
134+
	#if defined PR_SendRPC
135-
		BS_SendRPC(bs, forplayerid, 59);
135+
		PR_SendRPC(bs, forplayerid, 59);
136
	#else
137
		BS_RPC(bs, forplayerid, 59);
138
	#endif
139
	BS_Delete(bs);
140
	return 1;
141
}
142
143
stock SetAttachedObjectForPlayer(playerid, forplayerid, index, modelid, bone, Float:fOffsetX = 0.0, Float:fOffsetY = 0.0, Float:fOffsetZ = 0.0, Float:fRotX = 0.0, Float:fRotY = 0.0, Float:fRotZ = 0.0, Float:fScaleX = 1.0, Float:fScaleY = 1.0, Float:fScaleZ = 1.0, materialcolor1 = 0, materialcolor2 = 0)
144
{
145
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid) || !(0 <= index < MAX_PLAYER_ATTACHED_OBJECTS)) return 0;
146
	new BitStream:bs = BS_New();
147
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT32, index, PR_BOOL, true, PR_UINT32, modelid, PR_UINT32, bone, PR_FLOAT, fOffsetX, PR_FLOAT, fOffsetY, PR_FLOAT, fOffsetZ, PR_FLOAT, fRotX, PR_FLOAT, fRotY, PR_FLOAT, fRotZ, PR_FLOAT, fScaleX, PR_FLOAT, fScaleY, PR_FLOAT, fScaleZ, PR_INT32, materialcolor1, PR_INT32, materialcolor2);
148-
	#if defined BS_SendRPC
148+
	#if defined PR_SendRPC
149-
		BS_SendRPC(bs, forplayerid, 113);
149+
		PR_SendRPC(bs, forplayerid, 113);
150
	#else
151
		BS_RPC(bs, forplayerid, 113);
152
	#endif
153
	BS_Delete(bs);
154
	return 1;
155
}
156
157
stock RemoveAttachedObjectForPlayer(playerid, forplayerid, index)
158
{
159
	if(!IsPlayerConnected(playerid) || !IsPlayerConnected(forplayerid) || !(0 <= index < MAX_PLAYER_ATTACHED_OBJECTS)) return 0;
160
	new BitStream:bs = BS_New();
161
	BS_WriteValue(bs, PR_UINT16, playerid, PR_UINT32, index, PR_BOOL, false);
162-
	#if defined BS_SendRPC
162+
	#if defined PR_SendRPC
163-
		BS_SendRPC(bs, forplayerid, 113);
163+
		PR_SendRPC(bs, forplayerid, 113);
164
	#else
165
		BS_RPC(bs, forplayerid, 113);
166
	#endif
167
	BS_Delete(bs);
168
	return 1;
169
}
170
171
stock ChangeVehicleColorForPlayer(playerid, vehicleid, color1, color2)
172
{
173
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
174
	new BitStream:bs = BS_New();
175
	BS_WriteValue(bs, PR_UINT16, INVALID_PLAYER_ID, PR_UINT32, 3, PR_UINT32, vehicleid, PR_UINT32, color1, PR_UINT32, color2);
176-
	#if defined BS_SendRPC
176+
	#if defined PR_SendRPC
177-
		BS_SendRPC(bs, playerid, 96);
177+
		PR_SendRPC(bs, playerid, 96);
178
	#else
179
		BS_RPC(bs, playerid, 96);
180
	#endif
181
	BS_Delete(bs);
182
	return 1;
183
}
184
185
stock ChangeVehiclePaintjobForPlayer(playerid, vehicleid, paintjobid)
186
{
187
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
188
	new BitStream:bs = BS_New();
189
	BS_WriteValue(bs, PR_UINT16, INVALID_PLAYER_ID, PR_UINT32, 1, PR_UINT32, vehicleid, PR_UINT32, paintjobid, PR_UINT32, 0);
190-
	#if defined BS_SendRPC
190+
	#if defined PR_SendRPC
191-
		BS_SendRPC(bs, playerid, 96);
191+
		PR_SendRPC(bs, playerid, 96);
192
	#else
193
		BS_RPC(bs, playerid, 96);
194
	#endif
195
	BS_Delete(bs);
196
	return 1;
197
}
198
199
stock AddVehicleComponentForPlayer(playerid, vehicleid, componentid)
200
{
201
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
202
	new BitStream:bs = BS_New();
203
	BS_WriteValue(bs, PR_UINT16, INVALID_PLAYER_ID, PR_UINT32, 2, PR_UINT32, vehicleid, PR_UINT32, componentid, PR_UINT32, 0);
204-
	#if defined BS_SendRPC
204+
	#if defined PR_SendRPC
205-
		BS_SendRPC(bs, playerid, 96);
205+
		PR_SendRPC(bs, playerid, 96);
206
	#else
207
		BS_RPC(bs, playerid, 96);
208
	#endif
209
	BS_Delete(bs);
210
	return 1;
211
}
212
213
stock RemoveVehicleComponentForPlayer(playerid, vehicleid, componentid)
214
{
215
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
216
	new BitStream:bs = BS_New();
217
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_UINT16, componentid);
218-
	#if defined BS_SendRPC
218+
	#if defined PR_SendRPC
219-
		BS_SendRPC(bs, playerid, 57);
219+
		PR_SendRPC(bs, playerid, 57);
220
	#else
221
		BS_RPC(bs, playerid, 57);
222
	#endif
223
	BS_Delete(bs);
224
	return 1;
225
}
226
227
stock LinkVehicleToInteriorForPlayer(playerid, vehicleid, interiorid)
228
{
229
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
230
	new BitStream:bs = BS_New();
231
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_UINT8, interiorid);
232-
	#if defined BS_SendRPC
232+
	#if defined PR_SendRPC
233-
		BS_SendRPC(bs, playerid, 65);
233+
		PR_SendRPC(bs, playerid, 65);
234
	#else
235
		BS_RPC(bs, playerid, 65);
236
	#endif
237
	BS_Delete(bs);
238
	return 1;
239
}
240
241
stock SetVehicleNumberPlateForPlayer(playerid, vehicleid, const numberplate[])
242
{
243
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
244
	new BitStream:bs = BS_New(), numberplatelen = strlen(numberplate);
245
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_UINT8, numberplatelen, PR_STRING, numberplate);
246-
	#if defined BS_SendRPC
246+
	#if defined PR_SendRPC
247-
		BS_SendRPC(bs, playerid, 123);
247+
		PR_SendRPC(bs, playerid, 123);
248
	#else
249
		BS_RPC(bs, playerid, 123);
250
	#endif
251
	BS_Delete(bs);
252
	return 1;
253
}
254
255
stock SetVehicleHealthForPlayer(playerid, vehicleid, Float:health)
256
{
257
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
258
	new BitStream:bs = BS_New();
259
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_FLOAT, health);
260-
	#if defined BS_SendRPC
260+
	#if defined PR_SendRPC
261-
		BS_SendRPC(bs, playerid, 147);
261+
		PR_SendRPC(bs, playerid, 147);
262
	#else
263
		BS_RPC(bs, playerid, 147);
264
	#endif
265
	BS_Delete(bs);
266
	return 1;
267
}
268
269
stock UpdateVehDamageStatusForPlayer(playerid, vehicleid, panels, doors, lights, tires)
270
{
271
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
272
	new BitStream:bs = BS_New();
273
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_UINT32, panels, PR_UINT32, doors, PR_UINT8, lights, PR_UINT8, tires);
274-
	#if defined BS_SendRPC
274+
	#if defined PR_SendRPC
275-
		BS_SendRPC(bs, playerid, 106);
275+
		PR_SendRPC(bs, playerid, 106);
276
	#else
277
		BS_RPC(bs, playerid, 106);
278
	#endif
279
	BS_Delete(bs);
280
	return 1;
281
}
282
283
stock RepairVehicleForPlayer(playerid, vehicleid)
284
{
285
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
286
	new BitStream:bs = BS_New();
287
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_FLOAT, 1000.0);
288-
	#if defined BS_SendRPC
288+
	#if defined PR_SendRPC
289-
		BS_SendRPC(bs, playerid, 147);
289+
		PR_SendRPC(bs, playerid, 147);
290
	#else
291
		BS_RPC(bs, playerid, 147);
292
	#endif
293
	BS_Delete(bs);
294
295
	bs = BS_New();
296
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_UINT32, 0, PR_UINT32, 0, PR_UINT8, 0, PR_UINT8, 0);
297-
	#if defined BS_SendRPC
297+
	#if defined PR_SendRPC
298-
		BS_SendRPC(bs, playerid, 106);
298+
		PR_SendRPC(bs, playerid, 106);
299
	#else
300
		BS_RPC(bs, playerid, 106);
301
	#endif
302
	BS_Delete(bs);
303
	return 1;
304
}
305
306
stock SetVehiclePosForPlayer(playerid, vehicleid, Float:x, Float:y, Float:z)
307
{
308
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
309
	new BitStream:bs = BS_New();
310
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_FLOAT, x, PR_FLOAT, y, PR_FLOAT, z);
311-
	#if defined BS_SendRPC
311+
	#if defined PR_SendRPC
312-
		BS_SendRPC(bs, playerid, 159);
312+
		PR_SendRPC(bs, playerid, 159);
313
	#else
314
		BS_RPC(bs, playerid, 159);
315
	#endif
316
	BS_Delete(bs);
317
	return 1;
318
}
319
320
stock SetVehicleZAngleForPlayer(playerid, vehicleid, Float:z_angle)
321
{
322
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
323
	new BitStream:bs = BS_New();
324
	BS_WriteValue(bs, PR_UINT16, vehicleid, PR_FLOAT, z_angle);
325-
	#if defined BS_SendRPC
325+
	#if defined PR_SendRPC
326-
		BS_SendRPC(bs, playerid, 160);
326+
		PR_SendRPC(bs, playerid, 160);
327
	#else
328
		BS_RPC(bs, playerid, 160);
329
	#endif
330
	BS_Delete(bs);
331
	return 1;
332
}
333
334
stock SetVehicleVelocityForPlayer(playerid, vehicleid, Float:X, Float:Y, Float:Z)
335
{
336
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
337
	if(IsPlayerInVehicle(playerid, vehicleid))
338
	{
339
		new BitStream:bs = BS_New();
340
		BS_WriteValue(bs, PR_UINT8, 0, PR_FLOAT, X, PR_FLOAT, Y, PR_FLOAT, Z);
341-
		#if defined BS_SendRPC
341+
		#if defined PR_SendRPC
342-
			BS_SendRPC(bs, playerid, 91);
342+
			PR_SendRPC(bs, playerid, 91);
343
		#else
344
			BS_RPC(bs, playerid, 91);
345
		#endif
346
		BS_Delete(bs);
347
	}
348
	return 1;
349
}
350
351
stock SetVehicleAngVelocityForPlayer(playerid, vehicleid, Float:X, Float:Y, Float:Z)
352
{
353
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
354
	if(IsPlayerInVehicle(playerid, vehicleid))
355
	{
356
		new BitStream:bs = BS_New();
357
		BS_WriteValue(bs, PR_UINT8, 1, PR_FLOAT, X, PR_FLOAT, Y, PR_FLOAT, Z);
358-
		#if defined BS_SendRPC
358+
		#if defined PR_SendRPC
359-
			BS_SendRPC(bs, playerid, 91);
359+
			PR_SendRPC(bs, playerid, 91);
360
		#else
361
			BS_RPC(bs, playerid, 91);
362
		#endif
363
		BS_Delete(bs);
364
	}
365
	return 1;
366
}
367
368
stock AttachTrailerToVehicleForPlayer(playerid, trailerid, vehicleid)
369
{
370
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(trailerid) || !pp_IsValidVehicle(vehicleid)) return 0;
371
	new BitStream:bs = BS_New();
372
	BS_WriteValue(bs, PR_UINT16, trailerid, PR_UINT16, vehicleid);
373-
	#if defined BS_SendRPC
373+
	#if defined PR_SendRPC
374-
		BS_SendRPC(bs, playerid, 148);
374+
		PR_SendRPC(bs, playerid, 148);
375
	#else
376
		BS_RPC(bs, playerid, 148);
377
	#endif
378
	BS_Delete(bs);
379
	return 1;
380
}
381
382
stock DetachTrailerFromVehForPlayer(playerid, vehicleid)
383
{
384
	if(!IsPlayerConnected(playerid) || !pp_IsValidVehicle(vehicleid)) return 0;
385
	new BitStream:bs = BS_New();
386
	BS_WriteUint16(bs, vehicleid);
387-
	#if defined BS_SendRPC
387+
	#if defined PR_SendRPC
388-
		BS_SendRPC(bs, playerid, 149);
388+
		PR_SendRPC(bs, playerid, 149);
389
	#else
390
		BS_RPC(bs, playerid, 149);
391
	#endif
392
	BS_Delete(bs);
393
	return 1;
394
}
395
396
static stock IsNicknameUsed(const nick[])
397
{
398
	for(new i = GetPlayerPoolSize(), tmpname[MAX_PLAYER_NAME + 1]; i >= 0; --i)
399
	{
400
		if(GetPlayerName(i, tmpname, sizeof tmpname))
401
		{
402
			if(strcmp(nick, tmpname) == 0) return 1;
403
		}
404
	}
405
	return 0;
406
}
407
408
static stock ContainsInvalidNickChars(const string[])
409
{
410
	new i;
411
	while(string[i])
412
	{
413
		if('0' <= string[i] <= '9' ||
414
		'A' <= string[i] <= 'Z' || 'a' <= string[i] <= 'z' ||
415
		string[i] == ']' || string[i] == '[' ||
416
		string[i] == '_' || string[i] == '$' ||
417
		string[i] == '=' || string[i] == '(' ||
418
		string[i] == ')' || string[i] == '@' ||
419
		string[i] == '.') i++;
420
		else return 1;
421
422
	}
423
	return 0;
424
}