-
-
Notifications
You must be signed in to change notification settings - Fork 452
/
Copy pathCStaticFunctionDefinitions.cpp
10092 lines (8672 loc) · 300 KB
/
CStaticFunctionDefinitions.cpp
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
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
* PURPOSE: Scripting function processing
*
* Multi Theft Auto is available from https://multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include <game/CAnimManager.h>
#include <game/CClock.h>
#include <game/CColPoint.h>
#include <game/CFireManager.h>
#include <game/CFx.h>
#include <game/CGarage.h>
#include <game/CGarages.h>
#include <game/CHandlingEntry.h>
#include <game/CHandlingManager.h>
#include <game/CPlayerInfo.h>
#include <game/CRopes.h>
#include <game/CSettings.h>
#include <game/CTaskManager.h>
#include <game/CWanted.h>
#include <game/CWeapon.h>
#include <game/CWeaponStat.h>
#include <game/CWeaponStatManager.h>
#include <game/CBuildingRemoval.h>
#include <game/TaskBasic.h>
using std::list;
static CLuaManager* m_pLuaManager;
static CEvents* m_pEvents;
static CCoreInterface* m_pCore;
static CGame* m_pGame;
static CClientGame* m_pClientGame;
static CClientManager* m_pManager;
static CClientEntity* m_pRootEntity;
static CClientPlayerManager* m_pPlayerManager;
static CClientVehicleManager* m_pVehicleManager;
static CClientObjectManager* m_pObjectManager;
static CClientColManager* m_pColManager;
static CClientTeamManager* m_pTeamManager;
static CGUI* m_pGUI;
static CClientGUIManager* m_pGUIManager;
static CScriptKeyBinds* m_pScriptKeyBinds;
static CClientMarkerManager* m_pMarkerManager;
static CClientPickupManager* m_pPickupManager;
static CMovingObjectsManager* m_pMovingObjectsManager;
static CBlendedWeather* m_pBlendedWeather;
static CPlayerMap* m_pPlayerMap;
static CClientCamera* m_pCamera;
static CClientExplosionManager* m_pExplosionManager;
static CClientProjectileManager* m_pProjectileManager;
static CClientSoundManager* m_pSoundManager;
// Used to run a function on all the children of the elements too
#define RUN_CHILDREN(func) \
if (Entity.CountChildren() && Entity.IsCallPropagationEnabled()) \
{ \
CElementListSnapshotRef pList = Entity.GetChildrenListSnapshot(); \
for (CElementListSnapshot::const_iterator iter = pList->begin(); iter != pList->end(); iter++) \
if (!(*iter)->IsBeingDeleted()) \
func; \
}
CStaticFunctionDefinitions::CStaticFunctionDefinitions(CLuaManager* pLuaManager, CEvents* pEvents, CCoreInterface* pCore, CGame* pGame,
CClientGame* pClientGame, CClientManager* pManager)
{
m_pLuaManager = pLuaManager;
m_pEvents = pEvents;
m_pCore = pCore;
m_pGame = pGame;
m_pClientGame = pClientGame;
m_pManager = pManager;
m_pRootEntity = m_pClientGame->GetRootEntity();
m_pPlayerManager = pManager->GetPlayerManager();
m_pVehicleManager = pManager->GetVehicleManager();
m_pObjectManager = pManager->GetObjectManager();
m_pColManager = pManager->GetColManager();
m_pTeamManager = pManager->GetTeamManager();
m_pGUI = pCore->GetGUI();
m_pGUIManager = pManager->GetGUIManager();
m_pScriptKeyBinds = m_pClientGame->GetScriptKeyBinds();
m_pMarkerManager = pManager->GetMarkerManager();
m_pPickupManager = pManager->GetPickupManager();
m_pMovingObjectsManager = m_pClientGame->GetMovingObjectsManager();
m_pBlendedWeather = m_pClientGame->GetBlendedWeather();
m_pPlayerMap = m_pClientGame->GetPlayerMap();
m_pCamera = pManager->GetCamera();
m_pExplosionManager = pManager->GetExplosionManager();
m_pProjectileManager = pManager->GetProjectileManager();
m_pSoundManager = pManager->GetSoundManager();
}
CStaticFunctionDefinitions::~CStaticFunctionDefinitions()
{
}
bool CStaticFunctionDefinitions::AddEvent(CLuaMain& LuaMain, const char* szName, bool bAllowRemoteTrigger)
{
assert(szName);
// Valid name?
if (szName[0] != '\0')
{
// Add our event to CEvents
return m_pEvents->AddEvent(szName, "", &LuaMain, bAllowRemoteTrigger);
}
return false;
}
bool CStaticFunctionDefinitions::AddEventHandler(CLuaMain& LuaMain, const char* szName, CClientEntity& Entity, const CLuaFunctionRef& iLuaFunction,
bool bPropagated, EEventPriorityType eventPriority, float fPriorityMod)
{
assert(szName);
// We got an event with that name?
if (m_pEvents->Exists(szName))
{
// Add the event handler
if (Entity.AddEvent(&LuaMain, szName, iLuaFunction, bPropagated, eventPriority, fPriorityMod))
return true;
}
return false;
}
bool CStaticFunctionDefinitions::RemoveEventHandler(CLuaMain& LuaMain, const char* szName, CClientEntity& Entity, const CLuaFunctionRef& iLuaFunction)
{
assert(szName);
// We got an event and handler with that name?
if (m_pEvents->Exists(szName))
{
// ACHTUNG: CHECK WHETHER THE LUA FUNCTION REF IS CORRECTLY FOUND
if (Entity.DeleteEvent(&LuaMain, szName, iLuaFunction))
{
return true;
}
}
return false;
}
bool CStaticFunctionDefinitions::TriggerEvent(const char* szName, CClientEntity& Entity, const CLuaArguments& Arguments, bool& bWasCancelled)
{
// There is such event?
if (m_pEvents->Exists(szName))
{
// Call the event
Entity.CallEvent(szName, Arguments, true);
bWasCancelled = m_pEvents->WasEventCancelled();
return true;
}
return false;
}
bool CStaticFunctionDefinitions::TriggerServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments)
{
assert(szName);
if (CallWithEntity.IsLocalEntity())
return false;
NetBitStreamInterface* pBitStream = g_pNet->AllocateNetBitStream();
if (pBitStream)
{
unsigned short usNameLength = static_cast<unsigned short>(strlen(szName));
pBitStream->WriteCompressed(usNameLength);
pBitStream->Write(szName, usNameLength);
pBitStream->Write(CallWithEntity.GetID());
if (!Arguments.WriteToBitStream(*pBitStream))
{
g_pNet->DeallocateNetBitStream(pBitStream);
return false;
}
g_pNet->SendPacket(PACKET_ID_LUA_EVENT, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(pBitStream);
return true;
}
return false;
}
bool CStaticFunctionDefinitions::TriggerLatentServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments, int iBandwidth,
CLuaMain* pLuaMain, ushort usResourceNetId)
{
assert(szName);
if (CallWithEntity.IsLocalEntity())
return false;
NetBitStreamInterface* pBitStream = g_pNet->AllocateNetBitStream();
if (pBitStream)
{
unsigned short usNameLength = static_cast<unsigned short>(strlen(szName));
pBitStream->WriteCompressed(usNameLength);
pBitStream->Write(szName, usNameLength);
pBitStream->Write(CallWithEntity.GetID());
if (!Arguments.WriteToBitStream(*pBitStream))
{
g_pNet->DeallocateNetBitStream(pBitStream);
return false;
}
g_pClientGame->GetLatentTransferManager()->AddSendBatchBegin(PACKET_ID_LUA_EVENT, pBitStream);
g_pClientGame->GetLatentTransferManager()->AddSend(0, pBitStream->Version(), iBandwidth, pLuaMain, usResourceNetId);
g_pClientGame->GetLatentTransferManager()->AddSendBatchEnd();
g_pNet->DeallocateNetBitStream(pBitStream);
return true;
}
return false;
}
bool CStaticFunctionDefinitions::CancelEvent(bool bCancel)
{
m_pEvents->CancelEvent(bCancel);
return true;
}
bool CStaticFunctionDefinitions::WasEventCancelled()
{
return m_pEvents->WasEventCancelled();
}
bool CStaticFunctionDefinitions::DownloadFile(CResource* pResource, const char* szFile, CResource* pRequestResource, CChecksum checksum)
{
SString strHTTPDownloadURLFull("%s/%s/%s", g_pClientGame->GetHTTPURL().c_str(), pResource->GetName(), szFile);
SString strPath("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), pResource->GetName(), szFile);
// Call SingularFileDownloadManager
if (g_pClientGame->GetSingularFileDownloadManager())
{
g_pClientGame->GetSingularFileDownloadManager()->AddFile(pResource, strPath.c_str(), szFile, strHTTPDownloadURLFull, pRequestResource, checksum);
return true;
}
return false;
}
bool CStaticFunctionDefinitions::OutputConsole(const char* szText)
{
m_pCore->GetConsole()->Print(szText);
return true;
}
bool CStaticFunctionDefinitions::ClearChatBox()
{
m_pCore->ClearChat();
return true;
}
bool CStaticFunctionDefinitions::OutputChatBox(const char* szText, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, bool bColorCoded)
{
if (strlen(szText) <= MAX_OUTPUTCHATBOX_LENGTH)
{
CLuaArguments Arguments;
Arguments.PushString(szText);
Arguments.PushNumber(ucRed);
Arguments.PushNumber(ucGreen);
Arguments.PushNumber(ucBlue);
bool bCancelled = !g_pClientGame->GetRootEntity()->CallEvent("onClientChatMessage", Arguments, false);
if (!bCancelled)
{
m_pCore->ChatPrintfColor("%s", bColorCoded, ucRed, ucGreen, ucBlue, szText);
return true;
}
}
return false;
}
bool CStaticFunctionDefinitions::SetClipboard(SString& strText)
{
std::wstring strUTF = MbUTF8ToUTF16(strText);
// Open and empty the clipboard
OpenClipboard(NULL);
EmptyClipboard();
// Allocate the clipboard buffer and copy the data
HGLOBAL hBuf = GlobalAlloc(GMEM_DDESHARE, strUTF.length() * sizeof(wchar_t) + sizeof(wchar_t));
wchar_t* buf = reinterpret_cast<wchar_t*>(GlobalLock(hBuf));
wcscpy(buf, strUTF.c_str());
GlobalUnlock(hBuf);
// Copy the data into the clipboard
SetClipboardData(CF_UNICODETEXT, hBuf);
// Close the clipboard
CloseClipboard();
return true;
}
bool CStaticFunctionDefinitions::SetWindowFlashing(bool flash, uint count)
{
// Don't flash if the window is active
if (g_pCore->IsFocused() || !g_pCore->GetCVars()->GetValue<bool>("server_can_flash_window", true))
return false;
FLASHWINFO flashInfo;
flashInfo.cbSize = sizeof(FLASHWINFO);
flashInfo.hwnd = g_pCore->GetHookedWindow();
flashInfo.dwTimeout = 0;
flashInfo.uCount = count;
flashInfo.dwFlags = flash ? (FLASHW_ALL | FLASHW_TIMERNOFG) : FLASHW_STOP;
::FlashWindowEx(&flashInfo);
return true;
}
bool CStaticFunctionDefinitions::CreateTrayNotification(SString strText, eTrayIconType eType, bool useSound)
{
// Don't create notifications if window is active
if (g_pCore->IsFocused() || !IsTrayNotificationEnabled())
return false;
// Create tray notification
return g_pCore->GetTrayIcon()->CreateTrayBallon(strText, eType, useSound);
}
bool CStaticFunctionDefinitions::IsTrayNotificationEnabled()
{
return g_pCore->GetCVars()->GetValue<bool>("allow_tray_notifications", true);
}
CClientEntity* CStaticFunctionDefinitions::GetRootElement()
{
return m_pRootEntity;
}
CClientEntity* CStaticFunctionDefinitions::GetElementByID(const char* szID, unsigned int uiIndex)
{
assert(szID);
// Search it from root and down
return m_pRootEntity->FindChild(szID, uiIndex, true);
}
CClientEntity* CStaticFunctionDefinitions::GetElementByIndex(const char* szType, unsigned int uiIndex)
{
assert(szType);
// Search it from root and down
// return m_pMapManager->GetRootElement ()->FindChildByType ( szType, uiIndex, true );
return m_pRootEntity->FindChildByType(szType, uiIndex, true);
}
CClientEntity* CStaticFunctionDefinitions::GetElementChild(CClientEntity& Entity, unsigned int uiIndex)
{
// Grab it
unsigned int uiCurrent = 0;
CChildListType ::const_iterator iter = Entity.IterBegin();
for (; iter != Entity.IterEnd(); iter++)
{
if (uiIndex == uiCurrent++)
{
return *iter;
}
}
// Doesn't exist
return NULL;
}
bool CStaticFunctionDefinitions::GetElementMatrix(CClientEntity& Entity, CMatrix& matrix)
{
return Entity.GetMatrix(matrix);
}
bool CStaticFunctionDefinitions::GetElementPosition(CClientEntity& Entity, CVector& vecPosition)
{
Entity.GetPosition(vecPosition);
return true;
}
bool CStaticFunctionDefinitions::GetElementRotation(CClientEntity& Entity, CVector& vecRotation, eEulerRotationOrder desiredRotOrder)
{
int iType = Entity.GetType();
switch (iType)
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
Ped.GetRotationDegrees(vecRotation);
// Correct the rotation
vecRotation.fZ = fmodf(-vecRotation.fZ, 360);
if (vecRotation.fZ < 0)
vecRotation.fZ = 360 + vecRotation.fZ;
if (desiredRotOrder != EULER_DEFAULT)
{
// In get, ped is Z-Y-X wheras in set it's -Z-Y-Z
// It's a bug in ped, but the goal here is not to fix it, so we hack
vecRotation.fZ = -vecRotation.fZ;
vecRotation = ConvertEulerRotationOrder(vecRotation, EULER_MINUS_ZYX, desiredRotOrder);
}
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
Vehicle.GetRotationDegrees(vecRotation);
if (desiredRotOrder != EULER_DEFAULT && desiredRotOrder != EULER_ZYX)
{
vecRotation = ConvertEulerRotationOrder(vecRotation, EULER_ZYX, desiredRotOrder);
}
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
Object.GetRotationDegrees(vecRotation);
if (desiredRotOrder != EULER_DEFAULT && desiredRotOrder != EULER_ZXY)
{
vecRotation = ConvertEulerRotationOrder(vecRotation, EULER_ZXY, desiredRotOrder);
}
break;
}
case CCLIENTBUILDING:
{
CClientBuilding& pBuilding = static_cast<CClientBuilding&>(Entity);
pBuilding.GetRotationDegrees(vecRotation);
if (desiredRotOrder != EULER_DEFAULT && desiredRotOrder != EULER_ZXY)
{
vecRotation = ConvertEulerRotationOrder(vecRotation, EULER_ZXY, desiredRotOrder);
}
break;
}
case CCLIENTPROJECTILE:
{
CClientProjectile& Projectile = static_cast<CClientProjectile&>(Entity);
Projectile.GetRotationDegrees(vecRotation);
break;
}
case CCLIENTCAMERA:
case CCLIENTEFFECT:
{
Entity.GetRotationDegrees(vecRotation);
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::GetElementVelocity(CClientEntity& Entity, CVector& vecVelocity)
{
int iType = Entity.GetType();
switch (iType)
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
Ped.GetMoveSpeed(vecVelocity);
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
Vehicle.GetMoveSpeed(vecVelocity);
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
Object.GetMoveSpeed(vecVelocity);
break;
}
case CCLIENTPROJECTILE:
{
CClientProjectile& Projectile = static_cast<CClientProjectile&>(Entity);
Projectile.GetVelocity(vecVelocity);
break;
}
case CCLIENTSOUND:
{
CClientSound& Sound = static_cast<CClientSound&>(Entity);
Sound.GetVelocity(vecVelocity);
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::GetElementTurnVelocity(CClientEntity& Entity, CVector& vecTurnVelocity)
{
int iType = Entity.GetType();
switch (iType)
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
Ped.GetTurnSpeed(vecTurnVelocity);
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
Vehicle.GetTurnSpeed(vecTurnVelocity);
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
Object.GetTurnSpeed(vecTurnVelocity);
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::GetElementInterior(CClientEntity& Entity, unsigned char& ucInterior)
{
ucInterior = Entity.GetInterior();
return true;
}
bool CStaticFunctionDefinitions::GetElementBoundingBox(CClientEntity& Entity, CVector& vecMin, CVector& vecMax)
{
CModelInfo* pModelInfo = NULL;
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
pModelInfo = g_pGame->GetModelInfo(Ped.GetModel());
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
pModelInfo = g_pGame->GetModelInfo(Vehicle.GetModel());
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
pModelInfo = g_pGame->GetModelInfo(Object.GetModel());
break;
}
case CCLIENTBUILDING:
{
CClientBuilding& building = static_cast<CClientBuilding&>(Entity);
pModelInfo = g_pGame->GetModelInfo(building.GetModel());
break;
}
}
if (pModelInfo)
{
CBoundingBox* pBoundingBox = pModelInfo->GetBoundingBox();
if (pBoundingBox)
{
vecMin = pBoundingBox->vecBoundMin;
vecMin.fX += pBoundingBox->vecBoundOffset.fX;
vecMin.fY += pBoundingBox->vecBoundOffset.fY;
vecMin.fZ += pBoundingBox->vecBoundOffset.fZ;
vecMax = pBoundingBox->vecBoundMax;
vecMax.fX += pBoundingBox->vecBoundOffset.fX;
vecMax.fY += pBoundingBox->vecBoundOffset.fY;
vecMax.fZ += pBoundingBox->vecBoundOffset.fZ;
return true;
}
}
return false;
}
bool CStaticFunctionDefinitions::GetElementRadius(CClientEntity& Entity, float& fRadius)
{
CModelInfo* pModelInfo = NULL;
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
pModelInfo = g_pGame->GetModelInfo(Ped.GetModel());
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
pModelInfo = g_pGame->GetModelInfo(Vehicle.GetModel());
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
pModelInfo = g_pGame->GetModelInfo(Object.GetModel());
break;
}
}
if (pModelInfo)
{
CBoundingBox* pBoundingBox = pModelInfo->GetBoundingBox();
if (pBoundingBox)
{
fRadius = pBoundingBox->fRadius;
return true;
}
}
return false;
}
CClientEntity* CStaticFunctionDefinitions::GetElementAttachedTo(CClientEntity& Entity)
{
CClientEntity* pEntityAttachedTo = Entity.GetAttachedTo();
if (pEntityAttachedTo)
{
assert(pEntityAttachedTo->IsEntityAttached(&Entity));
return pEntityAttachedTo;
}
return NULL;
}
bool CStaticFunctionDefinitions::GetElementDistanceFromCentreOfMassToBaseOfModel(CClientEntity& Entity, float& fDistance)
{
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
fDistance = static_cast<CClientPed&>(Entity).GetDistanceFromCentreOfMassToBaseOfModel();
return true;
}
case CCLIENTVEHICLE:
{
fDistance = static_cast<CClientVehicle&>(Entity).GetDistanceFromCentreOfMassToBaseOfModel();
return true;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
fDistance = static_cast<CClientObject&>(Entity).GetDistanceFromCentreOfMassToBaseOfModel();
return true;
}
}
return false;
}
bool CStaticFunctionDefinitions::GetElementAttachedOffsets(CClientEntity& Entity, CVector& vecPosition, CVector& vecRotation)
{
Entity.GetAttachedOffsets(vecPosition, vecRotation);
ConvertRadiansToDegrees(vecRotation);
return true;
}
bool CStaticFunctionDefinitions::GetElementAlpha(CClientEntity& Entity, unsigned char& ucAlpha)
{
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
ucAlpha = Ped.GetAlpha();
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
ucAlpha = Vehicle.GetAlpha();
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
ucAlpha = Object.GetAlpha();
break;
}
case CCLIENTMARKER:
{
CClientMarker& Marker = static_cast<CClientMarker&>(Entity);
ucAlpha = Marker.GetColor().A;
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::IsElementOnScreen(CClientEntity& Entity, bool& bOnScreen)
{
bOnScreen = Entity.IsOnScreen();
return true;
}
bool CStaticFunctionDefinitions::GetElementHealth(CClientEntity& Entity, float& fHealth)
{
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
fHealth = Ped.GetHealth();
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
fHealth = Vehicle.GetHealth();
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
fHealth = Object.GetHealth();
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::GetElementModel(CClientEntity& Entity, unsigned short& usModel)
{
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
usModel = static_cast<unsigned short>(Ped.GetModel());
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
usModel = Vehicle.GetModel();
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
usModel = Object.GetModel();
break;
}
case CCLIENTPICKUP:
{
CClientPickup& pPickup = static_cast<CClientPickup&>(Entity);
usModel = pPickup.GetModel();
break;
}
case CCLIENTBUILDING:
{
CClientBuilding& pBuilding = static_cast<CClientBuilding&>(Entity);
usModel = pBuilding.GetModel();
break;
}
case CCLIENTPROJECTILE:
{
CClientProjectile& pProjectile = static_cast<CClientProjectile&>(Entity);
usModel = pProjectile.GetModel();
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::IsElementInWater(CClientEntity& Entity, bool& bInWater)
{
switch (Entity.GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
if (Ped.GetOccupiedVehicle())
{
bInWater = Ped.GetOccupiedVehicle()->IsInWater();
break;
}
else
{
bInWater = Ped.IsInWater();
break;
}
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
bInWater = Vehicle.IsInWater();
break;
}
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::IsElementSyncer(CClientEntity& Entity, bool& bIsSyncer)
{
switch (Entity.GetType())
{
case CCLIENTPED:
{
CClientPed* Ped = static_cast<CClientPed*>(&Entity);
if (Ped)
bIsSyncer = m_pClientGame->GetPedSync()->Exists(Ped);
break;
}
case CCLIENTVEHICLE:
{
CDeathmatchVehicle* Vehicle = static_cast<CDeathmatchVehicle*>(&Entity);
if (Vehicle)
bIsSyncer = m_pClientGame->GetUnoccupiedVehicleSync()->Exists(Vehicle);
break;
}
#ifdef WITH_OBJECT_SYNC
case CCLIENTOBJECT:
{
CDeathmatchObject* pObject = static_cast<CDeathmatchObject*>(&Entity);
if (pObject)
bIsSyncer = m_pClientGame->GetObjectSync()->Exists(pObject);
break;
}
#endif
default:
return false;
}
return true;
}
bool CStaticFunctionDefinitions::IsElementCollidableWith(CClientEntity& Entity, CClientEntity& ThisEntity, bool& bCanCollide)
{
switch (Entity.GetType())
{
case CCLIENTPLAYER:
case CCLIENTPED:
case CCLIENTOBJECT:
case CCLIENTVEHICLE:
{
switch (ThisEntity.GetType())
{
case CCLIENTPLAYER:
case CCLIENTPED:
case CCLIENTOBJECT:
case CCLIENTVEHICLE:
{
bCanCollide = Entity.IsCollidableWith(&ThisEntity);
return true;
}
default:
break;
}
break;
}
default:
break;
}
return false;
}
bool CStaticFunctionDefinitions::GetElementCollisionsEnabled(CClientEntity& Entity)
{
switch (Entity.GetType())
{
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
return Vehicle.IsCollisionEnabled();
}
case CCLIENTOBJECT:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
return Object.IsCollisionEnabled();
}
case CCLIENTPED:
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
return Ped.GetUsesCollision();
}
default:
return false;
}
return false;
}
bool CStaticFunctionDefinitions::IsElementFrozen(CClientEntity& Entity, bool& bFrozen)
{
switch (Entity.GetType())
{
case CCLIENTPLAYER:
case CCLIENTPED:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
bFrozen = Ped.IsFrozen();
break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
bFrozen = Vehicle.IsFrozen();
break;
}
case CCLIENTOBJECT:
{
CClientObject& Object = static_cast<CClientObject&>(Entity);
bFrozen = Object.IsFrozen();
break;
}
default:
return false;
}
return true;
}
CClientDummy* CStaticFunctionDefinitions::CreateElement(CResource& Resource, const char* szTypeName, const char* szID)
{
assert(szTypeName);
assert(szID);
// Long enough typename and not an internal one?
if (szTypeName[0] != '\0' && CClientEntity::GetTypeID(szTypeName) == CCLIENTUNKNOWN)
{
CClientDummy* pDummy = new CClientDummy(m_pManager, INVALID_ELEMENT_ID, szTypeName);
pDummy->SetName(szID);
pDummy->SetParent(Resource.GetResourceDynamicEntity());
return pDummy;
}
return NULL;
}
bool CStaticFunctionDefinitions::DestroyElement(CClientEntity& Entity)
{
if (!Entity.CanBeDestroyedByScript())
return false;
// Run us on all its children
CChildListType ::const_iterator iter = Entity.IterBegin();
while (iter != Entity.IterEnd())
{
if (DestroyElement(**iter))
iter = Entity.IterBegin();
else
++iter;
}
// Are we already being deleted?
if (Entity.IsBeingDeleted())
return false;
// We can't delete our root
if (&Entity == m_pRootEntity)
return false;
// Use the element deleter to delete it if it's local and not system
if (Entity.IsLocalEntity() && !Entity.IsSystemEntity())
{
m_pClientGame->GetElementDeleter()->Delete(&Entity);
return true;
}