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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
|
#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 (int %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 bool Entity_IsValid(int 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 int Entity_FindByName(const char[] name, const char[] className="")
{
if (className[0] == '\0') {
// Hack: Double the limit to gets none-networked entities too.
int realMaxEntities = GetMaxEntities() * 2;
for (int entity=0; entity < realMaxEntities; entity++) {
if (!IsValidEntity(entity)) {
continue;
}
if (Entity_NameMatches(entity, name)) {
return entity;
}
}
}
else {
int 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 int Entity_FindByHammerId(int hammerId, const char[] className="")
{
if (className[0] == '\0') {
// Hack: Double the limit to gets none-networked entities too.
int realMaxEntities = GetMaxEntities() * 2;
for (int entity=0; entity < realMaxEntities; entity++) {
if (!IsValidEntity(entity)) {
continue;
}
if (Entity_GetHammerId(entity) == hammerId) {
return entity;
}
}
}
else {
int 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 int Entity_FindByClassName(int startEntity, const char[] 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(int entity, const char[] className, bool partialMatch=false)
{
char 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(int entity, const char[] name)
{
char 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 int Entity_GetName(int entity, char[] buffer, int 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 bool Entity_SetName(int entity, const char[] name, any ...)
{
char 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 int Entity_GetClassName(int entity, char[] buffer, int 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 bool Entity_SetClassName(int entity, const char[] 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 int Entity_GetTargetName(int entity, char[] buffer, int 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 bool Entity_SetTargetName(int entity, const char[] name, any ...)
{
char 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 int Entity_GetGlobalName(int entity, char[] buffer, int 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 bool Entity_SetGlobalName(int entity, const char[] name, any ...)
{
char 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 int Entity_GetParentName(int entity, char[] buffer, int 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 bool Entity_SetParentName(int entity, const char[] name, any ...)
{
char 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 int Entity_GetHammerId(int 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(int entity)
{
return GetEntPropFloat(entity, Prop_Data, "m_flRadius");
}
/**
* Sets the radius (m_flRadius) of an entity.
*
* @param entity Entity index.
* @param radius Radius value
*/
stock void Entity_SetRadius(int entity, float radius)
{
SetEntPropFloat(entity, Prop_Data, "m_flRadius", radius);
}
/**
* Gets the Mins of an entity.
*
* @param entity Entity index.
* @param vec Buffer to hold the vector.
*/
stock void Entity_GetMinSize(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Send, "m_vecMins", vec);
}
/**
* Sets the Mins of an entity.
*
* @param entity Entity index.
* @param vec Vector.
*/
stock void Entity_SetMinSize(int 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 Buffer to hold the vector
*/
stock void Entity_GetMaxSize(int 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 Buffer to hold the vector.
*/
stock void Entity_SetMaxSize(int 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
*/
stock void Entity_SetMinMaxSize(int 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 (int i=0; i<3; i++) {
if (vecMins[i] > vecMaxs[i]) {
ThrowError("Error: mins[%d] > maxs[%d] of entity %d", i, i, EntRefToEntIndex(entity));
}
}
float m_vecMins[3], 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);
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 int Entity_GetSpawnFlags(int entity)
{
return GetEntProp(entity, Prop_Data, "m_spawnflags");
}
/**
* Sets the Spawnflags of an entity.
*
* @param entity Entity index.
* @param flags Flags value
*/
stock void Entity_SetSpawnFlags(int entity, int flags)
{
SetEntProp(entity, Prop_Data, "m_spawnflags", flags);
}
/**
* Adds Spawnflags to an entity.
*
* @param entity Entity index.
* @param flags Flags value
*/
stock void Entity_AddSpawnFlags(int entity, int flags)
{
int spawnFlags = Entity_GetSpawnFlags(entity);
spawnFlags |= flags;
Entity_SetSpawnFlags(entity, spawnFlags);
}
/**
* Removes Spawnflags from an entity.
*
* @param entity Entity index.
* @param flags Flags value
*/
stock void Entity_RemoveSpawnFlags(int entity, int flags)
{
int spawnFlags = Entity_GetSpawnFlags(entity);
spawnFlags &= ~flags;
Entity_SetSpawnFlags(entity, spawnFlags);
}
/**
* Clears all Spawnflags of an entity.
*
* @param entity Entity index.
* @noretur */
stock void Entity_ClearSpawnFlags(int 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(int entity, int flags)
{
return Entity_GetSpawnFlags(entity) & flags == 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(int entity)
{
return view_as<Entity_Flags>(GetEntProp(entity, Prop_Data, "m_iEFlags"));
}
/**
* Sets the entity's Entity flags (m_iEFlags).
*
* @param entity Entity index.
* @param flags Flags value
*/
stock void Entity_SetEFlags(int 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
*/
stock void Entity_AddEFlags(int entity, Entity_Flags flags)
{
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
*/
stock void Entity_RemoveEFlags(int entity, Entity_Flags flags)
{
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(int entity, Entity_Flags flags)
{
Entity_Flags currentEFlags = Entity_GetEFlags(entity);
return currentEFlags & flags == flags;
}
/**
* Marks the surrounding bounds of an entity as outdated.
* You normally call this when a collision setting has changed.
*
* @param entity Entity index.
*/
stock void Entity_MarkSurrBoundsDirty(int 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 int Entity_GetFlags(int entity)
{
return GetEntProp(entity, Prop_Data, "m_fFlags");
}
/**
* Sets the Flags of an entity.
*
* @param entity Entity index.
* @param flags New Flags value
*/
stock void Entity_SetFlags(int entity, int flags)
{
SetEntProp(entity, Prop_Data, "m_fFlags", flags);
}
/**
* Adds Flags to the entity
*
* @param entity Entity index.
* @param flags Flags to add
* @noreturn
*/
stock void Entity_AddFlags(int entity, int flags)
{
int setFlags = Entity_GetFlags(entity);
setFlags |= flags;
Entity_SetFlags(entity, setFlags);
}
/**
* Removes flags from the entity
*
* @param entity Entity index.
* @param flags Flags to remove
*/
stock void Entity_RemoveFlags(int entity, int flags)
{
int 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
*/
stock void Entity_ToggleFlag(int entity, int flag)
{
int setFlag = Entity_GetFlags(entity);
setFlag ^= flag;
Entity_SetFlags(entity, setFlag);
}
/**
* Removes all flags from the entity
*
* @param entity Entity index.
*/
stock void Entity_ClearFlags(int 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(int entity)
{
return view_as<SolidFlags_t>(GetEntProp(entity, Prop_Data, "m_usSolidFlags", 2));
}
/**
* Sets the solid flags of the entity
*
* @param entity Entity index.
* @param flags Solid Flags.
*/
stock void Entity_SetSolidFlags(int entity, SolidFlags_t flags)
{
SolidFlags_t oldFlags = Entity_GetSolidFlags(entity);
flags = flags & view_as<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.
*/
stock void Entity_AddSolidFlags(int entity, SolidFlags_t flags)
{
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.
*/
stock void Entity_RemoveSolidFlags(int entity, SolidFlags_t flags)
{
SolidFlags_t newFlags = Entity_GetSolidFlags(entity);
newFlags &= ~flags;
Entity_SetSolidFlags(entity, newFlags);
}
/**
* Removes all solid flags from the entity.
*
* @param entity Entity index.
*/
stock void Entity_ClearSolidFlags(int entity)
{
Entity_SetSolidFlags(entity, view_as<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(int entity, SolidFlags_t flagMask)
{
return Entity_GetSolidFlags(entity) & flagMask == 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(int entity)
{
return view_as<SolidType_t>(GetEntProp(entity, Prop_Data, "m_nSolidType", 1));
}
/**
* Sets the solidity type of the entity
*
* @param entity Entity index.
* @param Solid Type value.
*/
stock void Entity_SetSolidType(int 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(int 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 int Entity_GetModel(int entity, char[] buffer, int 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
*/
stock void Entity_SetModel(int entity, const char[] 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 int Entity_GetModelIndex(int 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.
*/
stock void Entity_SetModelIndex(int entity, int 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
*/
stock void Entity_SetMaxSpeed(int entity, float value)
{
SetEntPropFloat(entity, Prop_Data, "m_flMaxspeed", value);
}
/*
* Collision groups
* Taken from hl2sdk-ob-valve/public/const.h
*/
enum Collision_Group_t
{
COLLISION_GROUP_NONE = 0,
COLLISION_GROUP_DEBRIS, // Collides with nothing but world and static stuff
COLLISION_GROUP_DEBRIS_TRIGGER, // Same as debris, but hits triggers
COLLISION_GROUP_INTERACTIVE_DEB, // Collides with everything except other interactive debris or debris
COLLISION_GROUP_INTERACTIVE, // Collides with everything except interactive debris or debris
COLLISION_GROUP_PLAYER,
COLLISION_GROUP_BREAKABLE_GLASS,
COLLISION_GROUP_VEHICLE,
COLLISION_GROUP_PLAYER_MOVEMENT, // For HL2, same as Collision_Group_Player, for
// TF2, this filters out other players and CBaseObjects
COLLISION_GROUP_NPC, // Generic NPC group
COLLISION_GROUP_IN_VEHICLE, // for any entity inside a vehicle
COLLISION_GROUP_WEAPON, // for any weapons that need collision detection
COLLISION_GROUP_VEHICLE_CLIP, // vehicle clip brush to restrict vehicle movement
COLLISION_GROUP_PROJECTILE, // Projectiles!
COLLISION_GROUP_DOOR_BLOCKER, // Blocks entities not permitted to get near moving doors
COLLISION_GROUP_PASSABLE_DOOR, // Doors that the player shouldn't collide with
COLLISION_GROUP_DISSOLVING, // Things that are dissolving are in this group
COLLISION_GROUP_PUSHAWAY, // Nonsolid on client and server, pushaway in player code
COLLISION_GROUP_NPC_ACTOR, // Used so NPCs in scripts ignore the player.
COLLISION_GROUP_NPC_SCRIPTED // USed for NPCs in scripts that should not collide with each other
};
/**
* Gets the collision group of an entity.
*
* @param entity entity index
* @return Entity collision group.
*/
stock Collision_Group_t Entity_GetCollisionGroup(int entity)
{
return view_as<Collision_Group_t>(GetEntProp(entity, Prop_Data, "m_CollisionGroup"));
}
/**
* Sets the collision group of an entity.
*
* @param entity entity index
* @param value the new collision group.
*/
stock void Entity_SetCollisionGroup(int entity, Collision_Group_t value)
{
SetEntProp(entity, Prop_Data, "m_CollisionGroup", value);
}
/**
* Functions for getting / setting the origin (position) of an entity.
* Go to http://developer.valvesoftware.com/wiki/Origin
* if you want to learn more about origins
*/
/**
* Gets the Absolute Origin (position) of an entity.
*
* @param entity Entity index.
* @param vec 3 dimensional vector array.
*/
stock void Entity_GetAbsOrigin(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vec);
}
/**
* Sets the Absolute Origin (position) of an entity.
*
* @param entity Entity index.
* @param vec 3 dimensional vector array.
*/
stock void Entity_SetAbsOrigin(int entity, const float vec[3])
{
// We use TeleportEntity to set the origin more safely
// Todo: Replace this with a call to UTIL_SetOrigin() or CBaseEntity::SetLocalOrigin()
TeleportEntity(entity, vec, NULL_VECTOR, NULL_VECTOR);
}
/**
* Functions for getting / setting the angles (rotation) of an entity.
* http://developer.valvesoftware.com/wiki/Angles
* if you want to learn more about angles
*/
/**
* Gets the Angles of an entity
*
* @param entity Entity index.
* @param vec 3 dimensional vector array.
* @noreturn
*/
stock void Entity_GetAbsAngles(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Data, "m_angAbsRotation", vec);
}
/**
* Sets the Angles of an entity
*
* @param entity Entity index.
* @param vec 3 dimensional vector array.
*/
stock void Entity_SetAbsAngles(int entity, const float vec[3])
{
// We use TeleportEntity to set the angles more safely
// Todo: Replace this with a call to CBaseEntity::SetLocalAngles()
TeleportEntity(entity, NULL_VECTOR, vec, NULL_VECTOR);
}
/**
* Functions for getting / setting the velocity of an entity.
* Go to http://developer.valvesoftware.com/wiki/Velocity
* if you want to learn more about the different kind of velocities.
*/
/**
* Gets the Local velocity of an entity.
* The local velocity is the velocity generated by the entity.
*
* @param entity Entity index.
* @param vel An 3 dim array
*/
stock void Entity_GetLocalVelocity(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Data, "m_vecVelocity", vec);
}
/**
* Sets the Local velocity of an entity.
* The local velocity is the velocity generated by the entity.
* Only use this if you know what you are doing,
* the entity can overwrite this value on next frame.
*
* @param entity Entity index.
* @param vel An 3 dim array
*/
stock void Entity_SetLocalVelocity(int entity, const float vec[3])
{
SetEntPropVector(entity, Prop_Data, "m_vecVelocity", vec);
}
/**
* Gets the Base velocity of an entity.
* The base velocity is the velocity applied
* to the entity from other sources .
*
* @param entity Entity index.
* @param vel An 3 dim array
*/
stock void Entity_GetBaseVelocity(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Data, "m_vecBaseVelocity", vec);
}
/**
* Sets the Base velocity of an entity.
* The base velocity is the velocity applied
* to the entity from other sources .
*
* @param entity Entity index.
* @param vel An 3 dim array
*/
stock void Entity_SetBaseVelocity(int entity, const float vec[3])
{
SetEntPropVector(entity, Prop_Data, "m_vecBaseVelocity", vec);
}
/**
* Gets the Absolute velocity of an entity.
* The absolute velocity is the sum of the local
* and base velocities. It's the actual value used to move.
*
* @param entity Entity index.
* @param vel An 3 dim array
*/
stock void Entity_GetAbsVelocity(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Data, "m_vecAbsVelocity", vec);
}
/**
* Sets the Absolute velocity of an entity.
* The absolute velocity is the sum of the local
* and base velocities. It's the actual value used to move.
*
* @param entity Entity index.
* @param vel An 3 dim array
*/
stock void Entity_SetAbsVelocity(int entity, const float vec[3])
{
// We use TeleportEntity to set the velocity more safely
// Todo: Replace this with a call to CBaseEntity::SetAbsVelocity()
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vec);
}
/**
* Returns true if the entity is locked.
*
* @param entity Entity index.
* @return True if locked otherwise false.
*/
stock bool Entity_IsLocked(int entity)
{
return GetEntProp(entity, Prop_Data, "m_bLocked", 1) != 0;
}
/**
* Locks an entity.
*
* @param entity Entity index.
*/
stock void Entity_Lock(int entity)
{
SetEntProp(entity, Prop_Data, "m_bLocked", 1, 1);
}
/**
* Unlocks an entity.
*
* @param entity Entity index.
*/
stock void Entity_UnLock(int entity)
{
SetEntProp(entity, Prop_Data, "m_bLocked", 0, 1);
}
/**
* Gets the health of an entity.
*
* @param entity entity index.
* @return current health points
*/
stock int Entity_GetHealth(int entity)
{
return GetEntProp(entity, Prop_Data, "m_iHealth");
}
/**
* Sets the health of an entity.
*
* @param entity Entity index.
* @param value Health to set (anything above 511 will overload)
* @param ignoreMax Ignore the entity's maxhealth setting.
* @param kill Kill the entity if health gets to 0.
* @return The health the entity actually got set to.
*/
stock int Entity_SetHealth(int entity, int value, bool ignoreMax=false, bool kill=true)
{
int health = value;
if (!ignoreMax) {
int maxHealth = Entity_GetMaxHealth(entity);
if (health > maxHealth) {
health = maxHealth;
}
}
if (health < 0) {
health = 0;
}
SetEntProp(entity, Prop_Data, "m_iHealth", health);
if (health <= 0) {
Entity_Kill(entity);
}
return health;
}
/**
* Add health to an entity
*
* @param entity Entity index
* @param value Health to add
* @param ignoreMax Ignore the entity's maxhealth setting.
* @param kill Kill the entity if health gets to 0.
* @return Returns the new health value set
*/
stock int Entity_AddHealth(int entity, int value, bool ignoreMax=false, bool kill=true)
{
int health = Entity_GetHealth(entity);
health += value;
return Entity_SetHealth(entity, health, ignoreMax, kill);
}
/**
* Takes health from an entity
*
* @param entity entity index
* @param value health to add
* @return returns the new health value set
*/
stock int Entity_TakeHealth(int entity, int value, bool ignoreMax=false, bool kill=true)
{
int health = Entity_GetHealth(entity);
health -= value;
return Entity_SetHealth(entity, health, ignoreMax, kill);
}
/**
* Get the max health of an entity
*
* @param entity Entity Index
* @return Max health points
*/
stock int Entity_GetMaxHealth(int entity)
{
return GetEntProp(entity, Prop_Data, "m_iMaxHealth");
}
/**
* Set the max health of an entity.
*
* @param entity Entity index
* @param value Max health to set (anything above 511 will overload)
*/
stock void Entity_SetMaxHealth(int entity, int value)
{
SetEntProp(entity, Prop_Data, "m_iMaxHealth", value);
}
/**
* Returns the Float distance between an entity
* and a vector origin.
*
* @param entity Entity Index.
* @param target Vector Origin.
* @return Distance Float value.
*/
stock float Entity_GetDistanceOrigin(int entity, const float vec[3])
{
float entityVec[3];
Entity_GetAbsOrigin(entity, entityVec);
return GetVectorDistance(entityVec, vec);
}
/**
* Returns the Float distance between two entities.
* Both entities must be valid.
*
* @param entity Entity Index.
* @param target Target Entity Index.
* @return Distance Float value.
*/
stock float Entity_GetDistance(int entity, int target)
{
float targetVec[3];
Entity_GetAbsOrigin(target, targetVec);
return Entity_GetDistanceOrigin(entity, targetVec);
}
/**
* Checks if the given 2 entitys are within a given range.
*
* @param entity Entity Index.
* @param target Target Entity Index.
* @param distance Max Float distance.
* @return True if the given entities are closer than the given distance value, false otherwise.
*/
stock bool Entity_InRange(int entity, int target, float distance)
{
if (Entity_GetDistance(entity, target) > distance) {
return false;
}
return true;
}
/**
* Enables the motion of an entity.
*
* @param entity Entity index.
* @return True on success, false otherwise
*/
stock bool Entity_EnableMotion(int entity)
{
return AcceptEntityInput(entity, "enablemotion");
}
/**
* Disables the motion of an entity.
*
* @param entity Entity index.
* @return True on success, false otherwise
*/
stock bool Entity_DisableMotion(int entity)
{
return AcceptEntityInput(entity, "disablemotion");
}
/**
* Freezes an entity by setting the FL_FROZEN flag.
*
* @param entity Entity index.
*/
stock void Entity_Freeze(int entity)
{
Entity_AddFlags(entity, FL_FROZEN);
}
/**
* Unfreezes an entity by removing the FL_FROZEN flag.
*
* @param entity Entity index.
*/
stock void Entity_UnFreeze(int entity)
{
Entity_RemoveFlags(entity, FL_FROZEN);
}
/**
* This function points an entity to another with the targetname
* and name. Useful for allot of entities like trigger_teleport.
* If the name is not specified it will be generated automatically.
*
* @param entity Entity index.
* @param target Target entity index.
* @param Optional: target name
*/
stock void Entity_PointAtTarget(int entity, int target, const char[] name="")
{
char targetName[128];
Entity_GetTargetName(entity, targetName, sizeof(targetName));
if (name[0] == '\0') {
if (targetName[0] == '\0') {
// Let's generate our own name
Format(
targetName,
sizeof(targetName),
"_smlib_Entity_PointAtTarget:%d",
target
);
}
}
else {
strcopy(targetName, sizeof(targetName), name);
}
Entity_SetTargetName(entity, targetName);
Entity_SetName(target, targetName);
}
/**
* This function points a point_hurt entity to another damage target entity..
* and name. Useful for allot of entities like trigger_teleport.
* If the name is not specified it will be generated automatically.
*
* @param entity Entity index.
* @param target Target entity index.
* @param Optional: target name
*/
stock void Entity_PointHurtAtTarget(int entity, int target, const char[] name="")
{
char targetName[128];
Entity_GetTargetName(entity, targetName, sizeof(targetName));
if (name[0] == '\0') {
if (targetName[0] == '\0') {
// Let's generate our own name
Format(
targetName,
sizeof(targetName),
"_smlib_Entity_PointHurtAtTarget:%d",
target
);
}
}
else {
strcopy(targetName, sizeof(targetName), name);
}
DispatchKeyValue(entity, "DamageTarget", targetName);
Entity_SetName(target, targetName);
}
/**
* Checks if an entity is a player or not.
* No checks are done if the entity is actually valid,
* the player is connected or ingame.
*
* @param entity Entity index.
* @return True if the entity is a player, false otherwise.
*/
stock bool Entity_IsPlayer(int entity)
{
if (entity < 1 || entity > MaxClients) {
return false;
}
return true;
}
/**
* Creates an entity by classname.
*
* @param className Classname String.
* @param ForceEdictIndex Edict Index to use.
* @return Entity Index or INVALID_ENT_REFERENCE if the slot is already in use.
*/
stock int Entity_Create(const char[] className, int ForceEdictIndex=-1)
{
if (ForceEdictIndex != -1 && Entity_IsValid(ForceEdictIndex)) {
return INVALID_ENT_REFERENCE;
}
return CreateEntityByName(className, ForceEdictIndex);
}
/**
* Kills an entity on the next frame (delayed).
* It is safe to use with entity loops.
* If the entity is is player ForcePlayerSuicide() is called.
*
* @param kenny Entity index.
* @param killChildren When true, kennys children are killed too.
* @return True on success, false otherwise.
*/
stock bool Entity_Kill(int kenny, bool killChildren=false)
{
if (Entity_IsPlayer(kenny)) {
// Oh My God! They Killed Kenny!!
ForcePlayerSuicide(kenny);
return true;
}
if(killChildren){
return AcceptEntityInput(kenny, "KillHierarchy");
}
else {
return AcceptEntityInput(kenny, "Kill");
}
}
/**
* Kills all entities with the given networked classname.
* It is safe to use with entity loops.
* If the entity is is player ForcePlayerSuicide() is called.
*
* @param className Entity Network Class to search for.
* @return Number of entities killed.
*/
stock int Entity_KillAllByClassName(const char[] className)
{
int x = 0;
int entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, className)) != INVALID_ENT_REFERENCE) {
AcceptEntityInput(entity, "kill");
x++;
}
return x;
}
/**
* Gets the owner of an entity.
* For example the owner of a weapon entity.
*
* @param entity Entity index.
* @return Ground Entity or -1
*/
stock int Entity_GetOwner(int entity)
{
return GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
}
/**
* Sets the owner of an entity.
* For example the owner of a weapon entity.
*
* @param entity Entity index.
*/
stock void Entity_SetOwner(int entity, int newOwner)
{
SetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity", newOwner);
}
/**
* Get's the ground entity this entity stands on.
*
* @param entity Entity index.
* @return Ground Entity or -1
*/
stock int Entity_GetGroundEntity(int entity)
{
return GetEntPropEnt(entity, Prop_Data, "m_hGroundEntity");
}
/*
* Damage definitions
*/
#if !defined DMG_GENERIC
#define DMG_GENERIC 0 // generic damage was done
#define DMG_CRUSH (1 << 0) // crushed by falling or moving object.
// NOTE: It's assumed crush damage is occurring as a result of physics collision, so no extra physics force is generated by crush damage.
// DON'T use DMG_CRUSH when damaging entities unless it's the result of a physics collision. You probably want DMG_CLUB instead.
#define DMG_BULLET (1 << 1) // shot
#define DMG_SLASH (1 << 2) // cut, clawed, stabbed
#define DMG_BURN (1 << 3) // heat burned
#define DMG_VEHICLE (1 << 4) // hit by a vehicle
#define DMG_FALL (1 << 5) // fell too far
#define DMG_BLAST (1 << 6) // explosive blast damage
#define DMG_CLUB (1 << 7) // crowbar, punch, headbutt
#define DMG_SHOCK (1 << 8) // electric shock
#define DMG_SONIC (1 << 9) // sound pulse shockwave
#define DMG_ENERGYBEAM (1 << 10) // laser or other high energy beam
#define DMG_PREVENT_PHYSICS_FORCE (1 << 11) // Prevent a physics force
#define DMG_NEVERGIB (1 << 12) // with this bit OR'd in, no damage type will be able to gib victims upon death
#define DMG_ALWAYSGIB (1 << 13) // with this bit OR'd in, any damage type can be made to gib victims upon death.
#define DMG_DROWN (1 << 14) // Drowning
#define DMG_PARALYZE (1 << 15) // slows affected creature down
#define DMG_NERVEGAS (1 << 16) // nerve toxins, very bad
#define DMG_POISON (1 << 17) // blood poisoning - heals over time like drowning damage
#define DMG_RADIATION (1 << 18) // radiation exposure
#define DMG_DROWNRECOVER (1 << 19) // drowning recovery
#define DMG_ACID (1 << 20) // toxic chemicals or acid burns
#define DMG_SLOWBURN (1 << 21) // in an oven
#define DMG_REMOVENORAGDOLL (1<<22) // with this bit OR'd in, no ragdoll will be created, and the target will be quietly removed.
// use this to kill an entity that you've already got a server-side ragdoll for
#define DMG_PHYSGUN (1<<23) // Hit by manipulator. Usually doesn't do any damage.
#define DMG_PLASMA (1<<24) // Shot by Cremator
#define DMG_AIRBOAT (1<<25) // Hit by the airboat's gun
#define DMG_DISSOLVE (1<<26) // Dissolving!
#define DMG_BLAST_SURFACE (1<<27) // A blast on the surface of water that cannot harm things underwater
#define DMG_DIRECT (1<<28)
#define DMG_BUCKSHOT (1<<29) // not quite a bullet. Little, rounder, different.
#endif
/**
* Does damage to an entity.
* This is a powerful function that allows you to specify
* who the attacker is, the damage type and also what weapon
* should be displayed in the hud kill message.
* Note that for entities that fire another entity (RPG's, Crossbow's,
* you have to pass the bullet's class, not the weapon's class !
* It hasn't been tested how expensive this function is, as it
* uses the entity point_hurt.
* If you need a cheaper function use Entity_RemoveHealth().
*
* @param entity Entity index.
* @param damage Amount of damage.
* @param attacker Entity Index of the attacker.
* @param damageType Use the DMG_ definations.
* @param fakeClassName Classname to fake, you can set this if you
* want a specific weapon to be shown in the HUD kill message.
* @param customOrigin Teleport point_hurt to origin before triggering hurt
* useful for damage force calculations e.g. explosions, gun fire direction, ect.
* @return True on success, false otherwise.
*/
stock bool Entity_Hurt(int entity, int damage, int attacker=0, int damageType=DMG_GENERIC, const char[] fakeClassName="", float customOrigin[3]={0.0, 0.0, 0.0})
{
static int point_hurt = INVALID_ENT_REFERENCE;
if (point_hurt == INVALID_ENT_REFERENCE || !IsValidEntity(point_hurt)) {
point_hurt = EntIndexToEntRef(Entity_Create("point_hurt"));
if (point_hurt == INVALID_ENT_REFERENCE) {
return false;
}
DispatchSpawn(point_hurt);
}
AcceptEntityInput(point_hurt, "TurnOn");
SetEntProp(point_hurt, Prop_Data, "m_nDamage", damage);
SetEntProp(point_hurt, Prop_Data, "m_bitsDamageType", damageType);
char orignalTargetName[128];
Entity_GetName(entity, orignalTargetName, sizeof(orignalTargetName));
Entity_PointHurtAtTarget(point_hurt, entity);
if (fakeClassName[0] != '\0') {
Entity_SetClassName(point_hurt, fakeClassName);
}
TeleportEntity(point_hurt, customOrigin, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(point_hurt, "Hurt", attacker);
AcceptEntityInput(point_hurt, "TurnOff");
if (fakeClassName[0] != '\0') {
Entity_SetClassName(point_hurt, "point_hurt");
}
DispatchKeyValue(entity, "targetname", orignalTargetName);
return true;
}
/*
* Gets the parent entity of an entity.
*
* @param entity Entity Index.
* @return Entity Index of the parent.
*/
stock int Entity_GetParent(int entity)
{
return GetEntPropEnt(entity, Prop_Data, "m_pParent");
}
/*
* Clears the parent of an entity.
*
* @param entity Entity Index.
*/
stock void Entity_ClearParent(int entity)
{
//SetVariantString("");
AcceptEntityInput(entity, "ClearParent");
}
/*
* Sets the parent entity of an entity.
*
* @param entity Entity Index.
* @param parent Entity Index of the new parent.
*/
stock void Entity_SetParent(int entity, int parent)
{
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", parent);
}
/*
* Callback for Change_OverTime.
* Note that every parameter is a reference and can be changed during this callback.
* You can get the elapsed time since start by multiply tick with currentCall.
*
* @param entity Entity Index.
* @param interval The current interval from the current game time to execute the next call of this function.
* @param currentCall The current call number (0 is the 1st call at 0.0 seconds, 1 the 2nd call at tick*1 seconds, ...).
* @return When true this callback will be called again at the next defined tick, otherwise it won't.
*/
typedef Entity_ChangeOverTimeCallback = function bool (int &entity, float &interval, int ¤tCall);
/*
* Creates a timer and provides a callback to change various things about an entity over time.
*
* @param entity Entity Index.
* @param interval Interval from the current game time to execute the given function.
* @noreturn
*/
stock void Entity_ChangeOverTime(int entity, float interval=0.1, Entity_ChangeOverTimeCallback valueCallback)
{
DataPack dataPack = CreateDataPack();
WritePackCell(dataPack, EntIndexToEntRef(entity));
WritePackFloat(dataPack, interval);
WritePackCell(dataPack, 0);
WritePackFunction(dataPack, valueCallback);
ResetPack(dataPack);
__smlib_Timer_ChangeOverTime(INVALID_HANDLE,dataPack);
}
public Action __smlib_Timer_ChangeOverTime(Handle Timer, DataPack dataPack)
{
int entity = EntRefToEntIndex(ReadPackCell(dataPack));
if(!Entity_IsValid(entity)){
return Plugin_Stop;
}
float interval = ReadPackFloat(dataPack);
int currentCall = ReadPackCell(dataPack);
Function callback = ReadPackFunction(dataPack);
any result;
Call_StartFunction(INVALID_HANDLE, callback);
Call_PushCellRef(entity);
Call_PushFloatRef(interval);
Call_PushCellRef(currentCall);
Call_Finish(result);
if(result == false){
return Plugin_Stop;
}
ResetPack(dataPack,true);
WritePackCell(dataPack, EntIndexToEntRef(entity));
WritePackFloat(dataPack, interval);
WritePackCell(dataPack, currentCall+1);
WritePackFunction(dataPack, callback);
ResetPack(dataPack);
CreateTimer(interval, __smlib_Timer_ChangeOverTime, dataPack);
return Plugin_Stop;
}
/**
* Gets the next child, entity is parent of.
*
* @param parent Entity Index (of Parent)
* @param start Start Index.
* @return Entity Index or -1 if no entity was found.
*/
stock int Entity_GetNextChild(int parent, int start=0)
{
int maxEntities = GetMaxEntities();
for (int entity=start; entity < maxEntities; entity++) {
if (!Entity_IsValid(entity)) {
continue;
}
if (entity > 0 && entity <= MaxClients && !IsClientConnected(entity)) {
continue;
}
if (Entity_GetParent(entity) == parent) {
return entity;
}
}
return INVALID_ENT_REFERENCE;
}
/**
* Gets the move/open direction of an entity (only available for func_door*, prop_door* and func_movelinear).
* Ex: if vec[2] is 1.0 a func_door moves straight up.
*
* @param entity Entity index.
* @param vec Vector.
*/
stock void Entity_GetMoveDirection(int entity, float vec[3])
{
GetEntPropVector(entity, Prop_Data, "m_vecMoveDir", vec);
}
/**
* Sets the move/open direction of an entity (only available for func_door*, prop_door* and func_movelinear).
* Ex: if vec[2] is 1.0 a func_door moves straight up.
*
* @param entity Entity index.
* @param vec Vector.
*/
stock void Entity_SetMoveDirection(int entity, const float vec[3])
{
SetEntPropVector(entity, Prop_Data, "m_vecMoveDir", vec);
}
/**
* Returns if the entity will force close (won't be blockable by players and/or objects) or not when triggered to move.
*
* @param entity Entity index.
* @return True if the door will force close, otherwise false.
*/
stock bool Entity_GetForceClose(int entity)
{
return GetEntProp(entity, Prop_Data, "m_bForceClosed") != 0;
}
/**
* Sets if the door should force close (souldn't be blockable by players and/or objects) or not when triggered to move.
*
* @param entity Entity index.
* @param forceClose If true the door will force close, otherwise it won't.
*/
stock void Entity_SetForceClose(int entity, bool forceClose)
{
SetEntProp(entity, Prop_Data, "m_bForceClosed", forceClose);
}
/**
* Gets the speed of a moving entity (like doors: open close speed).
*
* @param entity Entity index.
* @return Speed of the entity.
*/
stock float Entity_GetSpeed(int entity)
{
return GetEntPropFloat(entity, Prop_Data, "m_flSpeed");
}
/**
* Sets how fast an entity moves (like doors: open close speed).
*
* @param entity Entity index.
* @param speed The new speed of the entity.
*/
stock void Entity_SetSpeed(int entity, float speed)
{
SetEntPropFloat(entity, Prop_Data, "m_flSpeed", speed);
}
/**
* Gets the damage of a moving entity when blocked (like doors when open or close and players and/or objects are between the entity and something else).
* Note: Negative values add health to the blocking entity.
*
* @param entity Entity index.
* @return Damage.
*/
stock float Entity_GetBlockDamage(int entity)
{
return GetEntPropFloat(entity, Prop_Data, "m_flBlockDamage");
}
/**
* Sets the damage of a moving entity when blocked (like doors when open or close and players and/or objects are between the entity and something else).
* Note: Negative values add health to the blocking entity.
*
* @param entity Entity index.
* @param damage Damage.
*/
stock void Entity_SetBlockDamage(int entity, float damage)
{
SetEntPropFloat(entity, Prop_Data, "m_flBlockDamage", damage);
}
/**
* Returns if the given entity is disabled or not.
*
* @param entity Entity index.
* @return True if entity is disabled, otherwise false.
*/
stock bool Entity_IsDisabled(int entity)
{
return GetEntProp(entity, Prop_Data, "m_bDisabled", 1) != 0;
}
/**
* Disables the given entity.
*
* @param entity Entity index.
* @return True if successful otherwise false.
*/
stock bool Entity_Disable(int entity)
{
return AcceptEntityInput(entity, "Disable");
}
/**
* Enables the given entity.
*
* @param entity Entity index.
* @return True if successful otherwise false.
*/
stock bool Entity_Enable(int entity)
{
return AcceptEntityInput(entity, "Enable");
}
// settings for m_takedamage taken from hl2sdk-ob-valve\game\shared\shareddefs.h
#define DAMAGE_NO 0
#define DAMAGE_EVENTS_ONLY 1 // Call damage functions, but don't modify health
#define DAMAGE_YES 2
#define DAMAGE_AIM 3
/**
* Sets the mode for an entity to take damage.
* Note: This is used to give a client god mode (DAMAGE_NO).
*
* @param entity Entity index.
* @param value Mode, use DAMAGE_* defines.
*/
stock void Entity_SetTakeDamage(int entity, int value)
{
SetEntProp(entity, Prop_Data, "m_takedamage", value, 1);
}
/**
* Gets the mode for an entity to take damage.
* Note: When the return value is DAMAGE_NO then the client is using godmode.
*
* @param entity Entity index.
* @return Take damage mode (DAMAGE_*).
*/
stock int Entity_GetTakeDamage(int entity)
{
return GetEntProp(entity, Prop_Data, "m_takedamage", 1);
}
/**
* Sets the minimum of damage required to hurt this entity.
* Example: This is used to block any damage done by projectile weapons against a gun ship in Half-Life 2.
*
* @param entity Entity index.
* @param minDamage Minimum required damage.
*/
stock void Entity_SetMinHealthDamage(int entity, int minDamage)
{
SetEntProp(entity, Prop_Data, "m_iMinHealthDmg", minDamage);
}
/**
* Gets the minimum of damage required to hurt this entity.
* Example: This is used to block any damage done by projectile weapons against a gun ship in Half-Life 2.
*
* @param entity Entity index.
* @return Minimum required damage.
*/
stock int Entity_GetMinHealthDamage(int entity)
{
return GetEntProp(entity, Prop_Data, "m_iMinHealthDmg");
}
/**
* Gets an entity's color.
*
* @param entity Entity index
* @param color 4 dimensional array where [r,g,b,a] values are stored
* @error Invalid entity index, or lack of mod compliance.
*/
stock void Entity_GetRenderColor(int entity, int color[4])
{
static bool gotconfig = false;
static char prop[32];
if (!gotconfig) {
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_clrRender", prop, sizeof(prop));
delete gc;
if (!exists) {
strcopy(prop, sizeof(prop), "m_clrRender");
}
gotconfig = true;
}
int offset = GetEntSendPropOffs(entity, prop);
if (offset <= 0) {
ThrowError("SetEntityRenderColor not supported by this mod");
}
for (int i=0; i < 4; i++) {
color[i] = GetEntData(entity, offset + i, 1);
}
}
/**
* Sets an entity's color.
* Doesn't change the value, if set to -1.
*
* @param entity Entity index
* @param r Amount of red (0-255)
* @param g Amount of green (0-255)
* @param b Amount of blue (0-255)
* @param a Amount of alpha (0-255)
* @error Invalid entity index, or lack of mod compliance.
*/
stock void Entity_SetRenderColor(int entity, int r=-1, int g=-1, int b=-1, int a=-1)
{
static bool gotconfig = false;
static char prop[32];
if (!gotconfig) {
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_clrRender", prop, sizeof(prop));
delete gc;
if (!exists) {
strcopy(prop, sizeof(prop), "m_clrRender");
}
gotconfig = true;
}
int offset = GetEntSendPropOffs(entity, prop);
if (offset <= 0) {
ThrowError("SetEntityRenderColor not supported by this mod");
}
if(r != -1) {
SetEntData(entity, offset, r, 1, true);
}
if(g != -1) {
SetEntData(entity, offset + 1, g, 1, true);
}
if(b != -1) {
SetEntData(entity, offset + 2, b, 1, true);
}
if(a != -1) {
SetEntData(entity, offset + 3, a, 1, true);
}
}
/**
* Sends the 'addouput' command to an entity.
*
* @param entity Entity Index.
* @param input Input command.
* @param activator Entity index which initiated the sequence of actions (-1 for a NULL entity).
* @param caller Entity index from which this event is sent (-1 for a NULL entity).
* @param outputid Unknown.
* @return True if successful, otherwise false.
*/
stock bool Entity_AddOutput(int entity, const char[] input, int activator=-1, int caller=-1, int outputid=0)
{
SetVariantString(input);
return AcceptEntityInput(entity, "addoutput", activator, caller, outputid);
}
|