-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathitem.inc
2389 lines (1841 loc) · 61.1 KB
/
item.inc
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// built-in include guard removal
// just in case the user has a local dependency with the same file name
#if defined _inc_item
#undef _inc_item
#endif
// custom include-guard to ensure we don't duplicate
#if defined _item_included
#endinput
#endif
#define _item_included
#tryinclude <open.mp>
#if !defined _INC_open_mp
#include <a_samp>
#endif
#include <logger>
#include <errors>
#include <YSI_Data\y_iterate>
#include <YSI_Coding\y_inline>
#include <YSI_Coding\y_timers>
#include <YSI_Visual\y_dialog>
#include <streamer>
#include <uuid>
#include <button>
#include <mathutil>
#include <tick-difference>
#include <action-text>
#include <personal-space>
#include <YSI_Coding\y_hooks>
/*==============================================================================
Constant Definitions, Function Declarations and Documentation
==============================================================================*/
// Maximum amount of items that can be created.
#if !defined MAX_ITEM
#define MAX_ITEM (Item:8192)
#endif
// Maximum amount of item types that can be defined.
#if !defined MAX_ITEM_TYPE
#define MAX_ITEM_TYPE (ItemType:256)
#endif
// Maximum string length for item type names.
#if !defined MAX_ITEM_NAME
#define MAX_ITEM_NAME (32)
#endif
// Maximum string length for item specific extra text.
#if !defined MAX_ITEM_TEXT
#define MAX_ITEM_TEXT (32)
#endif
// Item attachment index for SetPlayerAttachedObject native.
#if !defined ITEM_ATTACH_INDEX
#define ITEM_ATTACH_INDEX (0)
#endif
// Key code for interact key
#if !defined ITEM_KEY_INTERACT
#define ITEM_KEY_INTERACT (KEY_SECONDARY_ATTACK)
#endif
// Key code for dropping items
#if !defined ITEM_KEY_DROP_ITEM
#define ITEM_KEY_DROP_ITEM (KEY_NO)
#endif
// Colour for item text labels if the "label" parameter is set.
#if !defined ITEM_LABEL_COLOUR
#define ITEM_LABEL_COLOUR (0xFFFF00FF)
#endif
// Game text symbol for interact key
#if !defined ITEM_GAMETEXT_INTERACT
#define ITEM_GAMETEXT_INTERACT "~k~~VEHICLE_ENTER_EXIT~"
#endif
// Area size of the button to pick up an item
#if !defined ITEM_BUTTON_AREASIZE
#define ITEM_BUTTON_AREASIZE (1.0)
#endif
#if !defined ITEM_GAMETEXT_PICKUP
#define ITEM_GAMETEXT_PICKUP "Press "ITEM_GAMETEXT_INTERACT" to pick up"
#endif
// Game text symbol for dropping items
#if !defined ITEM_GAMETEXT_DROP_ITEM
#define ITEM_GAMETEXT_DROP_ITEM "~k~~CONVERSATION_NO~"
#endif
// Text symbol for the dialog title when there are multiple items to pick up
#if !defined ITEM_DIALOGTEXT_TITLE
#define ITEM_DIALOGTEXT_TITLE "Multiple items nearby"
#endif
// Text symbol for the dialog button 1 when there are multiple items to pick up
#if !defined ITEM_DIALOGTEXT_PICKUP_ITEM
#define ITEM_DIALOGTEXT_PICKUP_ITEM "Pick up"
#endif
// Text symbol for the dialog button 2 when there are multiple items to pick up
#if !defined ITEM_DIALOGTEXT_CANCEL
#define ITEM_DIALOGTEXT_CANCEL "Close"
#endif
// Offset from player Z coordinate to floor Z coordinate
#define ITEM_FLOOR_OFFSET (0.96)
// Item validity check constant
#define INVALID_ITEM_ID (Item:-1)
// Item type validity check constant
#define INVALID_ITEM_TYPE (ItemType:-1)
#if !defined STREAMER_TAG_OBJECT
#define STREAMER_TAG_OBJECT _
#endif
// Functions
forward ItemType:DefineItemType(const name[], const uname[], model, size, Float:rotx = 0.0, Float:roty = 0.0, Float:rotz = 0.0, Float:modelz = 0.0, Float:attx = 0.0, Float:atty = 0.0, Float:attz = 0.0, Float:attrx = 0.0, Float:attry = 0.0, Float:attrz = 0.0, bool:usecarryanim = false, colour = -1, boneid = 6, bool:longpickup = false, Float:buttonz = ITEM_FLOOR_OFFSET, maxhitpoints = 5, price = 1);
/*
# Description
Defines a new item type with the specified name and model. Item types are the
fundamental pieces of data that give items specific characteristics. At least
one item definition must exist or CreateItem will have no data to use.
# Parameters
- name: The name of the item, that will be displayed on item labels.
- uname: The unique name of the item to identify the item type via string.
- model: The GTA:SA model id to use when the item is visible in the game world.
- size: An arbitrary size value (has no effect in this module).
- rotx, roty, rotz: The default rotation the item object will have when dropped.
- modelz: Z offset from the item world position to create item model.
- attx, atty, attz, attrx, attry, attrz: Player holding attachment coordinates.
- usecarryanim: When true, player will use a two-handed carry animation.
- colour: Item model texture colour.
- boneid: The attachment bone to use, by default this is the right hand (6).
- longpickup: When true, requires long press to pick up, tap results in using.
- buttonz: Z offset from the item world position to create item button.
- maxhitpoints: maximum and default hitpoints for items of this type.
- price: The price of the item, can be used for shop systems.
# Returns
Item Type ID handle of the newly defined item type. INVALID_ITEM_TYPE If the
item type definition index is full and no more item types can be defined.
*/
forward Item:CreateItem(ItemType:type, Float:x = 0.0, Float:y = 0.0, Float:z = 0.0, Float:rx = 0.0, Float:ry = 0.0, Float:rz = 0.0, world = 0, interior = 0, bool:label = true, bool:applyrotoffsets = true, bool:virtual = false, const uuid[] = "", hitpoints = -1, price = -1);
/*
# Description
Creates an item in the game world at the specified coordinates with the
specified rotation with options for world, interior and whether or not to
display a 3D text label above the item.
# Parameters
- type: An item type defined with DefineItemType.
- x, y, z: The position to create the object and button of the item.
- rx, ry, rz: The rotation value of the object, overrides item type data.
- world: The virtual world in which the object, button and label will appear.
- interior: Interior world, same as above but for interior worlds.
- label: True to show a label with the item name at the item.
- applyrotoffsets: False to make rx, ry, rz rotation values absolute.
- virtual: When true, the item doesn't have an in-world existence.
- uuid: Allows specific UUID to be set instead of generating one.
- hitpoints: -1 by default, if -1 then item type maxhitpoints value is used.
- price: -1 by default, if -1 then item type price value is used.
# Returns
Item ID handle of the newly created item or INVALID_ITEM_ID If the item index is
full and no more items can be created.
*/
forward DestroyItem(Item:id);
/*
# Description
Destroys an item.
# Returns
Boolean to indicate success or failure.
*/
forward CreateItemInWorld(Item:id, Float:x = 0.0, Float:y = 0.0, Float:z = 0.0, Float:rx = 0.0, Float:ry = 0.0, Float:rz = 0.0, world = 0, interior = 0, bool:label = true, bool:applyrotoffsets = true, hitpoints = -1, price = -1);
/*
# Description
Adds an existing item to the game world if it was previously removed either by
a player picking it up or via RemoveItemFromWorld.
# Returns
1 If the item doesn't exist, 2 if the item is already in the world, 3 if the
item type is invalid, 4 if the button ID was invalid and 0 on success.
*/
forward RemoveItemFromWorld(Item:id);
/*
# Description
Removes an item from the world. Deletes all physical elements but keeps the item
in memory with a valid ID and removes the ID from the world index. Effectively
makes the item a "virtual" item, as in it still exists in the server memory but
it doesn't exist physically in the game world.
# Returns
Boolean to indicate success or failure.
*/
forward PlayerPickUpItem(playerid, Item:id);
/*
# Description
A function to directly make a player pick up an item, regardless of whether he
is within the button range.
*/
forward PlayerDropItem(playerid);
/*
# Description
Force a player to drop their currently held item.
# Returns
1 If the function was called successfully 0 If the player isn't holding an item
or if the function was stopped by a return of 1 in OnPlayerDropItem.
*/
forward PlayerGiveItem(playerid, targetid, call = true);
/*
# Description
# Returns
1 If the give was successful. 0 If the player isn't holding an item, of the
function was stopped by a return of 1 in OnPlayerGiveItem. -1 If the target
player was already holding an item.
*/
forward PlayerUseItem(playerid);
/*
# Description
Forces a player to use their current item, resulting in a call to OnPlayerUseItem.
*/
forward GiveWorldItemToPlayer(playerid, Item:id, call = 1);
/*
# Description
Give a world item to a player.
# Parameters
- playerid: The player to give the item to.
- id: The ID of the item to give to the player.
- call: Determines whether OnPLayerPickUpItem is called.
# Returns
Boolean to indicate success or failure.
*/
forward Item:RemoveCurrentItem(playerid);
/*
# Description
Removes the player's currently held item and places it in the world.
# Returns
INVALID_ITEM_ID If the player ID is invalid or the player isn't holding an item.
*/
forward Item:AllocNextItemID(ItemType:type, const uuid[] = "");
/*
# Description
Preallocates an item ID for a specific item type. This doesn't actually create
an item but it makes the ID valid so item related functions can be called on it
to set various pieces of data before the item is created. Useful for setting
data that needs to be valid for when OnItemCreate(InWorld) is called.
# Returns
The allocated ID of the item or INVALID_ITEM_ID If there are no more free item
slots or -2 If the specified type is invalid.
*/
forward CreateItem_ExplicitID(Item:id, Float:x = 0.0, Float:y = 0.0, Float:z = 0.0, Float:rx = 0.0, Float:ry = 0.0, Float:rz = 0.0, world = 0, interior = 0, bool:label = true, bool:applyrotoffsets = true, bool:virtual = false, hitpoints = -1, price = -1);
/*
# Description
Creates an item using an ID allocated from AllocNextItemID. This is the only
function that can create items that were preallocated.
# Parameters:
Apart from the explicit item ID, parameters are the same as CreateItem.
# Returns
1 On success or 0 if the ID is invalid or is destroyed in OnItemCreate.
*/
forward bool:IsValidItem(Item:id);
/*
# Description
Returns whether the entered value is a valid item ID handle.
*/
forward GetItemObjectID(Item:id, &objectid);
/*
# Description
Returns the streamed object ID for a world item. Cannot be a virtual item.
*/
forward GetItemButtonID(Item:id, &Button:buttonid);
/*
# Description
Returns the button ID of a world item. Cannot be a virtual item.
*/
forward SetItemLabel(Item:id, const text[], colour = ITEM_LABEL_COLOUR, Float:range = 10.0);
/*
# Description
Creates or updates a 3D text label above the item. This is actually the label
which is associated with the button for the item, so you could just call
GetItemButtonID then use SetButtonLabel but this is just here for convenience.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemTypeCount(ItemType:itemtype);
/*
# Description
Returns the amount of created items of the given type.
*/
forward ItemType:GetItemType(Item:id);
/*
# Description
Returns the item type of an item.
*/
forward GetItemPos(Item:id, &Float:x, &Float:y, &Float:z);
/*
# Description
Returns the position of a world item. If used on a non-world item such as an
item being held by a player, it will return the last position of the item.
# Returns
Boolean to indicate success or failure.
*/
forward SetItemPos(Item:id, Float:x, Float:y, Float:z);
/*
# Description
Changes the position of an item. This includes the associated object and button.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemRot(Item:id, &Float:rx, &Float:ry, &Float:rz);
/*
# Description
Returns the rotation of a world item.
# Returns
Boolean to indicate success or failure.
*/
forward SetItemRot(Item:id, Float:rx, Float:ry, Float:rz, bool:offsetfromdefaults = false);
/*
# Description
Sets the rotation of a world item object.
# Parameters
- offsetfromdefaults: If true, parameters are offsets from item type defaults.
# Returns
Boolean to indicate success or failure.
*/
forward SetItemWorld(Item:id, world);
/*
# Description
Sets an item's virtual world.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemWorld(Item:id, &world);
/*
# Description
Returns an item's virtual world.
*/
forward SetItemInterior(Item:id, interior);
/*
# Description
Sets an item's interior ID.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemInterior(Item:id, &interior);
/*
# Description
Returns an item's interior ID.
*/
forward SetItemHitPoints(Item:id, hitpoints);
/*
# Description
Sets an item's hitpoint value, destroys the item if 0.
*/
forward GetItemHitPoints(Item:id);
/*
# Description
Returns an item's hitpoint value.
*/
forward SetItemPrice(Item:id, price);
/*
# Description
Sets an item's price value.
*/
forward GetItemPrice(Item:id);
/*
# Description
Returns an item's price value.
*/
forward SetItemExtraData(Item:id, data);
/*
# Description
Sets the item's extra data field, this is one cell of data space allocated for
each item, this value can be a simple value or point to a cell in a more complex
set of data to act as extra characteristics for items.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemExtraData(Item:id, &data);
/*
# Description
Retrieves the integer assigned to the item set with SetItemExtraData.
*/
forward SetItemNameExtra(Item:id, const string[]);
/*
# Description
Gives the item a unique string of text to be appended to the name in brackets.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemNameExtra(Item:id, string[]);
/*
# Description
Retrieves the unique string of text assigned to an item.
# Returns
Boolean to indicate success or failure.
*/
forward bool:IsValidItemType(ItemType:itemtype);
/*
# Description
Checks whether a value is a valid item type.
*/
forward GetItemTypeName(ItemType:itemtype, string[]);
/*
# Description
Retrieves the name of an item type.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemTypeUniqueName(ItemType:itemtype, string[]);
/*
# Description
Gets the unique name for an item type.
# Returns
Boolean to indicate success or failure.
*/
forward ItemType:GetItemTypeFromUniqueName(const string[], bool:ignorecase = false);
/*
# Description
Returns an item type for the specified unique item type name via lookup.
# Returns
Boolean to indicate success or failure.
*/
forward GetItemTypeModel(ItemType:itemtype, &model);
/*
# Description
Returns the model assigned to an item type.
*/
forward GetItemTypeSize(ItemType:itemtype, &size);
/*
# Description
Returns the defined size of an item type.
# Returns
0 if itemtype is invalid.
*/
forward GetItemTypeRotation(ItemType:itemtype, &Float:rx, &Float:ry, &Float:rz);
/*
# Description
Returns the rotation offsets defined in DefineItemType for an item type.
# Returns
0 if itemtype is invalid.
*/
forward bool:IsItemTypeCarry(ItemType:itemtype);
/*
# Description
Returns true if the itemtype uses two-handed carry animations set via the
usecarryanim parameter of DefineItemType.
*/
forward GetItemTypeColour(ItemType:itemtype, &colour);
/*
# Description
Returns the default colour of an item type.
*/
forward GetItemTypeBone(ItemType:itemtype);
/*
# Description
Returns the bone that an item type will attach the mesh to.
*/
forward bool:IsItemTypeLongPickup(ItemType:itemtype);
/*
# Description
Returns true if the item requires holding the pick-up key in order to pick up.
*/
forward GetItemTypeMaxHitPoints(ItemType:itemtype);
/*
# Description
Returns the max hit points of an item type.
*/
forward GetItemTypePrice(ItemType:itemtype);
/*
# Description
Returns the price of an item type.
*/
forward bool:IsItemDestroying(Item:id);
/*
# Description
Returns true in OnItemDestroy calls, use to prevent unwanted recursion.
*/
forward GetItemHolder(Item:id);
/*
# Description
Returns the ID of the player who is holding an item.
# Returns
INVALID_PLAYER_ID if the item isn't being held by anyone.
*/
forward Item:GetPlayerItem(playerid);
/*
# Description
Returns the item ID handle of the item a player is holding.
# Returns
INVALID_ITEM_ID if the player isn't holding an item.
*/
forward bool:IsItemInWorld(Item:id);
/*
# Description
Checks if an item is in the game world regardless of whether or not the item
exists at all (in other words, the function returning false gives no indication
of whether or not the item is not in the world or just doesn't exist)
*/
forward Item:GetItemFromButtonID(Button:buttonid);
/*
# Description
Returns the item ID associated with the specified button ID (if any).
# Returns
INVALID_ITEM_ID if the button is not associated with any item.
*/
forward GetItemName(Item:id, string[]);
/*
# Description
Returns the name of the type of the specified item ID and appends the unique
text assigned to the item to the end.
# Returns
Boolean to indicate success or failure.
*/
forward Item:GetPlayerInteractingItem(playerid);
/*
# Description
Returns the ID handle of the item that <playerid> is interacting with. This
means either picking up, dropping or giving.
*/
forward GetPlayerNearbyItems(playerid, Item:list[]);
/*
# Description:
Stores a list of items the player is within interaction range of into <list>.
*/
forward Item:GetNextItemID();
/*
# Description:
Returns the next item ID in the index that is unused. Useful for determining
what ID an item will have before calling CreateItem and thus OnItemCreated.
*/
forward GetItemsInRange(Float:x, Float:y, Float:z, Float:range = 300.0, Item:items[], maxitems = sizeof(items));
/*
# Description:
Returns a list of items in range of the specified point. Uses streamer cells so
the range is limited and will only list items in the surrounding cells.
*/
// Events
forward OnItemTypeDefined(uname[]);
/*
# Called
After an item type is defined.
*/
forward OnItemCreate(Item:itemid);
/*
# Called
As an item is created.
*/
forward OnItemCreated(Item:itemid);
/*
# Called
After an item is created.
*/
forward OnItemDestroy(Item:itemid);
/*
# Called
Before an item is destroyed, the item is still valid and existing.
*/
forward OnItemDestroyed(Item:itemid);
/*
# Called
After an item is destroyed, item ID is now invalid.
*/
forward OnItemCreateInWorld(Item:itemid);
/*
# Called
After an existing (already created with CreateItem) item is created in the game world (for instance, after a player drops the item, or directly after it is created with CreateItem)
*/
forward OnItemRemoveFromWorld(Item:itemid);
/*
# Called
After an item is removed from the world either by being given to a player or by calling RemoveItemFromWorld
*/
forward OnPlayerUseItem(playerid, Item:itemid);
/*
# Called
When a player presses F/Enter while holding an item.
*/
forward OnPlayerUseItemWithItem(playerid, Item:itemid, Item:withitemid);
/*
# Called
When a player uses a held item with an item in the world.
*/
forward OnPlayerUseItemWithButton(playerid, Button:buttonid, Item:itemid);
/*
# Called
When a player uses an item while in the area of a button from an item that is in the game world.
*/
forward OnPlayerRelButtonWithItem(playerid, Button:buttonid, Item:itemid);
/*
# Called
When a player releases the interact key after calling OnPlayerUseItemWithButton.
*/
forward OnPlayerPickUpItem(playerid, Item:itemid);
/*
# Called
When a player presses the button to pick up an item.
# Returns
1 To cancel the pickup request, no animation will play.
*/
forward OnPlayerPickedUpItem(playerid, Item:itemid);
/*
# Called
When a player finishes the picking up animation.
# Returns
1 To cancel giving the item ID to the player.
*/
forward OnPlayerGetItem(playerid, Item:itemid);
/*
# Called
When a player acquires an item from any source.
*/
forward OnPlayerDropItem(playerid, Item:itemid);
/*
# Called
When a player presses the button to drop an item.
# Returns
1 To cancel the drop, no animation will play and the player will keep their item.
*/
forward OnPlayerDroppedItem(playerid, Item:itemid);
/*
# Called
When a player finishes the animation for dropping an item.
*/
forward OnPlayerGiveItem(playerid, targetid, Item:itemid);
/*
# Called
When a player presses the button to give an item to another player.
# Returns
1 To cancel the give request, no animations will play.
*/
forward OnPlayerGivenItem(playerid, targetid, Item:itemid);
/*
# Called
When a player finishes the animation for giving an item to another player.
# Returns
1 To cancel removing the item from the giver and the target receiving the item.
*/
forward OnItemRemovedFromPlayer(playerid, Item:itemid);
/*
# Called
When an item is removed from a player's hands without him dropping it (through a script action)
*/
forward OnItemNameRender(Item:itemid, ItemType:itemtype);
/*
# Called
When the function GetItemName is called, so an additional piece of text can be added to items giving more information unique to that specific item.
*/
forward OnItemHitPointsUpdate(Item:itemid, oldvalue, newvalue);
/*
# Called
When an item's hitpoints value is changed.
*/
forward OnItemPriceUpdate(Item:itemid, oldvalue, newvalue);
/*
# Called
When an item's price value is changed.
*/
/*==============================================================================
Setup
==============================================================================*/
enum E_ITEM_TYPE_DATA {
itm_name[MAX_ITEM_NAME],
itm_uname[MAX_ITEM_NAME],
itm_model,
itm_size,
Float:itm_offsetRotX,
Float:itm_offsetRotY,
Float:itm_offsetRotZ,
Float:itm_zModelOffset,
Float:itm_zButtonOffset,
Float:itm_attachPosX,
Float:itm_attachPosY,
Float:itm_attachPosZ,
Float:itm_attachRotX,
Float:itm_attachRotY,
Float:itm_attachRotZ,
bool:itm_useCarryAnim,
itm_colour,
itm_attachBone,
bool:itm_longPickup,
itm_maxHitPoints,
itm_price
}
enum E_ITEM_DATA {
STREAMER_TAG_OBJECT:itm_objId,
Button:itm_button,
ItemType:itm_type,
Float:itm_posX,
Float:itm_posY,
Float:itm_posZ,
Float:itm_rotX,
Float:itm_rotY,
Float:itm_rotZ,
itm_world,
itm_interior,
itm_hitPoints,
itm_price,
itm_exData,
itm_nameEx[MAX_ITEM_TEXT],
itm_uuid[UUID_LEN]
}
static
itm_TypeData[MAX_ITEM_TYPE][E_ITEM_TYPE_DATA],
itm_TypeCount[MAX_ITEM_TYPE],
itm_TypeTotal;
static
itm_Data[MAX_ITEM][E_ITEM_DATA],
bool:itm_Destroying[MAX_ITEM],
itm_Interactor[MAX_ITEM],
itm_Holder[MAX_ITEM];
const ITEM_ITER_SIZE = _:MAX_ITEM;
new
Iterator:itm_Index<ITEM_ITER_SIZE>,
Iterator:itm_WorldIndex<ITEM_ITER_SIZE>,
Item:itm_ButtonIndex[BTN_MAX];
static
Item:itm_Holding[MAX_PLAYERS],
itm_LongPickupTick[MAX_PLAYERS],
Item:itm_Interacting[MAX_PLAYERS],
itm_Giving[MAX_PLAYERS],
Button:itm_CurrentButton[MAX_PLAYERS],
Timer:itm_InteractTimer[MAX_PLAYERS],
Timer:itm_LongPickupTimer[MAX_PLAYERS];
/*==============================================================================
Zeroing
==============================================================================*/
hook OnScriptInit() {
for(new i; i < MAX_PLAYERS; i++) {
itm_Holding[i] = INVALID_ITEM_ID;
itm_Interacting[i] = INVALID_ITEM_ID;
itm_Giving[i] = INVALID_PLAYER_ID;
}
for(new Item:i; i < MAX_ITEM; i++) {
itm_Holder[i] = INVALID_PLAYER_ID;
}
for(new Button:i; i < BTN_MAX; i++) {
itm_ButtonIndex[i] = INVALID_ITEM_ID;
}
return 1;
}
hook OnPlayerConnect(playerid) {
itm_Holding[playerid] = INVALID_ITEM_ID;
itm_Interacting[playerid] = INVALID_ITEM_ID;
itm_CurrentButton[playerid] = INVALID_BUTTON_ID;
stop itm_InteractTimer[playerid];
stop itm_LongPickupTimer[playerid];
}
hook OnPlayerDisconnect(playerid, reason) {
stop itm_InteractTimer[playerid];
stop itm_LongPickupTimer[playerid];
}
/*==============================================================================
Core Functions
==============================================================================*/
timer _LongPickupItemDelay[500](playerid, id) {
if(CallLocalFunction("OnPlayerPickUpItem", "dd", playerid, id)) {
return;
}
itm_LongPickupTick[playerid] = 0;
itm_Interacting[playerid] = INVALID_ITEM_ID;
PlayerPickUpItem(playerid, Item:id);
}
timer PickUpItemDelay[400](playerid, id, animtype) {
if(animtype == 0) {
ApplyAnimation(playerid, "BOMBER", "BOM_PLANT_2IDLE", 4.0, false, false, false, false, 0);
}
HideActionText(playerid);
itm_Interacting[playerid] = INVALID_ITEM_ID;
if(CallLocalFunction("OnPlayerPickedUpItem", "dd", playerid, id)) {
return 1;
}
GiveWorldItemToPlayer(playerid, Item:id, 1);
return 1;
}
timer DropItemDelay[400](playerid) {
new
Item:id = itm_Holding[playerid],
Float:x,
Float:y,
Float:z,
Float:r;
if(!Iter_Contains(itm_Index, _:id)) {
return 1;
}
RemovePlayerAttachedObject(playerid, ITEM_ATTACH_INDEX);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
itm_Holding[playerid] = INVALID_ITEM_ID;
itm_Interacting[playerid] = INVALID_ITEM_ID;
itm_Holder[id] = INVALID_PLAYER_ID;
itm_Interactor[id] = INVALID_PLAYER_ID;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, r);
CreateItemInWorld(
id,
(x + RandomFloat(-0.5, 0.5)) + (0.5 * floatsin(-r, degrees)),
(y + RandomFloat(-0.5, 0.5)) + (0.5 * floatcos(-r, degrees)),
z - ITEM_FLOOR_OFFSET,
0.0,
0.0,
r,
GetPlayerVirtualWorld(playerid),
GetPlayerInterior(playerid),
true
);
Streamer_Update(playerid);
ApplyAnimation(playerid, "BOMBER", "BOM_PLANT_2IDLE", 4.0, false, false, false, false, 0);
CallLocalFunction("OnPlayerDroppedItem", "dd", playerid, _:id);
CallLocalFunction("OnItemRemovedFromPlayer", "dd", playerid, _:id);
return 1;
}
timer _item_giveItem[500](playerid, targetid) {
// In case the giver quits
if(!IsPlayerConnected(playerid)) {
return;
}
// In case the receiver quits