Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45d42cd

Browse files
Flobuccw808
authored andcommitted
Added 5267: ([Request and Patch] serverside set/getElementRotation)
fixed set/get ped rotation clientside
1 parent c90d14f commit 45d42cd

File tree

7 files changed

+159
-8
lines changed

7 files changed

+159
-8
lines changed

MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,14 @@ bool CStaticFunctionDefinitions::GetElementRotation ( CClientEntity& Entity, CVe
302302

303303
// Correct the rotation
304304
vecRotation.fZ = 0.0f - vecRotation.fZ;
305+
if ( vecRotation.fZ < 0 )
306+
vecRotation.fZ = vecRotation.fZ + 360;
305307
break;
306308
}
307309
case CCLIENTVEHICLE:
308310
{
309311
CClientVehicle& Vehicle = static_cast < CClientVehicle& > ( Entity );
310-
Vehicle.GetRotationDegrees ( vecRotation );
312+
Vehicle.GetRotationDegrees ( vecRotation );
311313
break;
312314
}
313315
case CCLIENTOBJECT:

MTA10/mods/shared_logic/CClientPed.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,12 @@ void CClientPed::GetRotationRadians ( CVector& vecRotation ) const
543543
void CClientPed::SetRotationDegrees ( const CVector& vecRotation )
544544
{
545545
// Convert from degrees to radians
546-
CVector vecTemp;
547-
vecTemp.fX = vecRotation.fX * 3.1415926535897932384626433832795f / 180.0f;
548-
vecTemp.fY = vecRotation.fY * 3.1415926535897932384626433832795f / 180.0f;
549-
vecTemp.fZ = vecRotation.fZ * 3.1415926535897932384626433832795f / 180.0f;
546+
float fTempRotation = vecRotation.fZ * 3.1415926535897932384626433832795f / 180.0f;
550547

551-
// Set the rotation as radians
552-
SetRotationRadians ( vecTemp );
548+
// Set the rotation
549+
SetCurrentRotation ( fTempRotation );
550+
if ( !IS_PLAYER ( this ) )
551+
SetCameraRotation ( fTempRotation );
553552
}
554553

