int CLuaFunctionDefs::SetSoundEffectEnabled ( lua_State* luaVM ) { CClientPlayer* pPlayer = NULL; CClientSound* pSound = NULL; SString strEffectName = ""; CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsUserDataOfType < CClientSound > ( ) ) { argStream.ReadUserData ( pSound ); } else if ( argStream.NextIsUserDataOfType < CClientPlayer > ( ) ) { argStream.ReadUserData ( pPlayer ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "sound/player", 1 ); lua_pushboolean ( luaVM, false ); return false; } argStream.ReadString ( strEffectName ); if ( !argStream.HasErrors() ) { if ( pSound ) { bool bEnable = false; if ( argStream.NextIsBool ( ) ) { argStream.ReadBool ( bEnable ); } if ( CStaticFunctionDefinitions::SetSoundEffectEnabled ( *pSound, strEffectName, bEnable ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else if ( pPlayer ) { bool bEnable = false; if ( argStream.NextIsBool ( ) ) { argStream.ReadBool ( bEnable ); } if ( CStaticFunctionDefinitions::SetSoundEffectEnabled ( *pPlayer, strEffectName, bEnable ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaEngineDefs::EngineLoadTXD ( lua_State* luaVM ) { SString strFile = ""; bool bFilteringEnabled = true; CScriptArgReader argStream ( luaVM ); // Grab the TXD filename or data argStream.ReadString ( strFile ); if ( argStream.NextIsBool() ) // Some scripts have a number here (in error) argStream.ReadBool ( bFilteringEnabled, true ); if ( !argStream.HasErrors ( ) ) { // Grab our virtual machine and grab our resource from that. CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Grab this resource CResource* pResource = pLuaMain->GetResource (); if ( pResource ) { bool bIsRawData = CClientTXD::IsTXDData( strFile ); SString strPath; // Is this a legal filepath? if ( bIsRawData || CResourceManager::ParseResourcePathInput( strFile, pResource, &strPath ) ) { // Grab the resource root entity CClientEntity* pRoot = pResource->GetResourceTXDRoot (); // Create a TXD element CClientTXD* pTXD = new CClientTXD ( m_pManager, INVALID_ELEMENT_ID ); // Try to load the TXD file if ( pTXD->LoadTXD ( bIsRawData ? strFile : strPath, bFilteringEnabled, bIsRawData ) ) { // Success loading the file. Set parent to TXD root pTXD->SetParent ( pRoot ); // Return the TXD lua_pushelement ( luaVM, pTXD ); return 1; } else { // Delete it again delete pTXD; argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Error loading TXD" ); } } else argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Bad file path" ); } } } if ( argStream.HasErrors() ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // We failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWorldSoundEnabled ( lua_State* luaVM ) { // setWorldSoundEnabled ( int group, [int index, ], bool enable ) int group; int index = -1; bool bEnabled; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( group ); if ( !argStream.NextIsBool () ) argStream.ReadNumber ( index ); argStream.ReadBool ( bEnabled ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWorldSoundEnabled ( group, index, bEnabled ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM ) { SString strSound = ""; CVector vecPosition; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strSound ); argStream.ReadNumber ( vecPosition.fX ); argStream.ReadNumber ( vecPosition.fY ); argStream.ReadNumber ( vecPosition.fZ ); if ( !argStream.HasErrors() ) { CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( luaMain ) { CResource* pResource = luaMain->GetResource(); if ( pResource ) { SString strFilename; bool bIsURL = false; if ( CResourceManager::ParseResourcePathInput( strSound, pResource, strFilename ) ) strSound = strFilename; else bIsURL = true; // ParseResourcePathInput changes pResource in some cases e.g. an invalid resource URL - crun playSound( ":myNotRunningResource/music/track.mp3" ) // Fixes #6507 - Caz if ( pResource ) { bool bLoop = false; if ( argStream.NextIsBool ( ) ) { argStream.ReadBool ( bLoop ); } CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop ); if ( pSound ) { // call onClientSoundStarted CLuaArguments Arguments; Arguments.PushString ( "play" ); // Reason pSound->CallEvent ( "onClientSoundStarted", Arguments, false ); lua_pushelement ( luaVM, pSound ); return 1; } } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPlayerDefs::SetPlayerNametagColor ( lua_State* luaVM ) { CScriptArgReader argStream ( luaVM ); if ( !argStream.NextIsBool ( 1 ) ) { // Call type 1 // bool setPlayerNametagColor ( player thePlayer, int r, int g, int b ) CClientEntity* pPlayer; int iR; int iG; int iB; argStream.ReadUserData ( pPlayer ); argStream.ReadNumber ( iR ); argStream.ReadNumber ( iG ); argStream.ReadNumber ( iB ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetPlayerNametagColor ( *pPlayer, false, iR, iG, iB ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else { // Call type 2 // bool setPlayerNametagColor ( player thePlayer, false ) CClientEntity* pPlayer; bool bFalse; argStream.ReadUserData ( pPlayer ); argStream.ReadBool ( bFalse ); if ( !argStream.HasErrors () ) { if ( bFalse == false ) { if ( CStaticFunctionDefinitions::SetPlayerNametagColor ( *pPlayer, true, 255, 255, 255 ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPedDefs::SetPedAnimation ( lua_State* luaVM ) { // bool setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, bool loop=true, bool updatePosition=true, bool interruptable=true, bool freezeLastFrame = true] ) CElement * pPed; SString strBlockName, strAnimName; int iTime; bool bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame; bool bDummy; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pPed ); if ( argStream.NextIsBool () ) argStream.ReadBool ( bDummy ); // Wiki used setPedAnimation(source,false) as an example else if ( argStream.NextIsNil () ) argStream.m_iIndex++; // Wiki docs said blockName could be nil else argStream.ReadString ( strBlockName, "" ); argStream.ReadString ( strAnimName, "" ); if ( argStream.NextCouldBeNumber () ) // Freeroam skips the time arg sometimes argStream.ReadNumber ( iTime, -1 ); else iTime = -1; argStream.ReadBool ( bLoop, true ); argStream.ReadBool ( bUpdatePosition, true ); argStream.ReadBool ( bInterruptable, true ); argStream.ReadBool ( bFreezeLastFrame, true ); if ( !argStream.HasErrors () ) { const char *szBlock, *szAnim; szBlock = strBlockName.empty () ? NULL : strBlockName.c_str (); szAnim = strAnimName.empty () ? NULL : strAnimName.c_str (); if ( CStaticFunctionDefinitions::SetPedAnimation ( pPed, szBlock, szAnim, iTime, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetCTime ( lua_State* luaVM ) { // table getRealTime( [int seconds = current], bool localTime = true ) time_t timer; time ( &timer ); bool bLocalTime = true; CScriptArgReader argStream ( luaVM ); if ( argStream.NextCouldBeNumber () ) { argStream.ReadNumber ( timer ); if ( timer < 0 ) { argStream.SetCustomError ( "seconds cannot be negative" ); } } if ( argStream.NextIsBool () ) argStream.ReadBool ( bLocalTime ); tm * time; if ( bLocalTime ) time = localtime ( &timer ); else time = gmtime ( &timer ); if ( time == NULL ) argStream.SetCustomError ( "seconds is out of range" ); if ( argStream.HasErrors () ) { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; } CLuaArguments ret; ret.PushString ( "second" ); ret.PushNumber ( time->tm_sec ); ret.PushString ( "minute" ); ret.PushNumber ( time->tm_min ); ret.PushString ( "hour" ); ret.PushNumber ( time->tm_hour ); ret.PushString ( "monthday" ); ret.PushNumber ( time->tm_mday ); ret.PushString ( "month" ); ret.PushNumber ( time->tm_mon ); ret.PushString ( "year" ); ret.PushNumber ( time->tm_year ); ret.PushString ( "weekday" ); ret.PushNumber ( time->tm_wday ); ret.PushString ( "yearday" ); ret.PushNumber ( time->tm_yday ); ret.PushString ( "isdst" ); ret.PushNumber ( time->tm_isdst ); ret.PushString ( "timestamp" ); ret.PushNumber ( (double) timer ); ret.PushAsTable ( luaVM ); return 1; }