Skip to content

Commit

Permalink
Added 5267: ([Request and Patch] serverside set/getElementRotation)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flobu committed Apr 24, 2010
1 parent 55dc212 commit b8b2d96
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 3 deletions.
7 changes: 5 additions & 2 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -301,13 +301,16 @@ bool CStaticFunctionDefinitions::GetElementRotation ( CClientEntity& Entity, CVe
Ped.GetRotationDegrees ( vecRotation );

// Correct the rotation
vecRotation.fZ = 0.0f - vecRotation.fZ;
vecRotation.fZ = fmod( -vecRotation.fZ, 360);
if ( vecRotation.fZ < 0 )
vecRotation.fZ = 360 + vecRotation.fZ;

break;
}
case CCLIENTVEHICLE:
{
CClientVehicle& Vehicle = static_cast < CClientVehicle& > ( Entity );
Vehicle.GetRotationDegrees ( vecRotation );
Vehicle.GetRotationDegrees ( vecRotation );
break;
}
case CCLIENTOBJECT:
Expand Down
5 changes: 5 additions & 0 deletions MTA10/mods/shared_logic/CClientPed.cpp
Expand Up @@ -550,6 +550,11 @@ void CClientPed::SetRotationDegrees ( const CVector& vecRotation )

// Set the rotation as radians
SetRotationRadians ( vecTemp );

// HACK: set again the z rotation to work on ground
SetCurrentRotation ( vecTemp.fZ );
if ( !IS_PLAYER ( this ) )
SetCameraRotation ( vecTemp.fZ );
}


Expand Down
2 changes: 1 addition & 1 deletion MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp
Expand Up @@ -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 ) )
{
Expand Down
71 changes: 71 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
75 changes: 75 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -513,6 +515,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
Expand Down Expand Up @@ -1347,6 +1381,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
Expand Down
2 changes: 2 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit b8b2d96

Please sign in to comment.