/
entities.inc
2152 lines (1914 loc) · 60.3 KB
/
entities.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
#if defined _smlib_entities_included
#endinput
#endif
#define _smlib_entities_included
#include <sourcemod>
#include <sdktools_entinput>
#include <sdktools_functions>
/**
* Macro for iterating trough all children (entities it is parent of) of an entity.
*
* @param 1 Entity Index of the parent.
* @param 2 Name of the children entity index variable (will be only valid in the loop).
*/
#define LOOP_CHILDREN(%1,%2) for (new %2=Entity_GetNextChild(%1); %2 != INVALID_ENT_REFERENCE; %2=Entity_GetNextChild(%1, ++%2))
/*
* Checks if an entity is valid and exists.
*
* @param entity Entity Index.
* @return True if the entity is valid, false otherwise.
*/
stock Entity_IsValid(entity)
{
return IsValidEntity(entity);
}
/**
* Finds an entity by its name.
* You can optionally specify the classname to search for.
* Note: If the classname is specified it uses The Sourcemod native
* function FindEntityByClassname() which uses the engine's
* linked entity list for finding entities. This might be
* cheaper, use this if you call this function very often.
*
* @param name Name of the entity you want so search.
* @param className Optional: Classname of the entity
* @return Entity index or INVALID_ENT_REFERENCE if not matching entity was found.
*/
stock Entity_FindByName(const String:name[], const String:className[]="")
{
if (className[0] == '\0') {
// Hack: Double the limit to gets none-networked entities too.
new realMaxEntities = GetMaxEntities() * 2;
for (new entity=0; entity < realMaxEntities; entity++) {
if (!IsValidEntity(entity)) {
continue;
}
if (Entity_NameMatches(entity, name)) {
return entity;
}
}
}
else {
new entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, className)) != INVALID_ENT_REFERENCE) {
if (Entity_NameMatches(entity, name)) {
return entity;
}
}
}
return INVALID_ENT_REFERENCE;
}
/**
* Finds an entity by its HammerID.
* The newer version of Valve's Hammer editor
* sets a unique ID for each entity in a map.
* It only finds the first occurence.
* Note: If the classname is specified it uses The Sourcemod native
* function FindEntityByClassname() which uses the engine's
* linked entity list for finding entities. This might be
* cheaper, use this if you call this function very often.
*
* @param hammerId Hammer editor ID
* @param className Optional: Classname of the entity
* @return Edict Index or INVALID_ENT_REFERENCE if no entity was found.
*/
stock Entity_FindByHammerId(hammerId, const String:className[]="")
{
if (className[0] == '\0') {
// Hack: Double the limit to gets none-networked entities too.
new realMaxEntities = GetMaxEntities() * 2;
for (new entity=0; entity < realMaxEntities; entity++) {
if (!IsValidEntity(entity)) {
continue;
}
if (Entity_GetHammerId(entity) == hammerId) {
return entity;
}
}
}
else {
new entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, className)) != INVALID_ENT_REFERENCE) {
if (Entity_GetHammerId(entity) == hammerId) {
return entity;
}
}
}
return INVALID_ENT_REFERENCE;
}
/**
* Searches for an entity by classname.
* This is a wrapper around FindEntityByClassname
* and has been added for completion.
*
* @param startEnt The entity index after which to begin searching from. Use -1 to start from the first entity.
* @param classname Classname of the entity to find.
* @return Entity index >= 0 if found, -1 otherwise.
*/
stock Entity_FindByClassName(startEntity, const String:className[])
{
return FindEntityByClassname(startEntity, className);
}
/**
* Checks if an entity (partially) matches a specific entity class.
*
* @param entity Entity Index.
* @param className Classname String.
* @partialMatch If to do a partial classname check.
* @return True if the classname matches, false otherwise.
*/
stock bool:Entity_ClassNameMatches(entity, const String:className[], partialMatch=false)
{
decl String:entity_className[64];
Entity_GetClassName(entity, entity_className, sizeof(entity_className));
if (partialMatch) {
return (StrContains(entity_className, className) != -1);
}
return StrEqual(entity_className, className);
}
/**
* Checks if an entity matches a name
*
* @param entity Entity Index.
* @param class Name String.
* @return True if the name matches, false otherwise.
*/
stock bool:Entity_NameMatches(entity, const String:name[])
{
decl String:entity_name[128];
Entity_GetName(entity, entity_name, sizeof(entity_name));
return StrEqual(name, entity_name);
}
/**
* Gets the Name of an entity.
*
* @param entity Entity index.
* @param buffer Return/Output buffer.
* @param size Max size of buffer.
* @return Number of non-null bytes written.
*/
stock Entity_GetName(entity, String:buffer[], size)
{
return GetEntPropString(entity, Prop_Data, "m_iName", buffer, size);
}
/**
* Sets the Name of an entity.
*
* @param entity Entity index.
* @param name The name you want to give.
* @return True on success, false otherwise.
*/
stock Entity_SetName(entity, const String:name[], any:...)
{
decl String:format[128];
VFormat(format, sizeof(format), name, 3);
return DispatchKeyValue(entity, "targetname", format);
}
/**
* Gets the Classname of an entity.
* This is like GetEdictClassname(), except it works for ALL
* entities, not just edicts.
*
* @param entity Entity index.
* @param buffer Return/Output buffer.
* @param size Max size of buffer.
* @return Number of non-null bytes written.
*/
stock Entity_GetClassName(entity, String:buffer[], size)
{
return GetEntPropString(entity, Prop_Data, "m_iClassname", buffer, size);
}
/**
* Sets the Classname of an entity.
*
* @param entity Entity index.
* @param name The name you want to give.
* @return True on success, false otherwise.
*/
stock Entity_SetClassName(entity, const String:className[])
{
return DispatchKeyValue(entity, "classname", className);
}
/**
* Gets the Target name of an other entity
*
* @param entity Entity index.
* @param buffer Return/Output buffer.
* @param size Max size of buffer.
* @return Number of non-null bytes written.
*/
stock Entity_GetTargetName(entity, String:buffer[], size)
{
return GetEntPropString(entity, Prop_Data, "m_target", buffer, size);
}
/**
* Sets the Target name of an other Entity
*
* @param entity Entity index.
* @param name The target name you want to set
* @return True on success, false otherwise.
*/
stock Entity_SetTargetName(entity, const String:name[], any:...)
{
decl String:format[128];
VFormat(format, sizeof(format), name, 3);
return DispatchKeyValue(entity, "target", format);
}
/**
* Gets the Global Name of an entity.
*
* @param entity Entity index.
* @param buffer Return/Output buffer.
* @param size Max size of buffer.
* @return Number of non-null bytes written.
*/
stock Entity_GetGlobalName(entity, String:buffer[], size)
{
return GetEntPropString(entity, Prop_Data, "m_iGlobalname", buffer, size);
}
/**
* Sets the Global Name of an entity.
*
* @param entity Entity index.
* @param name The global name you want to set.
* @return True on success, false otherwise.
*/
stock Entity_SetGlobalName(entity, const String:name[], any:...)
{
decl String:format[128];
VFormat(format, sizeof(format), name, 3);
return DispatchKeyValue(entity, "globalname", format);
}
/**
* Gets the Parent name of an entity.
*
* @param entity Entity index.
* @param buffer Return/Output buffer.
* @param size Max size of buffer.
* @return Number of non-null bytes written.
*/
stock Entity_GetParentName(entity, String:buffer[], size)
{
return GetEntPropString(entity, Prop_Data, "m_iParent", buffer, size);
}
/**
* Sets the Parent name of an entity.
*
* @param entity Entity index.
* @param name The parent name you want to set.
* @return True on success, false otherwise.
*/
stock Entity_SetParentName(entity, const String:name[], any:...)
{
decl String:format[128];
VFormat(format, sizeof(format), name, 3);
return DispatchKeyValue(entity, "parentname", format);
}
/**
* Gets the Hammer-ID of an entity.
* The Hammer Editor gives every entity a unique ID.
* Note: Old maps don't have Hammer-ID's set for entities
*
* @param entity Entity index.
* @return Hammer ID.
*/
stock Entity_GetHammerId(entity)
{
return GetEntProp(entity, Prop_Data, "m_iHammerID");
}
/**
* Gets the radius (m_flRadius) of an entity.
*
* @param entity Entity index.
* @return Radius
*/
stock Float:Entity_GetRadius(entity)
{
return GetEntPropFloat(entity, Prop_Data, "m_flRadius");
}
/**
* Sets the radius (m_flRadius) of an entity.
*
* @param entity Entity index.
* @param radius Radius value
* @noreturn
*/
stock Entity_SetRadius(entity, Float:radius)
{
SetEntPropFloat(entity, Prop_Data, "m_flRadius", radius);
}
/**
* Gets the Mins of an entity.
*
* @param entity Entity index.
* @param vec Vector.
* @noreturn
*/
stock Entity_GetMinSize(entity, Float:vec[3])
{
GetEntPropVector(entity, Prop_Send, "m_vecMins", vec);
}
/**
* Sets the Mins of an entity.
*
* @param entity Entity index.
* @param vec Vector.
* @noreturn
*/
stock Entity_SetMinSize(entity, const Float:vecMins[3])
{
SetEntPropVector(entity, Prop_Send, "m_vecMins", vecMins);
}
/**
* Gets the Mins of an entity.
* This functions isn't safe to use, use Entity_SetMinMaxSize() instead.
*
* @param entity Entity index
* @param vec return vector.
* @noreturn
*/
stock Entity_GetMaxSize(entity, Float:vec[3])
{
GetEntPropVector(entity, Prop_Send, "m_vecMaxs", vec);
}
/**
* Sets the Maxs of an entity.
* This functions isn't safe to use, use Entity_SetMinMaxSize() instead.
*
* @param entity Entity index.
* @param vec Vector.
* @noreturn
*/
stock Entity_SetMaxSize(entity, const Float:vecMaxs[3])
{
SetEntPropVector(entity, Prop_Send, "m_vecMaxs", vecMaxs);
}
/**
* Sets the Min and Max Size of an entity.
* Code is taken from HL2SDK and rewritten for Sourcemod.
*
* @param entity Entity index.
* @param vecMins Min size Vector
* @param vecMaxs Max size Vector
* @noreturn
*/
stock Entity_SetMinMaxSize(entity, Float:vecMins[3], Float:vecMaxs[3])
{
// Taken from hl2sdk-ob-valve\game\server\util.cpp SetMinMaxSize()
// Todo: Replace this by a SDK call
for (new i=0; i<3; i++) {
if (vecMins[i] > vecMaxs[i]) {
ThrowError("Error: mins[%d] > maxs[%d] of entity %d", i, i, EntRefToEntIndex(entity));
}
}
decl Float:m_vecMins[3], Float:m_vecMaxs[3];
Entity_GetMinSize(entity, m_vecMins);
Entity_GetMaxSize(entity, m_vecMaxs);
if (Math_VectorsEqual(m_vecMins, vecMins) && Math_VectorsEqual(m_vecMaxs, vecMaxs)) {
return;
}
Entity_SetMinSize(entity, vecMins);
Entity_SetMaxSize(entity, vecMaxs);
decl Float:vecSize[3];
SubtractVectors(vecMaxs, vecMins, vecSize);
Entity_SetRadius(entity, GetVectorLength(vecSize) * 0.5);
Entity_MarkSurrBoundsDirty(entity);
}
/*
* Spawn Flags
* Many entities define their specific spawnflags, check the HL2SDK.
*/
/*
* Phys prop spawnflags
* Taken from hl2sdk-ob-valve\game\shared\props_shared.h
*/
#define SF_PHYSPROP_START_ASLEEP 0x000001
#define SF_PHYSPROP_DONT_TAKE_PHYSICS_DAMAGE 0x000002 // this prop can't be damaged by physics collisions
#define SF_PHYSPROP_DEBRIS 0x000004
#define SF_PHYSPROP_MOTIONDISABLED 0x000008 // motion disabled at startup (flag only valid in spawn - motion can be enabled via input)
#define SF_PHYSPROP_TOUCH 0x000010 // can be 'crashed through' by running player (plate glass)
#define SF_PHYSPROP_PRESSURE 0x000020 // can be broken by a player standing on it
#define SF_PHYSPROP_ENABLE_ON_PHYSCANNON 0x000040 // enable motion only if the player grabs it with the physcannon
#define SF_PHYSPROP_NO_ROTORWASH_PUSH 0x000080 // The rotorwash doesn't push these
#define SF_PHYSPROP_ENABLE_PICKUP_OUTPUT 0x000100 // If set, allow the player to +USE this for the purposes of generating an output
#define SF_PHYSPROP_PREVENT_PICKUP 0x000200 // If set, prevent +USE/Physcannon pickup of this prop
#define SF_PHYSPROP_PREVENT_PLAYER_TOUCH_ENABLE 0x000400 // If set, the player will not cause the object to enable its motion when bumped into
#define SF_PHYSPROP_HAS_ATTACHED_RAGDOLLS 0x000800 // Need to remove attached ragdolls on enable motion/etc
#define SF_PHYSPROP_FORCE_TOUCH_TRIGGERS 0x001000 // Override normal debris behavior and respond to triggers anyway
#define SF_PHYSPROP_FORCE_SERVER_SIDE 0x002000 // Force multiplayer physics object to be serverside
#define SF_PHYSPROP_RADIUS_PICKUP 0x004000 // For Xbox, makes small objects easier to pick up by allowing them to be found
#define SF_PHYSPROP_ALWAYS_PICK_UP 0x100000 // Physcannon can always pick this up, no matter what mass or constraints may apply.
#define SF_PHYSPROP_NO_COLLISIONS 0x200000 // Don't enable collisions on spawn
#define SF_PHYSPROP_IS_GIB 0x400000 // Limit # of active gibs
/*
* Physbox Spawnflags. Start at 0x01000 to avoid collision with CBreakable's
* Taken from hl2sdk-ob-valve\game\server\physobj.h
*/
#define SF_PHYSBOX_ASLEEP 0x01000
#define SF_PHYSBOX_IGNOREUSE 0x02000
#define SF_PHYSBOX_DEBRIS 0x04000
#define SF_PHYSBOX_MOTIONDISABLED 0x08000
#define SF_PHYSBOX_USEPREFERRED 0x10000
#define SF_PHYSBOX_ENABLE_ON_PHYSCANNON 0x20000
#define SF_PHYSBOX_NO_ROTORWASH_PUSH 0x40000 // The rotorwash doesn't push these
#define SF_PHYSBOX_ENABLE_PICKUP_OUTPUT 0x80000
#define SF_PHYSBOX_ALWAYS_PICK_UP 0x100000 // Physcannon can always pick this up, no matter what mass or constraints may apply.
#define SF_PHYSBOX_NEVER_PICK_UP 0x200000 // Physcannon will never be able to pick this up.
#define SF_PHYSBOX_NEVER_PUNT 0x400000 // Physcannon will never be able to punt this object.
#define SF_PHYSBOX_PREVENT_PLAYER_TOUCH_ENABLE 0x800000 // If set, the player will not cause the object to enable its motion when bumped into
/*
* Spawnflags for func breakable
* Taken from hl2sdk-ob-valve\game\server\func_break.h
*/
#define SF_BREAK_TRIGGER_ONLY 0x0001 // may only be broken by trigger
#define SF_BREAK_TOUCH 0x0002 // can be 'crashed through' by running player (plate glass)
#define SF_BREAK_PRESSURE 0x0004 // can be broken by a player standing on it
#define SF_BREAK_PHYSICS_BREAK_IMMEDIATELY 0x0200 // the first physics collision this breakable has will immediately break it
#define SF_BREAK_DONT_TAKE_PHYSICS_DAMAGE 0x0400 // this breakable doesn't take damage from physics collisions
#define SF_BREAK_NO_BULLET_PENETRATION 0x0800 // don't allow bullets to penetrate
/*
* Spawnflags for func_pushable (it's also func_breakable, so don't collide with those flags)
* Taken from hl2sdk-ob-valve\game\server\func_break.h
*/
#define SF_PUSH_BREAKABLE 0x0080
#define SF_PUSH_NO_USE 0x0100 // player cannot +use pickup this ent
/**
* Gets the Spawnflags of an entity.
*
* @param entity Entity index.
* @return Spawnflags value
*/
stock Entity_GetSpawnFlags(entity)
{
return GetEntProp(entity, Prop_Data, "m_spawnflags");
}
/**
* Sets the Spawnflags of an entity.
*
* @param entity Entity index.
* @param flags Flags value
* @noreturn
*/
stock Entity_SetSpawnFlags(entity, flags)
{
SetEntProp(entity, Prop_Data, "m_spawnflags", flags);
}
/**
* Adds Spawnflags to an entity.
*
* @param entity Entity index.
* @param flags Flags value
* @noreturn
*/
stock Entity_AddSpawnFlags(entity, flags)
{
new spawnFlags = Entity_GetSpawnFlags(entity);
spawnFlags |= flags;
Entity_SetSpawnFlags(entity, spawnFlags);
}
/**
* Removes Spawnflags from an entity.
*
* @param entity Entity index.
* @param flags Flags value
* @noreturn
*/
stock Entity_RemoveSpawnFlags(entity, flags)
{
new spawnFlags = Entity_GetSpawnFlags(entity);
spawnFlags &= ~flags;
Entity_SetSpawnFlags(entity, spawnFlags);
}
/**
* Clears all Spawnflags of an entity.
*
* @param entity Entity index.
* @noreturn
*/
stock Entity_ClearSpawnFlags(entity)
{
Entity_SetSpawnFlags(entity, 0);
}
/**
* Returns whether the entity has specific Spawnflags.
*
* @param entity Entity index.
* @param flags Flags value.
* @return True if the entity has the spawnflags set, false otherwise.
*/
stock bool:Entity_HasSpawnFlags(entity, flags)
{
return bool:(Entity_GetSpawnFlags(entity) & flags);
}
/*
* Entity flags, CBaseEntity::m_iEFlags
* Taken from: hl2sdk-ob-valve\game\shared\shareddefs.h
*/
enum Entity_Flags
{
EFL_KILLME = (1<<0), // This entity is marked for death -- This allows the game to actually delete ents at a safe time
EFL_DORMANT = (1<<1), // Entity is dormant, no updates to client
EFL_NOCLIP_ACTIVE = (1<<2), // Lets us know when the noclip command is active.
EFL_SETTING_UP_BONES = (1<<3), // Set while a model is setting up its bones.
EFL_KEEP_ON_RECREATE_ENTITIES = (1<<4), // This is a special entity that should not be deleted when we restart entities only
EFL_HAS_PLAYER_CHILD= (1<<4), // One of the child entities is a player.
EFL_DIRTY_SHADOWUPDATE = (1<<5), // Client only- need shadow manager to update the shadow...
EFL_NOTIFY = (1<<6), // Another entity is watching events on this entity (used by teleport)
// The default behavior in ShouldTransmit is to not send an entity if it doesn't
// have a model. Certain entities want to be sent anyway because all the drawing logic
// is in the client DLL. They can set this flag and the engine will transmit them even
// if they don't have a model.
EFL_FORCE_CHECK_TRANSMIT = (1<<7),
EFL_BOT_FROZEN = (1<<8), // This is set on bots that are frozen.
EFL_SERVER_ONLY = (1<<9), // Non-networked entity.
EFL_NO_AUTO_EDICT_ATTACH = (1<<10), // Don't attach the edict; we're doing it explicitly
// Some dirty bits with respect to abs computations
EFL_DIRTY_ABSTRANSFORM = (1<<11),
EFL_DIRTY_ABSVELOCITY = (1<<12),
EFL_DIRTY_ABSANGVELOCITY = (1<<13),
EFL_DIRTY_SURR_COLLISION_BOUNDS = (1<<14),
EFL_DIRTY_SPATIAL_PARTITION = (1<<15),
// UNUSED = (1<<16),
EFL_IN_SKYBOX = (1<<17), // This is set if the entity detects that it's in the skybox.
// This forces it to pass the "in PVS" for transmission.
EFL_USE_PARTITION_WHEN_NOT_SOL = (1<<18), // Entities with this flag set show up in the partition even when not solid
EFL_TOUCHING_FLUID = (1<<19), // Used to determine if an entity is floating
// FIXME: Not really sure where I should add this...
EFL_IS_BEING_LIFTED_BY_BARNACLE = (1<<20),
EFL_NO_ROTORWASH_PUSH = (1<<21), // I shouldn't be pushed by the rotorwash
EFL_NO_THINK_FUNCTION = (1<<22),
EFL_NO_GAME_PHYSICS_SIMULATION = (1<<23),
EFL_CHECK_UNTOUCH = (1<<24),
EFL_DONTBLOCKLOS = (1<<25), // I shouldn't block NPC line-of-sight
EFL_DONTWALKON = (1<<26), // NPC;s should not walk on this entity
EFL_NO_DISSOLVE = (1<<27), // These guys shouldn't dissolve
EFL_NO_MEGAPHYSCANNON_RAGDOLL = (1<<28), // Mega physcannon can't ragdoll these guys.
EFL_NO_WATER_VELOCITY_CHANGE = (1<<29), // Don't adjust this entity's velocity when transitioning into water
EFL_NO_PHYSCANNON_INTERACTION = (1<<30), // Physcannon can't pick these up or punt them
EFL_NO_DAMAGE_FORCES = (1<<31), // Doesn't accept forces from physics damage
};
/**
* Gets the Entity flags (m_iEFlags) of an entity.
*
* @param entity Entity index.
* @return Entity flags value
*/
stock Entity_Flags:Entity_GetEFlags(entity)
{
return Entity_Flags:GetEntProp(entity, Prop_Data, "m_iEFlags");
}
/**
* Sets the entity's Entity flags (m_iEFlags).
*
* @param entity Entity index.
* @param flags Flags value
* @noreturn
*/
stock Entity_SetEFlags(entity, Entity_Flags:flags)
{
SetEntProp(entity, Prop_Data, "m_iEFlags", flags);
}
/**
* Adds Entity flags (m_iEFlags) to an entity.
*
* @param entity Entity index.
* @param flags Flags value
* @noreturn
*/
stock Entity_AddEFlags(entity, Entity_Flags:flags)
{
new Entity_Flags:setFlags = Entity_GetEFlags(entity);
setFlags |= flags;
Entity_SetEFlags(entity, setFlags);
}
/**
* Removes Entity flags (m_iEFlags) from an entity.
*
* @param entity Entity index.
* @param flags Flags value
* @noreturn
*/
stock Entity_RemoveEFlags(entity, Entity_Flags:flags)
{
new Entity_Flags:setFlags = Entity_GetEFlags(entity);
setFlags &= ~flags;
Entity_SetEFlags(entity, setFlags);
}
/**
* Checks if the entity has specific Entity flags (m_iEFlags) set.
*
* @param entity Entity index.
* @param flags Flags value
* @return True if the flags are set, false otherwise.
*/
stock bool:Entity_HasEFlags(entity, Entity_Flags:flags)
{
new Entity_Flags:currentEFlags = Entity_GetEFlags(entity);
return bool:(currentEFlags & flags);
}
/**
* Marks the surrounding bounds of an entity as outdated.
* You normally call this when a collision setting has changed.
*
* @param entity Entity index.
* @noreturn
*/
stock Entity_MarkSurrBoundsDirty(entity)
{
Entity_AddEFlags(entity, EFL_DIRTY_SURR_COLLISION_BOUNDS);
}
/*
* CBaseEntity::m_fFlags Functions
* Use the FL_ Defines (FL_ONGROUND, ...) or
* special entity specific flags.
* Note: The flag FL_AIMTARGET probably doesn't work as
* we have current no way of adding/removing it to the AimTarget List.
*/
/**
* Gets the Flags of an entity.
*
* @param entity Entity Index.
* @return Entity Flags.
*/
stock Entity_GetFlags(entity)
{
return GetEntProp(entity, Prop_Data, "m_fFlags");
}
/**
* Sets the Flags of an entity.
*
* @param entity Entity index.
* @param flags New Flags value
* @noreturn
*/
stock Entity_SetFlags(entity, flags)
{
SetEntProp(entity, Prop_Data, "m_fFlags", flags);
}
/**
* Adds Flags to the entity
*
* @param entity Entity index.
* @param flags Flags to add
* @noreturn
*/
stock Entity_AddFlags(entity, flags)
{
new setFlags = Entity_GetFlags(entity);
setFlags |= flags;
Entity_SetFlags(entity, flags);
}
/**
* Removes flags from the entity
*
* @param entity Entity index.
* @param flags Flags to remove
* @noreturn
*/
stock Entity_RemoveFlags(entity, flags)
{
new setFlags = Entity_GetFlags(entity);
setFlags &= ~flags;
Entity_SetFlags(entity, setFlags);
}
/**
* Toggles the specified flag on the entity.
* Adds the flag to the entity if it doesn't exists
* or removes it otherwise.
*
* @param entity Entity index.
* @param flags Flag to Toggle
* @noreturn
*/
stock Entity_ToggleFlag(entity, flag)
{
new setFlag = Entity_GetFlags(entity);
setFlag ^= flag;
Entity_SetFlags(entity, setFlag);
}
/**
* Removes all flags from the entity
*
* @param entity Entity index.
* @noreturn
*/
stock Entity_ClearFlags(entity)
{
Entity_SetFlags(entity, 0);
}
/* edict->solid values
* NOTE: Some movetypes will cause collisions independent of SOLID_NOT/SOLID_TRIGGER when the entity moves
* SOLID only effects OTHER entities colliding with this one when they move - UGH!
*
* Solid type basically describes how the bounding volume of the object is represented
* NOTE: These numerical values are used in the FGD by the prop code (see prop_dynamic)
* Taken from: hl2sdk-ob-valve\public\const.h
*/
enum SolidFlags_t
{
FSOLID_CUSTOMRAYTEST = 0x0001, // Ignore solid type + always call into the entity for ray tests
FSOLID_CUSTOMBOXTEST = 0x0002, // Ignore solid type + always call into the entity for swept box tests
FSOLID_NOT_SOLID = 0x0004, // Are we currently not solid?
FSOLID_TRIGGER = 0x0008, // This is something may be collideable but fires touch functions
// even when it's not collideable (when the FSOLID_NOT_SOLID flag is set)
FSOLID_NOT_STANDABLE = 0x0010, // You can't stand on this
FSOLID_VOLUME_CONTENTS = 0x0020, // Contains volumetric contents (like water)
FSOLID_FORCE_WORLD_ALIGNED = 0x0040, // Forces the collision rep to be world-aligned even if it's SOLID_BSP or SOLID_VPHYSICS
FSOLID_USE_TRIGGER_BOUNDS = 0x0080, // Uses a special trigger bounds separate from the normal OBB
FSOLID_ROOT_PARENT_ALIGNED = 0x0100, // Collisions are defined in root parent's local coordinate space
FSOLID_TRIGGER_TOUCH_DEBRIS = 0x0200, // This trigger will touch debris objects
FSOLID_MAX_BITS = 10
};
/**
* Gets the solid flags of the entity
*
* @param entity Entity index.
* @return Solid Flags.
*/
stock SolidFlags_t:Entity_GetSolidFlags(entity)
{
return SolidFlags_t:GetEntProp(entity, Prop_Data, "m_usSolidFlags", 2);
}
/**
* Sets the solid flags of the entity
*
* @param entity Entity index.
* @param flags Solid Flags.
* @noreturn
*/
stock Entity_SetSolidFlags(entity, SolidFlags_t:flags)
{
new SolidFlags_t:oldFlags = Entity_GetSolidFlags(entity);
flags = flags & SolidFlags_t:0xFFFF;
if (oldFlags == flags) {
return;
}
SetEntProp(entity, Prop_Data, "m_usSolidFlags", flags, 2);
// These two flags, if changed, can produce different surrounding bounds
if ((oldFlags & (FSOLID_FORCE_WORLD_ALIGNED | FSOLID_USE_TRIGGER_BOUNDS)) !=
(flags & (FSOLID_FORCE_WORLD_ALIGNED | FSOLID_USE_TRIGGER_BOUNDS)))
{
Entity_MarkSurrBoundsDirty(entity);
}
}
/**
* Adds solid flags to the entity
*
* @param entity Entity index.
* @param flags Solid Flags.
* @noreturn
*/
stock Entity_AddSolidFlags(entity, SolidFlags_t:flags)
{
new SolidFlags_t:newFlags = Entity_GetSolidFlags(entity);
newFlags |= flags;
Entity_SetSolidFlags(entity, newFlags);
}
/**
* Removes solid flags from the entity.
*
* @param entity Entity index.
* @param flags Solid Flags.
* @noreturn
*/
stock Entity_RemoveSolidFlags(entity, SolidFlags_t:flags)
{
new SolidFlags_t:newFlags = Entity_GetSolidFlags(entity);
newFlags &= ~flags;
Entity_SetSolidFlags(entity, newFlags);
}
/**
* Removes all solid flags from the entity.
*
* @param entity Entity index.
* @noreturn
*/
stock Entity_ClearSolidFlags(entity)
{
Entity_SetSolidFlags(entity, SolidFlags_t:0);
}
/**
* Checks whether certain solid flags are set on the entity.
*
* @param entity Entity index.
* @param flags Solid Flags.
* @return True if the specified flags are set, false otherwise.
*/
stock bool:Entity_SolidFlagsSet(entity, SolidFlags_t:flagMask)
{
return bool:(Entity_GetSolidFlags(entity) & flagMask);
}
enum SolidType_t
{
SOLID_NONE = 0, // no solid model
SOLID_BSP = 1, // a BSP tree
SOLID_BBOX = 2, // an AABB
SOLID_OBB = 3, // an OBB (not implemented yet)
SOLID_OBB_YAW = 4, // an OBB, constrained so that it can only yaw
SOLID_CUSTOM = 5, // Always call into the entity for tests
SOLID_VPHYSICS = 6, // solid vphysics object, get vcollide from the model and collide with that
SOLID_LAST,
};
/**
* Gets the solidity type of the entity
*
* @param entity Entity index.
* @return Solid Type
*/
stock SolidType_t:Entity_GetSolidType(entity)
{
return SolidType_t:GetEntProp(entity, Prop_Data, "m_nSolidType", 1);
}
/**
* Sets the solidity type of the entity
*
* @param entity Entity index.
* @param Solid Type value.
* @noreturn
*/
stock Entity_SetSolidType(entity, SolidType_t:value)
{
SetEntProp(entity, Prop_Send, "m_nSolidType", value, 1);
Entity_MarkSurrBoundsDirty(entity);
}
/**
* Checks whether the entity is solid or not.
*
* @param entity Entity index.
* @return True if the entity is solid, false otherwise.
*/
stock bool:Entity_IsSolid(entity)
{
return (Entity_GetSolidType(entity) != SOLID_NONE &&
!Entity_SolidFlagsSet(entity, FSOLID_NOT_SOLID));
}
/**
* Retrieves the model path of a given entity.
* Returns "*num" for Brush entities.
*
* @param entity entity reference or index
* @param model buffer String for the model
* @param size max size of buffer string
* @return Number of non-null bytes written.
*/
stock Entity_GetModel(entity, String:buffer[], size)
{
return GetEntPropString(entity, Prop_Data, "m_ModelName", buffer, size);
}
/**
* Sets the model to a given entity.
* Be sure it has been precached.
* This is an alias for SetEntityModel()
*
* @param entity Entity index
* @param model Model name
* @noreturn
*/
stock Entity_SetModel(entity, const String:model[])
{
SetEntityModel(entity, model);
}
/**
* Gets the entity's model index, if it has one set.
*
* @param entity Entity index.
* @return The Entity's model index
*/
stock Entity_GetModelIndex(entity)
{
return GetEntProp(entity, Prop_Data, "m_nModelIndex", 2);
}
/**
* Sets the entity's model index (must be precached)
*
* @param entity Entity index.
* @param index Model Index.
* @noreturn
*/
stock Entity_SetModelIndex(entity, index)
{
SetEntProp(entity, Prop_Data, "m_nModelIndex", index, 2);
}
/**
* Sets the entity's maxspeed to the given value (in units per second)
*
* @param entity Entity index
* @param maxspeed the maximum speed the entity can move
* @noreturn