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::GetObjectScale ( lua_State* luaVM ) { // float getObjectScale ( object theObject ) CClientObject* pObject; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pObject ); if ( !argStream.HasErrors () ) { float fScale; if ( CStaticFunctionDefinitions::GetObjectScale ( *pObject, fScale ) ) { lua_pushnumber ( luaVM, fScale ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "getObjectScale", *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetObjectScale ( lua_State* luaVM ) { // bool setObjectScale ( object theObject, float scale ) CClientEntity* pEntity; float fScale; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pEntity ); argStream.ReadNumber ( fScale ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetObjectScale ( *pEntity, fScale ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "setObjectScale", *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetObjectStatic ( lua_State* luaVM ) { // bool setObjectStatic ( object theObject, bool toggle ) CClientEntity* pEntity; bool bStatic; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pEntity ); argStream.ReadBool ( bStatic ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetObjectStatic ( *pEntity, bStatic ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "setObjectStatic", *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::RemoveEventHandler ( lua_State* luaVM ) { // bool removeEventHandler ( string eventName, element attachedTo, function functionVar ) SString strName; CClientEntity* pEntity; CLuaFunctionRef iLuaFunction; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pEntity ); argStream.ReadFunction ( iLuaFunction ); argStream.ReadFunctionComplete (); if ( !argStream.HasErrors () ) { // Grab our virtual machine CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Do it if ( CStaticFunctionDefinitions::RemoveEventHandler ( *pLuaMain, strName, *pEntity, iLuaFunction ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "removeEventHandler", *argStream.GetErrorMessage () ) ); // Failed 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, SString ( "Bad argument @ '%s' [%s]", "moveObject", *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::AddEvent ( lua_State* luaVM ) { // bool addEvent ( string eventName [, bool allowRemoteTrigger = false ] ) SString strName; bool bAllowRemoteTrigger; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadBool ( bAllowRemoteTrigger, false ); if ( !argStream.HasErrors () ) { // Grab our virtual machine CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Do it if ( CStaticFunctionDefinitions::AddEvent ( *pLuaMain, strName, bAllowRemoteTrigger ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "addEvent", *argStream.GetErrorMessage () ) ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::AddEventHandler ( lua_State* luaVM ) { // bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [bool getPropagated = true] ) SString strName; CClientEntity* pEntity; CLuaFunctionRef iLuaFunction; bool bPropagated; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pEntity ); argStream.ReadFunction ( iLuaFunction ); argStream.ReadBool ( bPropagated, true ); argStream.ReadFunctionComplete (); if ( !argStream.HasErrors () ) { // Grab our virtual machine CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Check if the handle is in use if ( pEntity->GetEventManager()->HandleExists ( pLuaMain, strName, iLuaFunction ) ) { m_pScriptDebugging->LogCustom ( luaVM, 255, 0, 0, "addEventHandler: '%s' with this function is already handled", *strName ); lua_pushboolean ( luaVM, false ); return 1; } // Do it if ( CStaticFunctionDefinitions::AddEventHandler ( *pLuaMain, strName, *pEntity, iLuaFunction, bPropagated ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "addEventHandler", *argStream.GetErrorMessage () ) ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::TriggerEvent ( lua_State* luaVM ) { // bool triggerEvent ( string eventName, element baseElement, [ var argument1, ... ] ) SString strName; CClientEntity* pEntity; CLuaArguments Arguments; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pEntity ); argStream.ReadLuaArguments ( Arguments ); if ( !argStream.HasErrors () ) { // Trigger it bool bWasCancelled; if ( CStaticFunctionDefinitions::TriggerEvent ( strName, *pEntity, Arguments, bWasCancelled ) ) { lua_pushboolean ( luaVM, !bWasCancelled ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "triggerEvent", *argStream.GetErrorMessage () ) ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFunctionDefs::TriggerServerEvent ( lua_State* luaVM ) { // bool triggerServerEvent ( string event, element theElement, [arguments...] ) SString strName; CClientEntity* pCallWithEntity; CLuaArguments Arguments; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pCallWithEntity ); argStream.ReadLuaArguments ( Arguments ); if ( !argStream.HasErrors () ) { // Trigger it if ( CStaticFunctionDefinitions::TriggerServerEvent ( strName, *pCallWithEntity, Arguments ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "triggerServerEvent", *argStream.GetErrorMessage () ) ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPointLightDefs::GetLightType ( lua_State* luaVM ) { // int getLightType ( light theLight ) CClientPointLights* pLight; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); if ( !argStream.HasErrors () ) { int iMode; if ( CStaticFunctionDefinitions::GetLightType ( pLight, iMode ) ) { lua_pushnumber ( luaVM, static_cast < lua_Number > ( iMode ) ); 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 CLuaPointLightDefs::CreateLight ( lua_State* luaVM ) { // light createLight ( int lightType, float posX, float posY, float posX, [ float radius = 3, int r = 255, int g = 0, int b = 0, float dirX = 0, float dirY = 0, float dirZ = 0, bool createsShadow = false ] ) int iMode; CVector vecPosition; float fRadius; SColor color; CVector vecDirection; bool bCreatesShadow; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( iMode ); argStream.ReadVector3D ( vecPosition ); argStream.ReadNumber ( fRadius, 3.0f ); argStream.ReadNumber ( color.R, 255 ); argStream.ReadNumber ( color.G, 0 ); argStream.ReadNumber ( color.B, 0 ); argStream.ReadVector3D ( vecDirection, vecDirection ); argStream.ReadBool ( bCreatesShadow, false ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); CResource* pResource = pLuaMain ? pLuaMain->GetResource () : NULL; if ( pResource ) { // Create it CClientPointLights* pLight = CStaticFunctionDefinitions::CreateLight ( *pResource, iMode, vecPosition, fRadius, color, vecDirection ); if ( pLight ) { CElementGroup * pGroup = pResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( (CClientEntity*) pLight ); } lua_pushelement ( luaVM, pLight ); 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 CLuaPointLightDefs::SetLightDirection ( lua_State* luaVM ) { // bool setLightDirection ( light theLight, float x, float y, float z ) CClientPointLights* pLight; CVector vecDirection; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); argStream.ReadVector3D ( vecDirection ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetLightDirection ( pLight, vecDirection ) ) { 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 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 CLuaPointLightDefs::SetLightRadius ( lua_State* luaVM ) { // bool setLightRadius ( Light theLight, float radius ) CClientPointLights* pLight; float fRadius; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); argStream.ReadNumber ( fRadius ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetLightRadius ( pLight, fRadius ) ) { 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; }