From 700f55165c8d6e91f08793cbb5e2350a49bacb65 Mon Sep 17 00:00:00 2001 From: Flobu Date: Tue, 30 Mar 2010 02:43:40 +0200 Subject: [PATCH] Added 5267: ([Request and Patch] serverside set/getElementRotation) fixed set/get ped rotation clientside --- .../logic/CStaticFunctionDefinitions.cpp | 4 +- MTA10/mods/shared_logic/CClientPed.cpp | 11 ++- .../lua/CLuaFunctionDefs.Element.cpp | 2 +- .../logic/CStaticFunctionDefinitions.cpp | 71 ++++++++++++++++++ .../logic/CStaticFunctionDefinitions.h | 2 + .../logic/luadefs/CLuaElementDefs.cpp | 75 +++++++++++++++++++ .../logic/luadefs/CLuaElementDefs.h | 2 + 7 files changed, 159 insertions(+), 8 deletions(-) diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index b6d23199bf..7d0538ceb0 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -302,12 +302,14 @@ bool CStaticFunctionDefinitions::GetElementRotation ( CClientEntity& Entity, CVe // Correct the rotation vecRotation.fZ = 0.0f - vecRotation.fZ; + if ( vecRotation.fZ < 0 ) + vecRotation.fZ = vecRotation.fZ + 360; break; } case CCLIENTVEHICLE: { CClientVehicle& Vehicle = static_cast < CClientVehicle& > ( Entity ); - Vehicle.GetRotationDegrees ( vecRotation ); + Vehicle.GetRotationDegrees ( vecRotation ); break; } case CCLIENTOBJECT: diff --git a/MTA10/mods/shared_logic/CClientPed.cpp b/MTA10/mods/shared_logic/CClientPed.cpp index 26be23d5a2..ee598e2d05 100644 --- a/MTA10/mods/shared_logic/CClientPed.cpp +++ b/MTA10/mods/shared_logic/CClientPed.cpp @@ -543,13 +543,12 @@ void CClientPed::GetRotationRadians ( CVector& vecRotation ) const void CClientPed::SetRotationDegrees ( const CVector& vecRotation ) { // Convert from degrees to radians - CVector vecTemp; - vecTemp.fX = vecRotation.fX * 3.1415926535897932384626433832795f / 180.0f; - vecTemp.fY = vecRotation.fY * 3.1415926535897932384626433832795f / 180.0f; - vecTemp.fZ = vecRotation.fZ * 3.1415926535897932384626433832795f / 180.0f; + float fTempRotation = vecRotation.fZ * 3.1415926535897932384626433832795f / 180.0f; - // Set the rotation as radians - SetRotationRadians ( vecTemp ); + // Set the rotation + SetCurrentRotation ( fTempRotation ); + if ( !IS_PLAYER ( this ) ) + SetCameraRotation ( fTempRotation ); } diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp index 8248fd0cb0..ce2aea3e88 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp @@ -298,7 +298,7 @@ int CLuaFunctionDefs::GetElementRotation ( lua_State* luaVM ) CClientEntity* pEntity = lua_toelement ( luaVM, 1 ); if ( pEntity ) { - // Grab the position + // Grab the rotation CVector vecRotation; if ( CStaticFunctionDefinitions::GetElementRotation ( *pEntity, vecRotation ) ) { diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index f7afb2fb6c..04519bad0d 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -947,6 +947,43 @@ bool CStaticFunctionDefinitions::GetElementPosition ( CElement* pElement, CVecto } +bool CStaticFunctionDefinitions::GetElementRotation ( CElement* pElement, CVector& vecRotation ) +{ + assert ( pElement ); + + int iType = pElement->GetType (); + switch ( iType ) + { + case CElement::PED: + case CElement::PLAYER: + { + CPed* pPed = static_cast < CPed* > ( pElement ); + vecRotation.fZ = ConvertRadiansToDegrees ( pPed->GetRotation () ); + + break; + } + case CElement::VEHICLE: + { + CVehicle* pVehicle = static_cast < CVehicle* > ( pElement ); + pVehicle->GetRotationDegrees ( vecRotation ); + + break; + } + case CElement::OBJECT: + { + CObject* pObject = static_cast < CObject* > ( pElement ); + pObject->GetRotation ( vecRotation ); + ConvertRadiansToDegrees ( vecRotation ); + + break; + } + default: return false; + } + + return true; +} + + bool CStaticFunctionDefinitions::GetElementVelocity ( CElement* pElement, CVector& vecVelocity ) { assert ( pElement ); @@ -1015,6 +1052,40 @@ bool CStaticFunctionDefinitions::SetElementPosition ( CElement* pElement, const } +bool CStaticFunctionDefinitions::SetElementRotation ( CElement* pElement, const CVector& vecRotation ) +{ + assert ( pElement ); + + int iType = pElement->GetType (); + switch ( iType ) + { + case CElement::PED: + case CElement::PLAYER: + { + CPed* pPed = static_cast < CPed* > ( pElement ); + SetPedRotation( pPed, vecRotation.fZ ); + + break; + } + case CElement::VEHICLE: + { + CVehicle* pVehicle = static_cast < CVehicle* > ( pElement ); + SetVehicleRotation( pVehicle, vecRotation ); + + break; + } + case CElement::OBJECT: + { + CObject* pObject = static_cast < CObject* > ( pElement ); + SetObjectRotation( pObject, vecRotation ); + } + default: return false; + } + + return true; +} + + bool CStaticFunctionDefinitions::SetElementVelocity ( CElement* pElement, const CVector& vecVelocity ) { assert ( pElement ); diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 2f21e29e48..14d23fa8ba 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -59,6 +59,7 @@ class CStaticFunctionDefinitions static CLuaArguments* GetAllElementData ( CElement* pElement, CLuaArguments * table ); static CElement* GetElementParent ( CElement* pElement ); static bool GetElementPosition ( CElement* pElement, CVector& vecPosition ); + static bool GetElementRotation ( CElement* pElement, CVector& vecRotation ); static bool GetElementVelocity ( CElement* pElement, CVector& vecVelocity ); static bool GetElementInterior ( CElement* pElement, unsigned char& ucInterior ); static bool IsElementWithinColShape ( CElement* pElement, CColShape* pColShape, bool& bWithin ); @@ -80,6 +81,7 @@ class CStaticFunctionDefinitions static bool RemoveElementData ( CElement* pElement, const char* szName ); static bool SetElementParent ( CElement* pElement, CElement* pParent ); static bool SetElementPosition ( CElement* pElement, const CVector& vecPosition, bool bWarp = true ); + static bool SetElementRotation ( CElement* pElement, const CVector& vecRotation ); static bool SetElementVelocity ( CElement* pElement, const CVector& vecVelocity ); static bool SetElementVisibleTo ( CElement* pElement, CElement* pReference, bool bVisible ); static bool SetElementInterior ( CElement* pElement, unsigned char ucInterior, bool bSetPosition, CVector& vecPosition ); diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index a85454b03a..f35c927b1c 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -43,6 +43,7 @@ void CLuaElementDefs::LoadFunctions ( void ) CLuaCFunctions::AddFunction ( "getElementID", CLuaElementDefs::getElementID ); CLuaCFunctions::AddFunction ( "getElementParent", CLuaElementDefs::getElementParent ); CLuaCFunctions::AddFunction ( "getElementPosition", CLuaElementDefs::getElementPosition ); + CLuaCFunctions::AddFunction ( "getElementRotation", CLuaElementDefs::getElementRotation ); CLuaCFunctions::AddFunction ( "getElementVelocity", CLuaElementDefs::getElementVelocity ); CLuaCFunctions::AddFunction ( "getElementsByType", CLuaElementDefs::getElementsByType ); CLuaCFunctions::AddFunction ( "getElementType", CLuaElementDefs::getElementType ); @@ -73,6 +74,7 @@ void CLuaElementDefs::LoadFunctions ( void ) CLuaCFunctions::AddFunction ( "setElementID", CLuaElementDefs::setElementID ); CLuaCFunctions::AddFunction ( "setElementParent", CLuaElementDefs::setElementParent ); CLuaCFunctions::AddFunction ( "setElementPosition", CLuaElementDefs::setElementPosition ); + CLuaCFunctions::AddFunction ( "setElementRotation", CLuaElementDefs::setElementRotation ); CLuaCFunctions::AddFunction ( "setElementVelocity", CLuaElementDefs::setElementVelocity ); CLuaCFunctions::AddFunction ( "setElementVisibleTo", CLuaElementDefs::setElementVisibleTo ); CLuaCFunctions::AddFunction ( "clearElementVisibleTo", CLuaElementDefs::clearElementVisibleTo ); @@ -512,6 +514,38 @@ int CLuaElementDefs::getElementPosition ( lua_State* luaVM ) } +int CLuaElementDefs::getElementRotation ( lua_State* luaVM ) +{ + // Verify the argument + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA ) + { + // Grab the element, verify it + CElement* pElement = lua_toelement ( luaVM, 1 ); + if ( pElement ) + { + // Grab the rotation + CVector vecRotation; + if ( CStaticFunctionDefinitions::GetElementRotation ( pElement, vecRotation ) ) + { + // Return it + lua_pushnumber ( luaVM, vecRotation.fX ); + lua_pushnumber ( luaVM, vecRotation.fY ); + lua_pushnumber ( luaVM, vecRotation.fZ ); + return 3; + } + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "getElementRotation", "element", 1 ); + } + else + m_pScriptDebugging->LogBadType ( luaVM, "getElementRotation" ); + + lua_pushboolean ( luaVM, false ); + return 1; +} + + + int CLuaElementDefs::getElementVelocity ( lua_State* luaVM ) { // Verify the argument @@ -1346,6 +1380,47 @@ int CLuaElementDefs::setElementPosition ( lua_State* luaVM ) } +int CLuaElementDefs::setElementRotation ( lua_State* luaVM ) +{ + // Verify the first argument + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA ) + { + // Grab the element and verify it + CElement* pElement = lua_toelement ( luaVM, 1 ); + if ( pElement ) + { + int iArgument2 = lua_type ( luaVM, 2 ); + int iArgument3 = lua_type ( luaVM, 3 ); + int iArgument4 = lua_type ( luaVM, 4 ); + if ( ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) && + ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) && + ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) ) + { + // Grab the rotation + CVector vecRotation = CVector ( static_cast < float > ( lua_tonumber ( luaVM, 2 ) ), + static_cast < float > ( lua_tonumber ( luaVM, 3 ) ), + static_cast < float > ( lua_tonumber ( luaVM, 4 ) ) ); + // Set the rotation + if ( CStaticFunctionDefinitions::SetElementRotation ( pElement, vecRotation ) ) + { + lua_pushboolean ( luaVM, true ); + return 1; + } + } + else + m_pScriptDebugging->LogBadType ( luaVM, "setElementRotation" ); + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "setElementRotation", "element", 1 ); + } + else + m_pScriptDebugging->LogBadType ( luaVM, "setElementRotation" ); + + lua_pushboolean ( luaVM, false ); + return 1; +} + + int CLuaElementDefs::setElementVelocity ( lua_State* luaVM ) { // Verify the first argument diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index 9cbf5d1c2b..c04c67dac9 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -41,6 +41,7 @@ class CLuaElementDefs: public CLuaDefs static int getAllElementData ( lua_State* luaVM ); static int getElementParent ( lua_State* luaVM ); static int getElementPosition ( lua_State* luaVM ); + static int getElementRotation ( lua_State* luaVM ); static int getElementVelocity ( lua_State* luaVM ); static int getElementType ( lua_State* luaVM ); static int getElementsByType ( lua_State* luaVM ); @@ -77,6 +78,7 @@ class CLuaElementDefs: public CLuaDefs static int setElementID ( lua_State* luaVM ); static int setElementParent ( lua_State* luaVM ); static int setElementPosition ( lua_State* luaVM ); + static int setElementRotation ( lua_State* luaVM ); static int setElementVelocity ( lua_State* luaVM ); static int setElementInterior ( lua_State* luaVM ); static int setElementDimension ( lua_State* luaVM );