int CLuaWorldDefs::setSunColor ( lua_State* luaVM ) { CScriptArgReader argStream ( luaVM ); unsigned char ucCoreR, ucCoreG, ucCoreB, ucCoronaR, ucCoronaG, ucCoronaB; argStream.ReadNumber ( ucCoreR, 0 ); argStream.ReadNumber ( ucCoreG, 0 ); argStream.ReadNumber ( ucCoreB, 0 ); argStream.ReadNumber ( ucCoronaR, ucCoreR ); argStream.ReadNumber ( ucCoronaG, ucCoreG ); argStream.ReadNumber ( ucCoronaB, ucCoreB ); if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::SetSunColor ( ucCoreR, ucCoreG, ucCoreB, ucCoronaR, ucCoronaG, ucCoronaB ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogBadType ( luaVM ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetBrowserVolume ( lua_State* luaVM ) { // bool setBrowserVolume ( float volume ) // bool setBrowserVolume ( browser webBrowser, float volume ) CClientWebBrowser* pWebBrowser; float fVolume; CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsNumber () ) { argStream.ReadNumber ( fVolume ); lua_pushboolean ( luaVM, g_pCore->GetWebCore ()->SetGlobalAudioVolume ( fVolume ) ); return 1; } argStream.ReadUserData ( pWebBrowser ); argStream.ReadNumber ( fVolume ); if ( !argStream.HasErrors () ) { lua_pushboolean ( luaVM, pWebBrowser->SetAudioVolume ( fVolume ) ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetTok ( lua_State* luaVM ) { SString strInput = ""; unsigned int uiToken = 0; unsigned int uiDelimiter = 0; SString strDelimiter; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strInput ); argStream.ReadNumber ( uiToken ); 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 () ) { if ( uiToken > 0 && uiToken < 1024 ) { unsigned int uiCount = 1; char* szText = new char[strInput.length () + 1]; strcpy ( szText, strInput ); char* szToken = strtok ( szText, strDelimiter ); // We're looking for the first part? if ( uiToken != 1 ) { // strtok count number of times do { uiCount++; szToken = strtok ( NULL, strDelimiter ); } while ( uiCount != uiToken ); } // Found it? if ( szToken ) { // Return it lua_pushstring ( luaVM, szToken ); delete[] szText; return 1; } // Delete the text delete[] szText; } else m_pScriptDebugging->LogWarning ( luaVM, "Token parameter sent to split must be greater than 0 and smaller than 1024" ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaWorldDefs::setHeatHaze ( lua_State* luaVM ) { CScriptArgReader argStream ( luaVM ); // Set the new heat haze settings SHeatHazeSettings heatHaze; argStream.ReadNumber ( heatHaze.ucIntensity ); argStream.ReadNumber ( heatHaze.ucRandomShift, 0 ); argStream.ReadNumber ( heatHaze.usSpeedMin, 12 ); argStream.ReadNumber ( heatHaze.usSpeedMax, 18 ); argStream.ReadNumber ( heatHaze.sScanSizeX, 75 ); argStream.ReadNumber ( heatHaze.sScanSizeY, 80 ); argStream.ReadNumber ( heatHaze.usRenderSizeX, 80 ); argStream.ReadNumber ( heatHaze.usRenderSizeY, 85 ); argStream.ReadBool ( heatHaze.bInsideBuilding, false ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetHeatHaze ( heatHaze ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogBadType ( luaVM ); // Return false lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::InterpolateBetween ( lua_State* luaVM ) { // float float float interpolateBetween ( float x1, float y1, float z1, // float x2, float y2, float z2, // float fProgress, string strEasingType, // [ float fEasingPeriod, float fEasingAmplitude, float fEasingOvershoot ] ) CVector vecPointA; CVector vecPointB; float fProgress; CEasingCurve::eType easingType; float fEasingPeriod; float fEasingAmplitude; float fEasingOvershoot; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPointA ); argStream.ReadVector3D ( vecPointB ); 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; } CVector vecResult = TInterpolation < CVector >::Interpolate ( vecPointA, vecPointB, fProgress, easingType, fEasingPeriod, fEasingAmplitude, fEasingOvershoot ); lua_pushnumber ( luaVM, vecResult.fX ); lua_pushnumber ( luaVM, vecResult.fY ); lua_pushnumber ( luaVM, vecResult.fZ ); return 3; }
int CLuaPointLightDefs::SetLightColor ( lua_State* luaVM ) { // bool setLightColor ( light theLight, float r, float g, float b ) CClientPointLights* pLight; float fRed; float fGreen; float fBlue; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); argStream.ReadNumber ( fRed ); argStream.ReadNumber ( fGreen ); argStream.ReadNumber ( fBlue ); if ( !argStream.HasErrors () ) { SColorRGBA color ( fRed, fGreen, fBlue, 0 ); if ( CStaticFunctionDefinitions::SetLightColor ( pLight, color ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWeaponProperty ( lua_State* luaVM ) { CClientWeapon * pWeapon; eWeaponProperty weaponProperty; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWeapon ); argStream.ReadEnumString ( weaponProperty ); if ( !argStream.HasErrors () ) { if ( weaponProperty == WEAPON_DAMAGE ) { short sData = 0; argStream.ReadNumber( sData ); if ( !argStream.HasErrors( ) ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, sData ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else if ( weaponProperty == WEAPON_FIRE_ROTATION ) { CVector vecRotation; argStream.ReadVector3D ( vecRotation ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, vecRotation ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else { float fData = 0.0f; argStream.ReadNumber( fData ); if ( !argStream.HasErrors( ) ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, fData ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaVector2Defs::Create ( lua_State* luaVM ) { CVector2D vector; CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsTable () ) { lua_pushvalue ( luaVM, 1 ); lua_pushstring ( luaVM, "x" ); lua_rawget ( luaVM, -2 ); if ( lua_isnumber ( luaVM, -1 ) ) { vector.fX = ( float ) lua_tonumber ( luaVM, -1 ); lua_pop ( luaVM, 1 ); } else { lua_pop ( luaVM, 1 ); lua_rawgeti ( luaVM, -1, 1 ); if ( lua_isnumber ( luaVM, -1 ) ) vector.fX = ( float ) lua_tonumber ( luaVM, -1 ); lua_pop ( luaVM, 1 ); } lua_pushstring ( luaVM, "y" ); lua_rawget ( luaVM, -2 ); if ( lua_isnumber ( luaVM, -1 ) ) { vector.fY = ( float ) lua_tonumber ( luaVM, -1 ); lua_pop ( luaVM, 1 ); } else { lua_pop ( luaVM, 1 ); lua_rawgeti ( luaVM, -1, 2 ); if ( lua_isnumber ( luaVM, -1 ) ) vector.fY = ( float ) lua_tonumber ( luaVM, -1 ); lua_pop ( luaVM, 1 ); } } else if ( argStream.NextIsNumber () ) { argStream.ReadNumber ( vector.fX ); if ( argStream.NextIsNumber () ) { argStream.ReadNumber ( vector.fY ); } } else if ( argStream.NextIsVector2D () ) { argStream.ReadVector2D ( vector ); } lua_pushvector ( luaVM, vector ); 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 CLuaFunctionDefs::SetWeaponTarget ( lua_State* luaVM ) { CClientWeapon * pWeapon; CClientEntity * pTarget; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWeapon ); if ( argStream.NextIsUserData() ) { int targetBone; argStream.ReadUserData ( pTarget ); argStream.ReadNumber ( targetBone, 255 ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponTarget ( pWeapon, pTarget, targetBone ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else if ( argStream.NextIsNumber() ) { CVector vecTarget; argStream.ReadNumber( vecTarget.fX ); argStream.ReadNumber( vecTarget.fY ); argStream.ReadNumber( vecTarget.fZ ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponTarget ( pWeapon, vecTarget ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else if ( argStream.NextIsNil() ) { if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::ClearWeaponTarget ( pWeapon ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else argStream.SetCustomError( "Expected element, number or nil at argument 2" ); if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWeaponAmmo ( lua_State* luaVM ) { // bool setWeaponAmmo ( player thePlayer, int weapon, int totalAmmo, [int ammoInClip = 0] ) CElement* pElement; eWeaponType weaponType; ushort usAmmo; ushort usAmmoInClip; CCustomWeapon * pWeapon = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pElement ); if ( !argStream.HasErrors () ) { if ( pElement->GetType () != CElement::WEAPON ) { argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadNumber ( usAmmo ); argStream.ReadNumber ( usAmmoInClip, 0 ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponAmmo ( pElement, weaponType, usAmmo, usAmmoInClip ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else { pWeapon = static_cast <CCustomWeapon *> ( pElement ); argStream.ReadNumber ( usAmmo ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponAmmo ( pWeapon, usAmmo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaVector4Defs::Mul ( lua_State* luaVM ) { CScriptArgReader argStream ( luaVM ); CLuaVector4D* pVector1 = NULL; if ( argStream.NextIsNumber ( ) ) { // number * vector4 float fValue = 0.0f; argStream.ReadNumber ( fValue ); argStream.ReadUserData ( pVector1 ); if ( !argStream.HasErrors ( ) ) { lua_pushvector ( luaVM, *pVector1 * fValue ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) ); } else { // vector4 * ? argStream.ReadUserData ( pVector1 ); if ( argStream.NextIsNumber ( ) ) { float fValue = 0.0f; argStream.ReadNumber ( fValue ); if ( !argStream.HasErrors ( ) ) { lua_pushvector ( luaVM, *pVector1 * fValue ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) ); } else { CLuaVector4D* pVector2 = NULL; argStream.ReadUserData ( pVector2 ); if ( !argStream.HasErrors ( ) ) { lua_pushvector ( luaVM, *pVector1 * *pVector2 ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) ); } } lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::OutputDebugString ( lua_State* luaVM ) { SString strMessage; unsigned int uiLevel; unsigned char ucR, ucG, ucB; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strMessage ); argStream.ReadNumber ( uiLevel, 3 ); if ( uiLevel == 0 ) { argStream.ReadNumber ( ucR, 0xFF ); argStream.ReadNumber ( ucG, 0xFF ); argStream.ReadNumber ( ucB, 0xFF ); } if ( !argStream.HasErrors () ) { if ( uiLevel > 3 ) { m_pScriptDebugging->LogWarning ( luaVM, "Bad level argument sent to %s (0-3)", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ) ); lua_pushboolean ( luaVM, false ); return 1; } if ( uiLevel == 1 ) { m_pScriptDebugging->LogError ( luaVM, "%s", strMessage.c_str () ); } else if ( uiLevel == 2 ) { m_pScriptDebugging->LogWarning ( luaVM, "%s", strMessage.c_str () ); } else if ( uiLevel == 3 ) { m_pScriptDebugging->LogInformation ( luaVM, "%s", strMessage.c_str () ); } else if ( uiLevel == 0 ) { m_pScriptDebugging->LogCustom ( luaVM, ucR, ucG, ucB, "%s", strMessage.c_str () ); } lua_pushboolean ( luaVM, true ); 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 CLuaFunctionDefs::MoveObject ( lua_State* luaVM ) { // bool moveObject ( object theObject, int time, float targetx, float targety, float targetz, // [ float moverx, float movery, float moverz, string strEasingType, float fEasingPeriod, float fEasingAmplitude, float fEasingOvershoot ] ) CClientEntity* pEntity; int iTime; CVector vecTargetPosition; CVector vecTargetRotation; CEasingCurve::eType easingType; float fEasingPeriod; float fEasingAmplitude; float fEasingOvershoot; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pEntity ); argStream.ReadNumber ( iTime ); argStream.ReadNumber ( vecTargetPosition.fX ); argStream.ReadNumber ( vecTargetPosition.fY ); argStream.ReadNumber ( vecTargetPosition.fZ ); argStream.ReadNumber ( vecTargetRotation.fX, 0 ); argStream.ReadNumber ( vecTargetRotation.fY, 0 ); argStream.ReadNumber ( vecTargetRotation.fZ, 0 ); argStream.ReadEnumString ( easingType, CEasingCurve::Linear ); argStream.ReadNumber ( fEasingPeriod, 0.3f ); argStream.ReadNumber ( fEasingAmplitude, 1.0f ); argStream.ReadNumber ( fEasingOvershoot, 1.70158f ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::MoveObject ( *pEntity, iTime, vecTargetPosition, vecTargetRotation, easingType, fEasingPeriod, fEasingAmplitude, fEasingOvershoot ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::CreateObject ( lua_State* luaVM ) { // object createObject ( int modelid, float x, float y, float z, [float rx, float ry, float rz, bool lowLOD] ) ushort usModelID; CVector vecPosition; CVector vecRotation; bool bLowLod; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( usModelID ); argStream.ReadNumber ( vecPosition.fX ); argStream.ReadNumber ( vecPosition.fY ); argStream.ReadNumber ( vecPosition.fZ ); argStream.ReadNumber ( vecRotation.fX, 0 ); argStream.ReadNumber ( vecRotation.fY, 0 ); argStream.ReadNumber ( vecRotation.fZ, 0 ); argStream.ReadBool ( bLowLod, false ); if ( !argStream.HasErrors () ) { if ( CClientObjectManager::IsValidModel ( usModelID ) ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource (); if ( pResource ) { CClientObject* pObject = CStaticFunctionDefinitions::CreateObject ( *pResource, usModelID, vecPosition, vecRotation, bLowLod ); if ( pObject ) { CElementGroup * pGroup = pResource->GetElementGroup(); if ( pGroup ) { pGroup->Add ( ( CClientEntity* ) pObject ); } lua_pushelement ( luaVM, pObject ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "createObject", "Invalid model id" ) ); } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "createObject", *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::IsObjectBreakable ( lua_State* luaVM ) { // bool isObjectBreakable ( int modelId ) CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsNumber () ) { unsigned short usModel; argStream.ReadNumber ( usModel ); lua_pushboolean ( luaVM, CClientObjectManager::IsBreakableModel ( usModel ) ); return 1; } // bool isObjectBreakable ( object theObject ) CClientObject* pObject; argStream.ReadUserData ( pObject ); if ( !argStream.HasErrors () ) { bool bBreakable; if ( CStaticFunctionDefinitions::IsObjectBreakable ( *pObject, bBreakable ) ) { lua_pushboolean ( luaVM, bBreakable ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaOOPDefs::DxGetFontHeight ( lua_State* luaVM ) { // int dxGetFontHeight ( [float scale=1, mixed font="default"] ) float fScale; CClientDxFont* pDxFontElement; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pDxFontElement ); argStream.ReadNumber ( fScale, 1 ); if ( !argStream.HasErrors () ) { ID3DXFont* pD3DXFont = CStaticFunctionDefinitions::ResolveD3DXFont ( FONT_DEFAULT, pDxFontElement ); float fHeight = g_pCore->GetGraphics ()->GetDXFontHeight ( fScale, pD3DXFont ); // Success lua_pushnumber ( luaVM, fHeight ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetAnalogControlState ( lua_State * luaVM ) { // bool setAnalogControlState ( string controlName [, float state] ) SString strControlState = ""; float fState = 0.0f; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strControlState ); if ( !argStream.HasErrors () ) { if ( argStream.NextIsNumber ( ) ) { argStream.ReadNumber ( fState ); if ( CClientPad::SetAnalogControlState ( strControlState , fState ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else if ( argStream.NextIsNone ( ) ) { CClientPad::RemoveSetAnalogControlState ( strControlState ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogBadType ( luaVM ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::CreateFire ( lua_State* luaVM ) { CVector vecPosition; float fSize; CElement* pCreator; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPosition ); argStream.ReadNumber ( fSize, 1.8f ); argStream.ReadUserData ( pCreator, NULL ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::CreateFire ( vecPosition, fSize, pCreator ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaTextDefs::textItemSetPriority ( lua_State* luaVM ) { CTextItem * pTextItem; int iPriority; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pTextItem ); if ( argStream.NextIsString( ) ) { SString strPriority; argStream.ReadString ( strPriority ); if ( strPriority == "high" ) iPriority = PRIORITY_HIGH; else if ( strPriority == "medium" ) iPriority = PRIORITY_MEDIUM; else iPriority = PRIORITY_LOW; } else { argStream.ReadNumber(iPriority); } if ( !argStream.HasErrors ( ) ) { pTextItem->SetPriority ( (eTextPriority)iPriority ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::PlaySoundFrontEnd ( lua_State* luaVM ) { CClientSound* pSound = NULL; CVector vecPosition; unsigned char ucSound = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( ucSound ); if ( !argStream.HasErrors() ) { if ( ucSound <= 101 ) { if ( CStaticFunctionDefinitions::PlaySoundFrontEnd ( ucSound ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogError ( luaVM, "Invalid sound ID specified. Valid sound IDs are 0 - 101." ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetCameraMatrix ( lua_State* luaVM ) { CVector vecPosition; CVector vecLookAt; float fRoll = 0.0f; float fFOV = 70.0f; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPosition ); argStream.ReadVector3D ( vecLookAt, CVector() ); argStream.ReadNumber ( fRoll, 0.0f ); argStream.ReadNumber ( fFOV, 70.0f ); if ( fFOV <= 0.0f || fFOV >= 180.0f ) fFOV = 70.0f; if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::SetCameraMatrix ( vecPosition, vecLookAt, fRoll, fFOV ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaEngineDefs::EngineGetModelNameFromID ( lua_State* luaVM ) { // string engineGetModelNameFromID ( int modelID ) int iModelID; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( iModelID ); if ( !argStream.HasErrors () ) { SString strModelName = CModelNames::GetModelName ( iModelID ); if ( !strModelName.empty () ) { lua_pushstring ( luaVM, strModelName ); return 1; } argStream.SetCustomError( "Expected valid model ID at argument 1" ); } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // We failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaEngineDefs::EngineSetModelLODDistance ( lua_State* luaVM ) { SString strModel = ""; float fDistance = 0.0; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strModel ); argStream.ReadNumber ( fDistance ); if ( !argStream.HasErrors () ) { unsigned short usModelID = CModelNames::ResolveModelID ( strModel ); CModelInfo* pModelInfo = g_pGame->GetModelInfo ( usModelID ); if ( pModelInfo && fDistance > 0.0f ) { pModelInfo->SetLODDistance ( fDistance ); lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetSoundWaveData ( lua_State* luaVM ) { CClientSound* pSound = NULL; CClientPlayer* pPlayer = NULL; float* pData = NULL; int iLength = 0; 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 1; } argStream.ReadNumber ( iLength ); if ( !argStream.HasErrors () ) { if ( pSound != NULL ) { pData = CStaticFunctionDefinitions::GetSoundWaveData ( *pSound, iLength ); } else if ( pPlayer != NULL ) { pData = CStaticFunctionDefinitions::GetSoundWaveData ( *pPlayer, iLength ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "sound/player", 1 ); lua_pushboolean ( luaVM, false ); return 1; } if ( pData != NULL ) { // Create a new table lua_newtable ( luaVM ); for (int i = 0; i < iLength;i++) { lua_pushnumber ( luaVM, i ); lua_pushnumber ( luaVM, pData[i] ); lua_settable ( luaVM, -3 ); } // Deallocate our data array here after it's used. delete [] pData; return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaXMLDefs::xmlNodeFindChild ( lua_State* luaVM ) { CXMLNode* pNode; SString strTagName; unsigned int uiIndex; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); argStream.ReadString ( strTagName ); argStream.ReadNumber ( uiIndex ); if ( !argStream.HasErrors () ) { CXMLNode * pFoundNode = pNode->FindSubNode ( strTagName, uiIndex ); if ( pFoundNode ) { lua_pushxmlnode ( luaVM, pFoundNode ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFileDefs::fileSetPos ( lua_State* luaVM ) { // int fileSetPos ( file theFile, int offset ) CScriptFile* pFile; long lPosition; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( lPosition ); if ( !argStream.HasErrors () ) { if ( lPosition >= 0 ) { long lResultPosition = pFile->SetPointer ( static_cast < unsigned long > ( lPosition ) ); if ( lResultPosition != -1 ) { // Set the position and return where we actually got it put lua_pushnumber ( luaVM, lResultPosition ); return 1; } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } } else m_pScriptDebugging->LogCustom ( luaVM, "Bad file position" ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaEngineDefs::EngineReplaceCOL ( lua_State* luaVM ) { CClientColModel* pCol = NULL; unsigned short usModel = 0; CScriptArgReader argStream ( luaVM ); // Grab the COL and model ID argStream.ReadUserData ( pCol ); argStream.ReadNumber ( usModel ); if ( !argStream.HasErrors ( ) ) { // Valid client DFF and model? if ( CClientColModelManager::IsReplacableModel ( usModel ) ) { // Replace the colmodel if ( pCol->Replace ( usModel ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogBadPointer ( luaVM, "number", 2 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetSoundMaxDistance ( lua_State* luaVM ) { CClientSound* pSound = NULL; float fDistance = 0.0f; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pSound ); argStream.ReadNumber ( fDistance ); if ( !argStream.HasErrors () ) { if ( pSound ) { if ( CStaticFunctionDefinitions::SetSoundMaxDistance ( *pSound, fDistance ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }