forked from PatrickGTR/actor_robbery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactor_robbery.inc
More file actions
328 lines (266 loc) · 8.73 KB
/
actor_robbery.inc
File metadata and controls
328 lines (266 loc) · 8.73 KB
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
/*
[DECLARATIONS]
*/
#if !defined _samp_included
#error Please include a_samp before actor_robbery.
#endif
#if !defined KEY_AIM
#define KEY_AIM 128
#endif
#if !defined PreloadAnimLib
#define PreloadAnimLib(%1,%2) ApplyAnimation(%1,%2,"null",0.0,0,0,0,0,0)
#endif
#define MAX_ROBBERY_ACTORS (50)
#define TYPE_SUCCESS (0)
#define TYPE_FAILED (1)
#define TYPE_UNFINISHED (2)
#define MIN_MONEY_ROB 500
#define MAX_MONEY_ROB 10000
#define ROBBERY_WAIT_TIME (5)
enum E_ACTOR_ROBBERY_DATA
{
actor_skin,
Float:actor_x,
Float:actor_y,
Float:actor_z,
Float:actor_ang,
actor_vw,
money_min,
money_max,
bool:actor_created,
actor_robbedRecently
}
static
robbery_data[MAX_ROBBERY_ACTORS][E_ACTOR_ROBBERY_DATA],
i_actor = 0;
forward RunActorAnimationSequence(playerid, actorid, animation_pattern);
forward OnPlayerStartRobbery(playerid, actorid, bool:robbed_recently);
forward OnPlayerFinishRobbery(playerid, actorid, robbedmoney, type);
forward OnPlayerRequestRobbery(playerid, actorid);
/*
Function:
CreateActorRobbery
Info:
Creates the robbery actor according to the position set.
Param:
* skinid -> Skin ID of the robbery actor
* Float:x -> Coordinate X of the robbery actor
* Float:y -> Coordinate X of the robbery actor
* Float:z -> Coordinate X of the robbery actor
* Float:ang -> Facing angle of the robbery actor
* actor_vwid -> virtualid of the robbery actor
* r_moneymin -> Minimum money to be robbed from the robbery actor
* r_moneymax -> Maximum money to be robbed from the robbery actor
*/
#pragma deprecated GetActorRobberyData
stock GetActorRobberyData(actorid, &skinid, &Float:x, &Float:y, &Float:z, &Float:ang, &actor_vwid, &r_moneymin, &r_moneymax) {
#pragma unused actorid, skinid, x, y, z, ang, actor_vwid, r_moneymin, r_moneymax
}
#pragma deprecated Please use new function name Robbery_CreateActor.
stock CreateActorRobbery(skinid, Float:x, Float:y, Float:z, Float:ang, actor_vwid = 0, r_moneymin = MIN_MONEY_ROB, r_moneymax = MAX_MONEY_ROB) {
#pragma unused skinid, x, y, z, ang, actor_vwid, r_moneymin, r_moneymax
return -1;
}
stock Robbery_CreateActor(skinid, Float:x, Float:y, Float:z, Float:ang, actor_vwid = 0, r_moneymin = MIN_MONEY_ROB, r_moneymax = MAX_MONEY_ROB) {
new actorid = GetActorFreeID();
if(actorid == -1) {
print("ERROR: Robbery_CreateActor - MAX_ROBBERY_ACTOR reached, increase the limit size.");
return -1;
}
CreateActor(skinid, x, y, z, ang);
SetActorVirtualWorld(actorid, actor_vwid);
robbery_data[actorid][actor_created] = true;
robbery_data[actorid][actor_skin] = skinid;
robbery_data[actorid][actor_x] = x;
robbery_data[actorid][actor_y] = y;
robbery_data[actorid][actor_z] = z;
robbery_data[actorid][actor_ang] = ang;
robbery_data[actorid][actor_vw] = actor_vwid;
robbery_data[actorid][money_min] = r_moneymin;
robbery_data[actorid][money_max] = r_moneymax;
return (i_actor ++);
}
/*
Function:
Robbery_GetActorData
Info:
Retrieves the actor data
Param:
* actorid -> ID of robbery actor you want to retrieve data from.
* &skinid -> Skin ID of the robbery actor
* &Float:x -> Coordinate X of the robbery actor
* &Float:y -> Coordinate X of the robbery actor
* &Float:z -> Coordinate X of the robbery actor
* &Float:ang -> Facing angle of the robbery actor
* &actor_vwid -> virtualid of the robbery actor
* &r_moneymin -> Minimum money to be robbed from the robbery actor
* &r_moneymax -> Maximum money to be robbed from the robbery actor
*/
stock Robbery_GetActorData(actorid, &skinid, &Float:x, &Float:y, &Float:z, &Float:ang, &actor_vwid, &r_moneymin, &r_moneymax) {
if(actorid == INVALID_ACTOR_ID) {
print("ERROR: GetActorRobberyData - Invalid actorid input.");
return 1;
}
skinid = robbery_data[actorid][actor_skin];
x = robbery_data[actorid][actor_x];
y = robbery_data[actorid][actor_y];
z = robbery_data[actorid][actor_z] ;
ang = robbery_data[actorid][actor_ang] ;
actor_vwid = robbery_data[actorid][actor_vw];
r_moneymin = robbery_data[actorid][money_min];
r_moneymax = robbery_data[actorid][money_max];
return 1;
}
/*
Function:
GetActorFreeID
Info:
Retrieves the unused ID of an actor.
Param:
None
*/
static stock GetActorFreeID()
{
for(new i = 0; i < MAX_ROBBERY_ACTORS; i++) {
if(!robbery_data[i][actor_created]) {
return i;
}
}
return -1;
}
/*
Robbery IMPL
*/
public RunActorAnimationSequence(playerid, actorid, animation_pattern) {
switch(animation_pattern) {
case 0: {
ClearActorAnimations(actorid);
ApplyActorAnimation(actorid, "SHOP", "SHP_Rob_HandsUp", 4.1, 0, 1, 1, 1, 0);
SetTimerEx("RunActorAnimationSequence", 1000 * ROBBERY_WAIT_TIME, false, "iii", playerid, actorid, 1);
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
if(!IsPlayerConnected(i)) {
continue;
}
PlayerPlaySound(i, 3401, x, y, z);
}
}
case 1: {
if(!IsPlayerInRangeOfPoint(playerid, 10.0, robbery_data[actorid][actor_x], robbery_data[actorid][actor_y], robbery_data[actorid][actor_z])) {
CallLocalFunction("OnPlayerFinishRobbery", "iiii", playerid, actorid, 0, TYPE_UNFINISHED);
}
else {
ClearActorAnimations(actorid);
ApplyActorAnimation(actorid, "SHOP", "SHP_Rob_GiveCash", 4.1, 0, 1, 1, 1, 0);
SetTimerEx("RunActorAnimationSequence", 1000 * ROBBERY_WAIT_TIME, false, "iii", playerid, actorid, 2);
}
}
case 2: {
ClearActorAnimations(actorid);
ApplyActorAnimation(actorid, "PED", "DUCK_cower", 4.1, 1, 1, 1, 1, 1);
SetTimerEx("RunActorAnimationSequence", 1000 * 60 * ROBBERY_WAIT_TIME, false, "iii", playerid, actorid, 3);
new robberyChance = random(100);
if(robberyChance > 40) {
CallLocalFunction("OnPlayerFinishRobbery", "iiii", playerid, actorid, (random(robbery_data[actorid][money_max] - robbery_data[actorid][money_min]) + robbery_data[actorid][money_min]), TYPE_SUCCESS);
}
else {
CallLocalFunction("OnPlayerFinishRobbery", "iiii", playerid, actorid, 0, TYPE_FAILED);
}
}
case 3: {
ClearActorAnimations(actorid);
PlayerPlaySound(playerid, 0, 0.0, 0.0, 0.0);
}
}
return 1;
}
public OnPlayerConnect(playerid)
{
EnablePlayerCameraTarget(playerid, 1);
PreloadAnimLib(playerid, "PED");
PreloadAnimLib(playerid, "SHOP");
#if defined actorrob_OnPlayerConnect
return actorrob_OnPlayerConnect(playerid);
#else
return 1;
#endif
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if((newkeys & KEY_AIM) == KEY_AIM && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
switch(GetPlayerWeapon(playerid))
{
case 22 .. 33:
{
new actorid = GetPlayerCameraTargetActor(playerid);
if(actorid == INVALID_ACTOR_ID) {
return 1;
}
if(!robbery_data[actorid][actor_created]) {
// this fixes the issue with normal create actors.
// there was a bug that you aim at an actor and rob it even though it wasn't created by actor_robbery.
return 1;
}
if(!OnPlayerRequestRobbery(playerid, actorid))
{
return 1;
}
if(gettime() - robbery_data[actorid][actor_robbedRecently] < 60 * ROBBERY_WAIT_TIME) {
return CallLocalFunction("OnPlayerStartRobbery", "iii", playerid, actorid, true);
}
robbery_data[actorid][actor_robbedRecently] = gettime();
RunActorAnimationSequence(playerid, actorid, 0);
CallLocalFunction("OnPlayerStartRobbery", "iii", playerid, actorid, false);
}
}
}
#if defined actorrob_OnPlayerKeyStateChange
return actorrob_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
#else
return 1;
#endif
}
/* OnPlayerRequestRobbery
Usage: return 0 to disallow the robbery.
See test.pwn for example.
*/
public OnPlayerRequestRobbery(playerid, actorid)
{
#if defined actorrob_OnPlayerRequestRobbery
return actorrob_OnPlayerRequestRobbery(playerid, actorid);
#else
return 1; // Default version always wants to returns >1 to allow robbery
#endif
}
//OnPlayerKeyStateChange hook directives
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange actorrob_OnPlayerKeyStateChange
#if defined actorrob_OnPlayerKeyStateChange
forward actorrob_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
#endif
//OnPlayerConnect directives
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect actorrob_OnPlayerConnect
#if defined actorrob_OnPlayerConnect
forward actorrob_OnPlayerConnect(playerid);
#endif
//OnPlayerRequestRobbery directives
#if defined _ALS_OnPlayerRequestRobbery
#undef OnPlayerRequestRobbery
#else
#define _ALS_OnPlayerRequestRobbery
#endif
#define OnPlayerRequestRobbery actorrob_OnPlayerRequestRobbery
#if defined actorrob_OnPlayerRequestRobbery
forward actorrob_OnPlayerRequestRobbery(playerid);
#endif