|
44 | 44 | #include "viewrender.h" |
45 | 45 | #endif |
46 | 46 |
|
| 47 | +#include "gamestringpool.h" |
| 48 | + |
47 | 49 | // memdbgon must be the last include file in a .cpp file!!! |
48 | 50 | #include "tier0/memdbgon.h" |
49 | 51 |
|
@@ -423,6 +425,42 @@ BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_AnimTimeMustBeFirst ) |
423 | 425 | RecvPropInt( RECVINFO(m_flAnimTime), 0, RecvProxy_AnimTime ), |
424 | 426 | END_RECV_TABLE() |
425 | 427 |
|
| 428 | +BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities" ) |
| 429 | + DEFINE_SCRIPTFUNC_NAMED( GetAbsOrigin, "GetOrigin", "" ) |
| 430 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetForward, "GetForwardVector", "Get the forward vector of the entity" ) |
| 431 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetLeft, "GetLeftVector", "Get the left vector of the entity" ) |
| 432 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetUp, "GetUpVector", "Get the up vector of the entity" ) |
| 433 | + DEFINE_SCRIPTFUNC( GetTeamNumber, "Gets this entity's team" ) |
| 434 | + |
| 435 | +#ifdef MAPBASE_VSCRIPT |
| 436 | + DEFINE_SCRIPTFUNC( GetHealth, "" ) |
| 437 | + DEFINE_SCRIPTFUNC( GetMaxHealth, "" ) |
| 438 | + |
| 439 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetModelName, "GetModelName", "Returns the name of the model" ) |
| 440 | + |
| 441 | + DEFINE_SCRIPTFUNC_NAMED( ScriptEmitSound, "EmitSound", "Plays a sound from this entity." ) |
| 442 | + DEFINE_SCRIPTFUNC_NAMED( VScriptPrecacheScriptSound, "PrecacheSoundScript", "Precache a sound for later playing." ) |
| 443 | + DEFINE_SCRIPTFUNC_NAMED( ScriptSoundDuration, "GetSoundDuration", "Returns float duration of the sound. Takes soundname and optional actormodelname." ) |
| 444 | + |
| 445 | + DEFINE_SCRIPTFUNC( GetClassname, "" ) |
| 446 | + DEFINE_SCRIPTFUNC_NAMED( GetEntityName, "GetName", "" ) |
| 447 | + |
| 448 | + DEFINE_SCRIPTFUNC_NAMED( WorldSpaceCenter, "GetCenter", "Get vector to center of object - absolute coords" ) |
| 449 | + DEFINE_SCRIPTFUNC_NAMED( ScriptEyePosition, "EyePosition", "Get vector to eye position - absolute coords" ) |
| 450 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetAngles, "GetAngles", "Get entity pitch, yaw, roll as a vector" ) |
| 451 | + |
| 452 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoundingMins, "GetBoundingMins", "Get a vector containing min bounds, centered on object" ) |
| 453 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoundingMaxs, "GetBoundingMaxs", "Get a vector containing max bounds, centered on object" ) |
| 454 | + |
| 455 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetMoveParent, "GetMoveParent", "If in hierarchy, retrieves the entity's parent" ) |
| 456 | + DEFINE_SCRIPTFUNC_NAMED( ScriptGetRootMoveParent, "GetRootMoveParent", "If in hierarchy, walks up the hierarchy to find the root parent" ) |
| 457 | + DEFINE_SCRIPTFUNC_NAMED( ScriptFirstMoveChild, "FirstMoveChild", "" ) |
| 458 | + DEFINE_SCRIPTFUNC_NAMED( ScriptNextMovePeer, "NextMovePeer", "" ) |
| 459 | + |
| 460 | + DEFINE_SCRIPTFUNC( GetEffects, "Get effects" ) |
| 461 | + DEFINE_SCRIPTFUNC( IsEffectActive, "Check if an effect is active" ) |
| 462 | +#endif |
| 463 | +END_SCRIPTDESC(); |
426 | 464 |
|
427 | 465 | #ifndef NO_ENTITY_PREDICTION |
428 | 466 | BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_PredictableId ) |
@@ -466,6 +504,8 @@ BEGIN_RECV_TABLE_NOBASE(C_BaseEntity, DT_BaseEntity) |
466 | 504 | RecvPropInt( RECVINFO_NAME(m_hNetworkMoveParent, moveparent), 0, RecvProxy_IntToMoveParent ), |
467 | 505 | RecvPropInt( RECVINFO( m_iParentAttachment ) ), |
468 | 506 |
|
| 507 | + RecvPropString(RECVINFO(m_iName)), |
| 508 | + |
469 | 509 | RecvPropInt( "movetype", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveType ), |
470 | 510 | RecvPropInt( "movecollide", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveCollide ), |
471 | 511 | RecvPropDataTable( RECVINFO_DT( m_Collision ), 0, &REFERENCE_RECV_TABLE(DT_CollisionProperty) ), |
@@ -1095,6 +1135,8 @@ bool C_BaseEntity::Init( int entnum, int iSerialNum ) |
1095 | 1135 |
|
1096 | 1136 | m_nCreationTick = gpGlobals->tickcount; |
1097 | 1137 |
|
| 1138 | + m_hScriptInstance = NULL; |
| 1139 | + |
1098 | 1140 | return true; |
1099 | 1141 | } |
1100 | 1142 |
|
@@ -1165,6 +1207,7 @@ void C_BaseEntity::Term() |
1165 | 1207 | g_Predictables.RemoveFromPredictablesList( GetClientHandle() ); |
1166 | 1208 | } |
1167 | 1209 |
|
| 1210 | + |
1168 | 1211 | // If it's play simulated, remove from simulation list if the player still exists... |
1169 | 1212 | if ( IsPlayerSimulated() && C_BasePlayer::GetLocalPlayer() ) |
1170 | 1213 | { |
@@ -1201,6 +1244,12 @@ void C_BaseEntity::Term() |
1201 | 1244 | RemoveFromLeafSystem(); |
1202 | 1245 |
|
1203 | 1246 | RemoveFromAimEntsList(); |
| 1247 | + |
| 1248 | + if ( m_hScriptInstance ) |
| 1249 | + { |
| 1250 | + g_pScriptVM->RemoveInstance( m_hScriptInstance ); |
| 1251 | + m_hScriptInstance = NULL; |
| 1252 | + } |
1204 | 1253 | } |
1205 | 1254 |
|
1206 | 1255 |
|
@@ -6442,6 +6491,55 @@ int C_BaseEntity::GetCreationTick() const |
6442 | 6491 | return m_nCreationTick; |
6443 | 6492 | } |
6444 | 6493 |
|
| 6494 | +//----------------------------------------------------------------------------- |
| 6495 | +// |
| 6496 | +//----------------------------------------------------------------------------- |
| 6497 | +HSCRIPT C_BaseEntity::GetScriptInstance() |
| 6498 | +{ |
| 6499 | + if (!m_hScriptInstance) |
| 6500 | + { |
| 6501 | + if (m_iszScriptId == NULL_STRING) |
| 6502 | + { |
| 6503 | + char* szName = (char*)stackalloc(1024); |
| 6504 | + g_pScriptVM->GenerateUniqueKey((m_iName != NULL_STRING) ? STRING(GetEntityName()) : GetClassname(), szName, 1024); |
| 6505 | + m_iszScriptId = AllocPooledString(szName); |
| 6506 | + } |
| 6507 | + |
| 6508 | + m_hScriptInstance = g_pScriptVM->RegisterInstance(GetScriptDesc(), this); |
| 6509 | + g_pScriptVM->SetInstanceUniqeId(m_hScriptInstance, STRING(m_iszScriptId)); |
| 6510 | + } |
| 6511 | + return m_hScriptInstance; |
| 6512 | +} |
| 6513 | + |
| 6514 | +#ifdef MAPBASE_VSCRIPT |
| 6515 | +//----------------------------------------------------------------------------- |
| 6516 | +//----------------------------------------------------------------------------- |
| 6517 | +HSCRIPT C_BaseEntity::ScriptGetMoveParent( void ) |
| 6518 | +{ |
| 6519 | + return ToHScript( GetMoveParent() ); |
| 6520 | +} |
| 6521 | +//----------------------------------------------------------------------------- |
| 6522 | +//----------------------------------------------------------------------------- |
| 6523 | +HSCRIPT C_BaseEntity::ScriptGetRootMoveParent() |
| 6524 | +{ |
| 6525 | + return ToHScript( GetRootMoveParent() ); |
| 6526 | +} |
| 6527 | + |
| 6528 | +//----------------------------------------------------------------------------- |
| 6529 | +//----------------------------------------------------------------------------- |
| 6530 | +HSCRIPT C_BaseEntity::ScriptFirstMoveChild( void ) |
| 6531 | +{ |
| 6532 | + return ToHScript( FirstMoveChild() ); |
| 6533 | +} |
| 6534 | + |
| 6535 | +//----------------------------------------------------------------------------- |
| 6536 | +//----------------------------------------------------------------------------- |
| 6537 | +HSCRIPT C_BaseEntity::ScriptNextMovePeer( void ) |
| 6538 | +{ |
| 6539 | + return ToHScript( NextMovePeer() ); |
| 6540 | +} |
| 6541 | +#endif |
| 6542 | + |
6445 | 6543 | //------------------------------------------------------------------------------ |
6446 | 6544 | void CC_CL_Find_Ent( const CCommand& args ) |
6447 | 6545 | { |
|
0 commit comments