int CLuaFunctionDefs::GetClothesByTypeIndex ( lua_State* luaVM ) { unsigned char ucType = 0; unsigned char ucIndex = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( ucType ); argStream.ReadNumber ( ucIndex ); if ( !argStream.HasErrors ( ) ) { SString strTexture, strModel; if ( CStaticFunctionDefinitions::GetClothesByTypeIndex ( ucType, ucIndex, strTexture, strModel ) ) { lua_pushstring ( luaVM, strTexture ); lua_pushstring ( luaVM, strModel ); return 2; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::UtfSeek ( lua_State* luaVM ) { SString strInput = ""; int iPos = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strInput ); argStream.ReadNumber ( iPos ); if ( !argStream.HasErrors ( ) ) { std::wstring strUTF = MbUTF8ToUTF16(strInput); if ( iPos <= static_cast < int >(strUTF.size()) && iPos >= 0 ) { strUTF = strUTF.substr(0,iPos); lua_pushnumber ( luaVM, UTF16ToMbUTF8(strUTF).size() ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::Split ( lua_State* luaVM ) { SString strInput = ""; unsigned int uiDelimiter = 0; SString strDelimiter; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strInput ); if ( argStream.NextIsNumber ( ) ) { argStream.ReadNumber ( uiDelimiter ); wchar_t wUNICODE[2] = { uiDelimiter, '\0' }; strDelimiter = UTF16ToMbUTF8(wUNICODE); } else // It's already a string argStream.ReadString ( strDelimiter ); if ( !argStream.HasErrors ( ) ) { // Copy the string char* strText = new char [ strInput.length ( ) + 1 ]; strcpy ( strText, strInput ); unsigned int uiCount = 0; char* szToken = strtok ( strText, strDelimiter ); // Create a new table lua_newtable ( luaVM ); // Add our first token lua_pushnumber ( luaVM, ++uiCount ); lua_pushstring ( luaVM, szToken ); lua_settable ( luaVM, -3 ); // strtok until we're out of tokens while ( szToken = strtok ( NULL, strDelimiter ) ) { // Add the token to the table lua_pushnumber ( luaVM, ++uiCount ); lua_pushstring ( luaVM, szToken ); lua_settable ( luaVM, -3 ); } // Delete the text delete [] strText; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); return 1; }
int CLuaFunctionDefs::TeaEncode ( lua_State* luaVM ) { SString str; SString key; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( str ); argStream.ReadString ( key ); if ( !argStream.HasErrors() ) { SString result; SString humanReadableResult; SharedUtil::TeaEncode ( str, key, &result ); humanReadableResult = Base64::encode ( result ); lua_pushstring ( luaVM, humanReadableResult ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::PlayMissionAudio ( lua_State* luaVM ) { CElement* pElement; CVector vecPosition; unsigned short usSlot; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pElement ); argStream.ReadNumber ( usSlot ); if ( argStream.NextCouldBeNumber () ) { argStream.ReadVector3D ( vecPosition ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::PlayMissionAudio ( pElement, &vecPosition, usSlot ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::PlayMissionAudio ( pElement, NULL, usSlot ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFileDefs::fileWrite ( lua_State* luaVM ) { // string fileWrite ( file, string [, string2, string3, ...] ) CScriptFile* pFile; SString strMessage; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadString ( strMessage ); if ( !argStream.HasErrors ( ) ) { // While we're not out of string arguments long lBytesWritten = 0; long lArgBytesWritten = 0; do { unsigned long ulDataLen = strMessage.length ( ); // Write it and add the bytes written to our total bytes written lArgBytesWritten = pFile->Write ( ulDataLen, strMessage.c_str ( ) ); if ( lArgBytesWritten == -1 ) { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); return 1; } lBytesWritten += lArgBytesWritten; if ( !argStream.NextIsString ( ) ) break; argStream.ReadString ( strMessage ); } while ( true ); // Inform file verifier if ( lBytesWritten > 0 ) g_pClientGame->GetResourceManager()->OnFileModifedByScript( pFile->GetAbsPath(), "fileWrite" ); // Return the number of bytes we wrote lua_pushnumber ( luaVM, lBytesWritten ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushnil ( luaVM ); return 1; }
int CLuaFunctionDefs::LoadBrowserURL ( lua_State* luaVM ) { // bool loadBrowserURL ( browser webBrowser, string url [, string postData = "", bool postURLEncoded = true ] ) CClientWebBrowser* pWebBrowser; SString strURL; SString strPostData; bool bURLEncoded; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWebBrowser ); argStream.ReadString ( strURL ); argStream.ReadString ( strPostData, "" ); argStream.ReadBool ( bURLEncoded, true ); if ( !argStream.HasErrors () ) { // Are we dealing with a remote website? if ( strURL.substr ( 0, 7 ) == "http://" || strURL.substr ( 0, 8 ) == "https://" ) { bool isLocalURL = strURL.substr ( 0, 11 ) == "http://mta/"; if ( pWebBrowser->IsLocal () != isLocalURL ) { lua_pushboolean ( luaVM, false ); return 1; } lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( strURL, !isLocalURL, strPostData, bURLEncoded ) ); return 1; } // Are we dealing with a local website? If so, parse resource path. Otherwise, return false and load nothing // Todo: Add an ACL right which is necessary to load local websites or websites in general CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { SString strAbsPath; CResource* pResource = pLuaMain->GetResource (); if ( CResourceManager::ParseResourcePathInput ( strURL, pResource, strAbsPath ) && pWebBrowser->IsLocal () ) { // Output deprecated warning, TODO: Remove this at a later point m_pScriptDebugging->LogWarning ( luaVM, "This URL scheme is deprecated and may not work in future versions. Please consider using http://mta/* instead. See https://wiki.mtasa.com/wiki/LoadBrowserURL for details" ); lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( "mtalocal://" + strURL, false, strPostData, bURLEncoded ) ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
// // Check min server is correct // void MinServerReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, const char* szReason ) { CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine ( argStream.m_luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource(); if ( pResource ) { if ( pResource->GetMinServerReqFromMetaXml () < szVersionReq ) { #if MTASA_VERSION_TYPE == VERSION_TYPE_RELEASE argStream.SetVersionWarning ( szVersionReq, "server", szReason ); #endif } } } }
int CLuaFunctionDefs::PlaySound ( lua_State* luaVM ) { SString strSound = ""; CVector vecPosition; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strSound ); 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::PlaySound ( pResource, strSound, bIsURL, 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 CLuaFunctionDefs::XMLNodeSetAttribute ( lua_State* luaVM ) { // pNode, Attribute Name, Value CXMLNode* pNode = NULL; SString strAttributeName = ""; SString strAttributeValue = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); argStream.ReadString ( strAttributeName ); argStream.ReadString ( strAttributeValue, "" ); if ( !argStream.HasErrors ( ) ) { if ( pNode ) { // Are we going to set it to a value? if ( argStream.NextCouldBeString( -1 ) ) { // Write the node CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( strAttributeName ); if ( pAttribute ) { pAttribute->SetValue ( strAttributeValue ); lua_pushboolean ( luaVM, true ); return 1; } } else { // Delete the attribute if it exists CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( strAttributeName ); if ( pAttribute ) { delete pAttribute; lua_pushboolean ( luaVM, true ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFxDefs::fxAddGlass ( lua_State* luaVM ) { // bool fxAddGlass ( float posX, float posY, float posZ, [int colorR=255, int colorG=0, int colorB=0, int colorA=255, float scale=1.0, int count=1] ) // Verify types CVector vecPosition; RwColor rwColor; rwColor.r = 255; rwColor.g = 0; rwColor.b = 0; rwColor.a = 255; float fScale = 1.0f; int iCount = 1; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPosition ); argStream.ReadNumber ( rwColor.r, 255 ); argStream.ReadNumber ( rwColor.g, 0 ); argStream.ReadNumber ( rwColor.b, 0 ); argStream.ReadNumber ( rwColor.a, 255 ); argStream.ReadNumber ( fScale, 1.0f ); argStream.ReadNumber ( iCount, 1 ); if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::FxAddGlass ( vecPosition, rwColor, fScale, iCount ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::AddAccount ( lua_State* luaVM ) { // account addAccount ( string name, string pass[, bool allowCaseVariations = false ] ) SString strName; SString strPassword; bool bAllowCaseVariations; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadString ( strPassword ); argStream.ReadBool ( bAllowCaseVariations, false ); if ( !argStream.HasErrors () ) { if ( !bAllowCaseVariations ) { // Message for new behaviour SString strCaseVariation = m_pAccountManager->GetActiveCaseVariation( strName ); if ( !strCaseVariation.empty() ) argStream.SetCustomError ( SString( "Already an account using a case variation of that name ('%s')", *strCaseVariation ) ); } if ( !argStream.HasErrors () ) { CAccount* pAccount; if ( ( pAccount = CStaticFunctionDefinitions::AddAccount ( strName, strPassword ) ) ) { lua_pushaccount ( luaVM, pAccount ); return 1; } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaMatrixDefs::Create ( lua_State* luaVM ) { CMatrix matrix; CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsVector3D () ) { CVector vecPosition; argStream.ReadVector3D ( vecPosition ); if ( argStream.NextIsVector3D () ) { CVector vecRotation; argStream.ReadVector3D ( vecRotation ); ConvertDegreesToRadiansNoWrap ( vecRotation ); matrix = CMatrix ( vecPosition, vecRotation ); } else { matrix = CMatrix ( vecPosition ); } } else if ( argStream.NextIsUserDataOfType<CLuaMatrix> () ) { argStream.ReadMatrix ( matrix ); matrix = CMatrix ( matrix ); } else if ( !argStream.NextIsNone() ) { argStream.SetCustomError ( "Expected vector3, matrix or nothing" ); m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; } lua_pushmatrix ( luaVM, matrix ); return 1; }
int CLuaFunctionDefs::PlaySFX3D ( lua_State* luaVM ) { // sound playSFX3D ( string audioContainer, int bankIndex, int audioIndex, float posX, float posY, float posZ [, loop = false ] ) eAudioLookupIndex containerIndex; int iBankIndex; int iAudioIndex; CVector vecPosition; bool bLoop; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumString ( containerIndex ); argStream.ReadNumber ( iBankIndex ); argStream.ReadNumber ( iAudioIndex ); argStream.ReadNumber ( vecPosition.fX ); argStream.ReadNumber ( vecPosition.fY ); argStream.ReadNumber ( vecPosition.fZ ); argStream.ReadBool ( bLoop, false ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource (); if ( pResource ) { CClientSound* pSound; if ( CStaticFunctionDefinitions::PlaySFX3D ( pResource, containerIndex, iBankIndex, iAudioIndex, vecPosition, bLoop, pSound ) ) { lua_pushelement ( luaVM, pSound ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaCameraDefs::setCameraMatrix ( lua_State* luaVM ) { // bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = 0, float fov = 70 ] ) CElement* pPlayer; CVector vecPosition; CVector vecLookAt; float fRoll; float fFOV; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pPlayer ); if ( argStream.NextIsUserDataOfType <CLuaMatrix> () ) { CLuaMatrix* pMatrix; argStream.ReadUserData( pMatrix ); vecPosition = pMatrix->GetPosition (); vecLookAt = pMatrix->GetRotation (); } else { argStream.ReadVector3D ( vecPosition ); argStream.ReadVector3D ( vecLookAt, CVector () ); } argStream.ReadNumber ( fRoll, 0.0f ); argStream.ReadNumber ( fFOV, 70.0f ); if ( !argStream.HasErrors () ) { if ( fFOV <= 0.0f || fFOV >= 180.0f ) fFOV = 70.0f; if ( CStaticFunctionDefinitions::SetCameraMatrix ( pPlayer, vecPosition, &vecLookAt, fRoll, fFOV ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaVector4Defs::Pow ( lua_State* luaVM ) { CLuaVector4D* pVector1 = NULL; CLuaVector4D* pVector2 = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pVector1 ); if ( argStream.NextIsNumber () ) { float fValue = 0.0f; argStream.ReadNumber ( fValue ); CVector4D vector ( *pVector1 ); vector.fX = pow ( vector.fX, fValue ); vector.fY = pow ( vector.fY, fValue ); vector.fZ = pow ( vector.fZ, fValue ); vector.fW = pow ( vector.fW, fValue ); lua_pushvector ( luaVM, vector ); return 1; } else { argStream.ReadUserData ( pVector2 ); if ( !argStream.HasErrors () ) { CVector4D vector ( *pVector1 ); vector.fX = pow ( vector.fX, pVector2->fX ); vector.fY = pow ( vector.fY, pVector2->fY ); vector.fZ = pow ( vector.fZ, pVector2->fZ ); vector.fW = pow ( vector.fW, pVector2->fW ); lua_pushvector ( luaVM, vector ); return 1; } else { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); } } lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::XMLCreateFile ( lua_State* luaVM ) { // xmlnode xmlCreateFile ( string filePath, string rootNodeName ) SString filePath; SString rootNodeName; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( filePath ); argStream.ReadString ( rootNodeName ); // Safety check: Don't allow the rootNodeName "private" incase user forget to declare a node name if ( rootNodeName == EnumToString ( ACCESS_PRIVATE ) ) { argStream.SetCustomError( "Expected string at argument 2, got access-type" ); } if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource(); SString strFile; if ( CResourceManager::ParseResourcePathInput( filePath, pResource, strFile ) ) { // Make sure the directory exists MakeSureDirExists ( strFile.c_str () ); // Create the XML CXMLFile * xmlFile = pLuaMain->CreateXML ( strFile.c_str () ); if ( xmlFile ) { // Create its root node CXMLNode* pRootNode = xmlFile->CreateRootNode ( rootNodeName ); if ( pRootNode ) { lua_pushxmlnode ( luaVM, pRootNode ); return 1; } // Delete the XML again pLuaMain->DestroyXML ( xmlFile ); } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaRadarAreaDefs::CreateRadarArea ( lua_State* luaVM ) { // radararea createRadarArea ( float leftX, float bottomY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = getRootElement() ] ) CVector2D vecPosition; CVector2D vecSize; float dRed; float dGreen; float dBlue; float dAlpha; CScriptArgReader argStream ( luaVM ); argStream.ReadVector2D ( vecPosition ); argStream.ReadVector2D ( vecSize ); argStream.ReadNumber ( dRed, 255 ); argStream.ReadNumber ( dGreen, 0 ); argStream.ReadNumber ( dBlue, 0 ); argStream.ReadNumber ( dAlpha, 255 ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); CResource* pResource = pLuaMain ? pLuaMain->GetResource () : NULL; if ( pResource ) { SColorARGB color ( dAlpha, dRed, dGreen, dBlue ); // Create it CClientRadarArea* pRadarArea = CStaticFunctionDefinitions::CreateRadarArea ( *pResource, vecPosition, vecSize, color ); if ( pRadarArea ) { CElementGroup * pGroup = pResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( (CClientEntity*) pRadarArea ); } lua_pushelement ( luaVM, pRadarArea ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFileDefs::fileRead ( lua_State* luaVM ) { // string fileRead ( file theFile, int count ) CScriptFile* pFile; unsigned long ulCount; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( ulCount ); if ( !argStream.HasErrors () ) { if ( ulCount > 0 ) { // Allocate a buffer to read the stuff into and read some shit into it char* pReadContent = new char [ulCount + 1]; long lBytesRead = pFile->Read ( ulCount, pReadContent ); if ( lBytesRead != -1 ) { // Push the string onto the lua stack. Use pushlstring so we are binary // compatible. Normal push string takes zero terminated strings. lua_pushlstring ( luaVM, pReadContent, lBytesRead ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } // Delete our read content. Lua should've stored it delete [] pReadContent; // We're returning the result string return 1; } else { // Reading zero bytes from a file results in an empty string lua_pushstring ( luaVM, "" ); return 1; } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFunctionDefs::SetCameraTarget ( lua_State* luaVM ) { // bool setCameraTarget ( element target = nil ) or setCameraTarget ( float x, float y, float z ) CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsUserData () ) { CClientEntity* pTarget; argStream.ReadUserData ( pTarget ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetCameraTarget ( pTarget ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else { CVector vecTarget; argStream.ReadVector3D ( vecTarget ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetCameraTarget ( vecTarget ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetPerformanceStats ( lua_State* luaVM ) { // table getPerformanceStats ( string category, string options, string filter ) SString strCategory, strOptions, strFilter; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strCategory ); argStream.ReadString ( strOptions, "" ); argStream.ReadString ( strFilter, "" ); if ( !argStream.HasErrors () ) { CClientPerfStatResult Result; CClientPerfStatManager::GetSingleton ()->GetStats ( &Result, strCategory, strOptions, strFilter ); lua_newtable ( luaVM ); for ( int c = 0; c < Result.ColumnCount () ; c++ ) { const SString& name = Result.ColumnName ( c ); lua_pushnumber ( luaVM, c+1 ); // row index number (starting at 1, not 0) lua_pushlstring ( luaVM, name.c_str (), name.length() ); lua_settable ( luaVM, -3 ); } lua_newtable ( luaVM ); for ( int r = 0; r < Result.RowCount () ; r++ ) { lua_newtable ( luaVM ); // new table lua_pushnumber ( luaVM, r+1 ); // row index number (starting at 1, not 0) lua_pushvalue ( luaVM, -2 ); // value lua_settable ( luaVM, -4 ); // refer to the top level table for ( int c = 0; c < Result.ColumnCount () ; c++ ) { SString& cell = Result.Data ( c, r ); lua_pushnumber ( luaVM, c+1 ); lua_pushlstring ( luaVM, cell.c_str (), cell.length () ); lua_settable ( luaVM, -3 ); } lua_pop ( luaVM, 1 ); // pop the inner table } return 2; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
// // Check min client is correct // Return false if below required // bool MinClientReqCheck(CScriptArgReader& argStream, const char* szVersionReq, const char* szReason) { CLuaMain* pLuaMain = g_pClientGame->GetLuaManager()->GetVirtualMachine(argStream.m_luaVM); if (pLuaMain) { CResource* pResource = pLuaMain->GetResource(); if (pResource) { if (pResource->GetMinClientReq() < szVersionReq) { #if MTASA_VERSION_TYPE == VERSION_TYPE_RELEASE if (szReason) argStream.SetVersionWarning(szVersionReq, "client", szReason); #endif return false; } } } return true; }
int CLuaFunctionDefs::CreateTeam ( lua_State* luaVM ) { SString strName; unsigned char ucRed; unsigned char ucGreen; unsigned char ucBlue; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadNumber ( ucRed, 235 ); argStream.ReadNumber ( ucGreen, 221 ); argStream.ReadNumber ( ucBlue, 178 ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = g_pGame->GetLuaManager ()->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource (); if ( pResource ) { CTeam* pTeam = CStaticFunctionDefinitions::CreateTeam ( pResource, strName, ucRed, ucGreen, ucBlue ); if ( pTeam ) { CElementGroup * pGroup = pResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( pTeam ); } lua_pushelement ( luaVM, pTeam ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::toJSON ( lua_State* luaVM ) { // Got a string argument? CScriptArgReader argStream ( luaVM ); if ( !argStream.NextIsNil () ) { int jsonFlags = 0; // Read the argument CLuaArguments JSON; JSON.ReadArgument ( luaVM, 1 ); argStream.Skip ( 1 ); bool bCompact; argStream.ReadBool ( bCompact, false ); jsonFlags |= bCompact ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED; eJSONPrettyType jsonPrettyType; argStream.ReadEnumString ( jsonPrettyType, JSONPRETTY_NONE ); if ( jsonPrettyType != JSONPRETTY_NONE ) jsonFlags |= jsonPrettyType; if ( !argStream.HasErrors () ) { // Convert it to a JSON string std::string strJSON; if ( JSON.WriteToJSONString ( strJSON, false, jsonFlags ) ) { // Return the JSON string lua_pushstring ( luaVM, strJSON.c_str () ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else m_pScriptDebugging->LogBadType ( luaVM ); // Failed lua_pushnil ( luaVM ); return 1; }
int CLuaColShapeDefs::CreateColPolygon ( lua_State* luaVM ) { CVector2D vecPosition; CScriptArgReader argStream ( luaVM ); argStream.ReadVector2D ( vecPosition ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource (); if ( pResource ) { // Create it and return it CClientColPolygon* pShape = CStaticFunctionDefinitions::CreateColPolygon ( *pResource, vecPosition ); if ( pShape ) { // Get the points while ( argStream.NextCouldBeNumber () && argStream.NextCouldBeNumber ( 1 ) ) { argStream.ReadVector2D ( vecPosition ); pShape->AddPoint ( vecPosition ); } CElementGroup * pGroup = pResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( pShape ); } lua_pushelement ( luaVM, pShape ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPedDefs::OOP_WarpPedIntoVehicle ( lua_State* luaVM ) { // ped.vehicle = element vehicle // ped.vehicle = nil CPed* pPed; CVehicle* pVehicle; uint uiSeat = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pPed ); argStream.ReadUserData ( pVehicle, NULL ); if ( pVehicle != NULL ) { if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::WarpPedIntoVehicle ( pPed, pVehicle, uiSeat ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else { if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::RemovePedFromVehicle ( pPed ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPedDefs::CreatePed ( lua_State* luaVM ) { unsigned short usModel; CVector vecPosition; float fRotation; bool bSynced; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( usModel ); argStream.ReadVector3D ( vecPosition ); argStream.ReadNumber ( fRotation, 0.0f ); argStream.ReadBool ( bSynced, true ); if ( !argStream.HasErrors () ) { CLuaMain * pLuaMain = g_pGame->GetLuaManager ()->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource * pResource = pLuaMain->GetResource (); if ( pResource ) { // Create the ped and return its handle CPed* pPed = CStaticFunctionDefinitions::CreatePed ( pResource, usModel, vecPosition, fRotation, bSynced ); if ( pPed ) { CElementGroup * pGroup = pResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( pPed ); } lua_pushelement ( luaVM, pPed ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetSoundSpeed ( lua_State* luaVM ) { CClientPlayer* pPlayer = NULL; CClientSound* pSound = NULL; float fSpeed = 0.0f; 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.ReadNumber ( fSpeed ); if ( !argStream.HasErrors() ) { if ( pSound ) { if ( CStaticFunctionDefinitions::SetSoundSpeed ( *pSound, fSpeed ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else if ( pPlayer ) { if ( CStaticFunctionDefinitions::SetSoundSpeed ( *pPlayer, fSpeed ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::LoadBrowserURL ( lua_State* luaVM ) { // bool loadBrowserURL ( browser webBrowser, string url [, string postData = "", bool postURLEncoded = true ] ) CClientWebBrowser* pWebBrowser; SString strURL; SString strPostData; bool bURLEncoded; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWebBrowser ); argStream.ReadString ( strURL ); argStream.ReadString ( strPostData, "" ); argStream.ReadBool ( bURLEncoded, true ); if ( !argStream.HasErrors () ) { // Are we dealing with a remote website? if ( strURL.substr ( 0, 7 ) == "http://" || strURL.substr ( 0, 8 ) == "https://" ) { lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( strURL, true, strPostData, bURLEncoded ) ); return 1; } // Are we dealing with a local website? If so, parse resource path. Otherwise, return false and load nothing // Todo: Add an ACL right which is necessary to load local websites or websites in general CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { SString strAbsPath; CResource* pResource = pLuaMain->GetResource (); if ( CResourceManager::ParseResourcePathInput ( strURL, pResource, strAbsPath ) && pWebBrowser->IsLocal () ) { pWebBrowser->SetTempURL ( strURL ); lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( "mtalocal://" + strURL, false, strPostData, bURLEncoded ) ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetEasingValue ( lua_State* luaVM ) { // float getEasingValue( float fProgress, string strEasingType [, float fEasingPeriod, float fEasingAmplitude, float fEasingOvershoot] ) float fProgress; CEasingCurve::eType easingType; float fEasingPeriod; float fEasingAmplitude; float fEasingOvershoot; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( fProgress ); argStream.ReadEnumString ( easingType ); argStream.ReadNumber ( fEasingPeriod, 0.3f ); argStream.ReadNumber ( fEasingAmplitude, 1.0f ); argStream.ReadNumber ( fEasingOvershoot, 1.70158f ); if ( argStream.HasErrors () ) { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; } CEasingCurve easingCurve ( easingType ); easingCurve.SetParams ( fEasingPeriod, fEasingAmplitude, fEasingOvershoot ); lua_pushnumber ( luaVM, easingCurve.ValueForProgress ( fProgress ) ); return 1; }