555554

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ int CLuaFunctionDefs::GetElementRotation ( lua_State* luaVM )
298298
CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
299299
if ( pEntity )
300300
{
301-
// Grab the position
301+
// Grab the rotation
302302
CVector vecRotation;
303303
if ( CStaticFunctionDefinitions::GetElementRotation ( *pEntity, vecRotation ) )
304304
{

MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,43 @@ bool CStaticFunctionDefinitions::GetElementPosition ( CElement* pElement, CVecto
947947
}
948948

949949

950+
bool CStaticFunctionDefinitions::GetElementRotation ( CElement* pElement, CVector& vecRotation )
951+
{
952+
assert ( pElement );
953+
954+
int iType = pElement->GetType ();
955+
switch ( iType )
956+
{
957+
case CElement::PED:
958+
case CElement::PLAYER:
959+
{
960+
CPed* pPed = static_cast < CPed* > ( pElement );
961+
vecRotation.fZ = ConvertRadiansToDegrees ( pPed->GetRotation () );
962+
963+
break;
964+
}
965+
case CElement::VEHICLE:
966+
{
967+
CVehicle* pVehicle = static_cast < CVehicle* > ( pElement );
968+
pVehicle->GetRotationDegrees ( vecRotation );
969+
970+
break;
971+
}
972+
case CElement::OBJECT:
973+
{
974+
CObject* pObject = static_cast < CObject* > ( pElement );
975+
pObject->GetRotation ( vecRotation );
976+
ConvertRadiansToDegrees ( vecRotation );
977+
978+
break;
979+
}
980+
default: return false;
981+
}
982+
983+
return true;
984+
}
985+
986+
950987
bool CStaticFunctionDefinitions::GetElementVelocity ( CElement* pElement, CVector& vecVelocity )
951988
{
952989
assert ( pElement );
@@ -1015,6 +1052,40 @@ bool CStaticFunctionDefinitions::SetElementPosition ( CElement* pElement, const
10151052
}
10161053

10171054

1055+
bool CStaticFunctionDefinitions::SetElementRotation ( CElement* pElement, const CVector& vecRotation )
1056+
{
1057+
assert ( pElement );
1058+
1059+
int iType = pElement->GetType ();
1060+
switch ( iType )
1061+
{
1062+
case CElement::PED:
1063+
case CElement::PLAYER:
1064+
{
1065+
CPed* pPed = static_cast < CPed* > ( pElement );
1066+
SetPedRotation( pPed, vecRotation.fZ );
1067+
1068+
break;
1069+
}
1070+
case CElement::VEHICLE:
1071+
{
1072+
CVehicle* pVehicle = static_cast < CVehicle* > ( pElement );
1073+
SetVehicleRotation( pVehicle, vecRotation );
1074+
1075+
break;
1076+
}
1077+
case CElement::OBJECT:
1078+
{
1079+
CObject* pObject = static_cast < CObject* > ( pElement );
1080+
SetObjectRotation( pObject, vecRotation );
1081+
}
1082+
default: return false;
1083+
}
1084+
1085+
return true;
1086+
}
1087+
1088+
10181089
bool CStaticFunctionDefinitions::SetElementVelocity ( CElement* pElement, const CVector& vecVelocity )
10191090
{
10201091
assert ( pElement );

MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CStaticFunctionDefinitions
5959
static CLuaArguments* GetAllElementData ( CElement* pElement, CLuaArguments * table );
6060
static CElement* GetElementParent ( CElement* pElement );
6161
static bool GetElementPosition ( CElement* pElement, CVector& vecPosition );
62+
static bool GetElementRotation ( CElement* pElement, CVector& vecRotation );
6263
static bool GetElementVelocity ( CElement* pElement, CVector& vecVelocity );
6364
static bool GetElementInterior ( CElement* pElement, unsigned char& ucInterior );
6465
static bool IsElementWithinColShape ( CElement* pElement, CColShape* pColShape, bool& bWithin );
@@ -80,6 +81,7 @@ class CStaticFunctionDefinitions
8081
static bool RemoveElementData ( CElement* pElement, const char* szName );
8182
static bool SetElementParent ( CElement* pElement, CElement* pParent );
8283
static bool SetElementPosition ( CElement* pElement, const CVector& vecPosition, bool bWarp = true );
84+
static bool SetElementRotation ( CElement* pElement, const CVector& vecRotation );
8385
static bool SetElementVelocity ( CElement* pElement, const CVector& vecVelocity );
8486
static bool SetElementVisibleTo ( CElement* pElement, CElement* pReference, bool bVisible );
8587
static bool SetElementInterior ( CElement* pElement, unsigned char ucInterior, bool bSetPosition, CVector& vecPosition );

MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void CLuaElementDefs::LoadFunctions ( void )
4343
CLuaCFunctions::AddFunction ( "getElementID", CLuaElementDefs::getElementID );
4444
CLuaCFunctions::AddFunction ( "getElementParent", CLuaElementDefs::getElementParent );
4545
CLuaCFunctions::AddFunction ( "getElementPosition", CLuaElementDefs::getElementPosition );
46+
CLuaCFunctions::AddFunction ( "getElementRotation", CLuaElementDefs::getElementRotation );
4647
CLuaCFunctions::AddFunction ( "getElementVelocity", CLuaElementDefs::getElementVelocity );
4748
CLuaCFunctions::AddFunction ( "getElementsByType", CLuaElementDefs::getElementsByType );
4849
CLuaCFunctions::AddFunction ( "getElementType", CLuaElementDefs::getElementType );
@@ -73,6 +74,7 @@ void CLuaElementDefs::LoadFunctions ( void )
7374
CLuaCFunctions::AddFunction ( "setElementID", CLuaElementDefs::setElementID );
7475
CLuaCFunctions::AddFunction ( "setElementParent", CLuaElementDefs::setElementParent );
7576
CLuaCFunctions::AddFunction ( "setElementPosition", CLuaElementDefs::setElementPosition );
77+
CLuaCFunctions::AddFunction ( "setElementRotation", CLuaElementDefs::setElementRotation );
7678
CLuaCFunctions::AddFunction ( "setElementVelocity", CLuaElementDefs::setElementVelocity );
7779
CLuaCFunctions::AddFunction ( "setElementVisibleTo", CLuaElementDefs::setElementVisibleTo );
7880
CLuaCFunctions::AddFunction ( "clearElementVisibleTo", CLuaElementDefs::clearElementVisibleTo );
@@ -512,6 +514,38 @@ int CLuaElementDefs::getElementPosition ( lua_State* luaVM )
512514
}
513515

514516

517+
int CLuaElementDefs::getElementRotation ( lua_State* luaVM )
518+
{
519+
// Verify the argument
520+
if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
521+
{
522+
// Grab the element, verify it
523+
CElement* pElement = lua_toelement ( luaVM, 1 );
524+
if ( pElement )
525+
{
526+
// Grab the rotation
527+
CVector vecRotation;
528+
if ( CStaticFunctionDefinitions::GetElementRotation ( pElement, vecRotation ) )
529+
{
530+
// Return it
531+
lua_pushnumber ( luaVM, vecRotation.fX );
532+
lua_pushnumber ( luaVM, vecRotation.fY );
533+
lua_pushnumber ( luaVM, vecRotation.fZ );
534+
return 3;
535+
}
536+
}
537+
else
538+
m_pScriptDebugging->LogBadPointer ( luaVM, "getElementRotation", "element", 1 );
539+
}
540+
else
541+
m_pScriptDebugging->LogBadType ( luaVM, "getElementRotation" );
542+
543+
lua_pushboolean ( luaVM, false );
544+
return 1;
545+
}
546+
547+
548+
515549
int CLuaElementDefs::getElementVelocity ( lua_State* luaVM )
516550
{
517551
// Verify the argument
@@ -1346,6 +1380,47 @@ int CLuaElementDefs::setElementPosition ( lua_State* luaVM )
13461380
}
13471381

13481382

1383+
int CLuaElementDefs::setElementRotation ( lua_State* luaVM )
1384+
{
1385+
// Verify the first argument
1386+
if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
1387+
{
1388+
// Grab the element and verify it
1389+
CElement* pElement = lua_toelement ( luaVM, 1 );
1390+
if ( pElement )
1391+
{
1392+
int iArgument2 = lua_type ( luaVM, 2 );
1393+
int iArgument3 = lua_type ( luaVM, 3 );
1394+
int iArgument4 = lua_type ( luaVM, 4 );
1395+
if ( ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
1396+
( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
1397+
( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) )
1398+
{
1399+
// Grab the rotation
1400+
CVector vecRotation = CVector ( static_cast < float > ( lua_tonumber ( luaVM, 2 ) ),
1401+
static_cast < float > ( lua_tonumber ( luaVM, 3 ) ),
1402+
static_cast < float > ( lua_tonumber ( luaVM, 4 ) ) );
1403+
// Set the rotation
1404+
if ( CStaticFunctionDefinitions::SetElementRotation ( pElement, vecRotation ) )
1405+
{
1406+
lua_pushboolean ( luaVM, true );
1407+
return 1;
1408+
}
1409+
}
1410+
else
1411+
m_pScriptDebugging->LogBadType ( luaVM, "setElementRotation" );
1412+
}
1413+
else
1414+
m_pScriptDebugging->LogBadPointer ( luaVM, "setElementRotation", "element", 1 );
1415+
}
1416+
else
1417+
m_pScriptDebugging->LogBadType ( luaVM, "setElementRotation" );
1418+
1419+
lua_pushboolean ( luaVM, false );
1420+
return 1;
1421+
}
1422+
1423+
13491424
int CLuaElementDefs::setElementVelocity ( lua_State* luaVM )
13501425
{
13511426
// Verify the first argument

MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CLuaElementDefs: public CLuaDefs
4141
static int getAllElementData ( lua_State* luaVM );
4242
static int getElementParent ( lua_State* luaVM );
4343
static int getElementPosition ( lua_State* luaVM );
44+
static int getElementRotation ( lua_State* luaVM );
4445
static int getElementVelocity ( lua_State* luaVM );
4546
static int getElementType ( lua_State* luaVM );
4647
static int getElementsByType ( lua_State* luaVM );
@@ -77,6 +78,7 @@ class CLuaElementDefs: public CLuaDefs
7778
static int setElementID ( lua_State* luaVM );
7879
static int setElementParent ( lua_State* luaVM );
7980
static int setElementPosition ( lua_State* luaVM );
81+
static int setElementRotation ( lua_State* luaVM );
8082
static int setElementVelocity ( lua_State* luaVM );
8183
static int setElementInterior ( lua_State* luaVM );
8284
static int setElementDimension ( lua_State* luaVM );

0 commit comments

Comments
 (0)