@@ -22,6 +22,8 @@ void CLuaEngineDefs::LoadFunctions ( void )
2222 CLuaCFunctions::AddFunction ( " engineRestoreCOL" , EngineRestoreCOL );
2323 CLuaCFunctions::AddFunction ( " engineReplaceModel" , EngineReplaceModel );
2424 CLuaCFunctions::AddFunction ( " engineRestoreModel" , EngineRestoreModel );
25+ CLuaCFunctions::AddFunction ( " engineReplaceAnimation" , EngineReplaceAnimation );
26+ CLuaCFunctions::AddFunction ( " engineRestoreAnimation" , EngineRestoreAnimation );
2527 CLuaCFunctions::AddFunction ( " engineGetModelLODDistance" , EngineGetModelLODDistance );
2628 CLuaCFunctions::AddFunction ( " engineSetModelLODDistance" , EngineSetModelLODDistance );
2729 CLuaCFunctions::AddFunction ( " engineSetAsynchronousLoading" , EngineSetAsynchronousLoading );
@@ -304,7 +306,7 @@ int CLuaEngineDefs::EngineLoadIFP ( lua_State* luaVM )
304306 if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath ) )
305307 {
306308 // Grab the resource root entity
307- CClientEntity* pRoot = pResource->GetResourceTXDRoot ();
309+ CClientEntity* pRoot = pResource->GetResourceIFPRoot ();
308310
309311 // Check whether the IFP blockname exists or not
310312 if ( g_pClientGame->GetIFPPointerFromMap ( strBlockName ) == nullptr )
@@ -507,6 +509,131 @@ int CLuaEngineDefs::EngineRestoreModel ( lua_State* luaVM )
507509}
508510
509511
512+ int CLuaEngineDefs::EngineReplaceAnimation ( lua_State* luaVM )
513+ {
514+ CClientEntity * pEntity = nullptr ;
515+ SString strInternalBlockName = " " ;
516+ SString strInternalAnimName = " " ;
517+ SString strCustomBlockName = " " ;
518+ SString strCustomAnimName = " " ;
519+
520+ CScriptArgReader argStream ( luaVM );
521+ argStream.ReadUserData ( pEntity );
522+ argStream.ReadString ( strInternalBlockName );
523+ argStream.ReadString ( strInternalAnimName );
524+ argStream.ReadString ( strCustomBlockName );
525+ argStream.ReadString ( strCustomAnimName );
526+
527+ if ( !argStream.HasErrors () )
528+ {
529+ if ( IS_PED ( pEntity ) )
530+ {
531+ CClientPed& Ped = static_cast < CClientPed& > ( *pEntity );
532+
533+ CAnimBlock * pInternalBlock = g_pGame->GetAnimManager ()->GetAnimationBlock ( strInternalBlockName );
534+ CClientIFP * pCustomIFP = g_pClientGame->GetIFPPointerFromMap ( strCustomBlockName );
535+ if ( pInternalBlock && pCustomIFP )
536+ {
537+ CAnimBlendHierarchy * pInternalAnimHierarchy = g_pGame->GetAnimManager ()->GetAnimation ( strInternalAnimName, pInternalBlock );
538+ CAnimBlendHierarchySAInterface * pCustomAnimHierarchyInterface = pCustomIFP->GetAnimationHierarchy ( strCustomAnimName );
539+ if ( pInternalAnimHierarchy && pCustomAnimHierarchyInterface )
540+ {
541+ Ped.ReplaceAnimation ( pInternalAnimHierarchy, pCustomIFP, pCustomAnimHierarchyInterface );
542+ lua_pushboolean ( luaVM, true );
543+ return 1 ;
544+ }
545+ else
546+ argStream.SetCustomError ( " Incorrect Animation name" );
547+ }
548+ else
549+ argStream.SetCustomError ( " Incorrect Block name" );
550+ }
551+ }
552+ if ( argStream.HasErrors () )
553+ m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
554+
555+ lua_pushboolean ( luaVM, false );
556+ return 1 ;
557+ }
558+
559+
560+ int CLuaEngineDefs::EngineRestoreAnimation ( lua_State* luaVM )
561+ {
562+ CClientEntity * pEntity = nullptr ;
563+ bool bRestoreAllAnimations = false ;
564+ bool bRestoreBlockAnimations = false ;
565+ SString strInternalBlockName = " " ;
566+ SString strInternalAnimName = " " ;
567+
568+ CScriptArgReader argStream ( luaVM );
569+ argStream.ReadUserData ( pEntity );
570+ if ( argStream.NextIsNil ( ) || argStream.NextIsNone ( ) )
571+ {
572+ bRestoreAllAnimations = true ;
573+ }
574+ else
575+ {
576+ argStream.ReadString ( strInternalBlockName );
577+ if ( argStream.NextIsNil ( ) || argStream.NextIsNone ( ) )
578+ {
579+ bRestoreBlockAnimations = true ;
580+ }
581+ else
582+ {
583+ argStream.ReadString ( strInternalAnimName );
584+ }
585+ }
586+
587+ if ( !argStream.HasErrors () )
588+ {
589+ if ( IS_PED ( pEntity ) )
590+ {
591+ CClientEntity & Entity = *pEntity;
592+ CClientPed& Ped = static_cast < CClientPed& > ( Entity );
593+
594+ if ( bRestoreAllAnimations )
595+ {
596+ Ped.RestoreAllAnimations ( );
597+ lua_pushboolean ( luaVM, true );
598+ return 1 ;
599+ }
600+ else
601+ {
602+ CAnimBlock * pInternalBlock = g_pGame->GetAnimManager ()->GetAnimationBlock ( strInternalBlockName );
603+ if ( pInternalBlock )
604+ {
605+ if ( bRestoreBlockAnimations )
606+ {
607+ Ped.RestoreAnimations ( *pInternalBlock );
608+ lua_pushboolean ( luaVM, true );
609+ return 1 ;
610+ }
611+ else
612+ {
613+ CAnimBlendHierarchy * pInternalAnimHierarchy = g_pGame->GetAnimManager ()->GetAnimation ( strInternalAnimName, pInternalBlock );
614+ if ( pInternalAnimHierarchy )
615+ {
616+ Ped.RestoreAnimation ( pInternalAnimHierarchy );
617+ lua_pushboolean ( luaVM, true );
618+ return 1 ;
619+ }
620+ else
621+ argStream.SetCustomError ( " Incorrect Animation name" );
622+ }
623+ }
624+ else
625+ argStream.SetCustomError ( " Incorrect Block name" );
626+ }
627+ }
628+ }
629+ if ( argStream.HasErrors () )
630+ m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
631+
632+ lua_pushboolean ( luaVM, false );
633+ return 1 ;
634+ }
635+
636+
510637int CLuaEngineDefs::EngineGetModelLODDistance ( lua_State* luaVM )
511638{
512639// float engineGetModelLODDistance ( int/string modelID )
0 commit comments