From 906c3496f2abcb1bfd37f7ff335636f1e6d8a9c4 Mon Sep 17 00:00:00 2001 From: "Mr.Hankey" Date: Sun, 14 Mar 2010 00:28:28 +0100 Subject: [PATCH 01/20] Added setElementSyncer ( ped/vehicle, player ) --- .../logic/CStaticFunctionDefinitions.cpp | 26 +++++++++++++++++ .../logic/CStaticFunctionDefinitions.h | 1 + .../logic/luadefs/CLuaElementDefs.cpp | 28 +++++++++++++++++++ .../logic/luadefs/CLuaElementDefs.h | 1 + 4 files changed, 56 insertions(+) diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index c5ea0aef2c..fe8cfc4d4c 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1491,6 +1491,32 @@ bool CStaticFunctionDefinitions::ClearElementVisibleTo ( CElement* pElement ) return true; } +bool CStaticFunctionDefinitions::SetElementSyncer ( CElement* pElement, CPlayer* pPlayer ) +{ + assert ( pElement ); + assert ( pPlayer ); + + switch ( pElement->GetType () ) + { + case CElement::PED: + { + CPed* pPed = static_cast < CPed* > ( pElement ); + pPed->SetSyncer ( pPlayer ); + return true; + break; + } + case CElement::VEHICLE: + { + CVehicle* pVehicle = static_cast < CVehicle* > ( pElement ); + pVehicle->SetSyncer ( pPlayer ); + return true; + break; + } + default: return false; + } + return false; +} + bool CStaticFunctionDefinitions::GetPlayerName ( CElement* pElement, char* szNick ) { diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index dd69c55405..72edee7f4e 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -92,6 +92,7 @@ class CStaticFunctionDefinitions static bool SetElementHealth ( CElement* pElement, float fHealth ); static bool SetElementModel ( CElement* pElement, unsigned short usModel ); static bool SetElementAttachedOffsets ( CElement* pElement, CVector & vecPosition, CVector & vecRotation ); + static bool SetElementSyncer ( CElement* pElement, CPlayer* pPlayer ); // Scoreboard static bool AddScoreboardColumn ( const char* szID, const char* szName, float fWidth ); diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index f35c927b1c..5e84eff301 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -84,6 +84,7 @@ void CLuaElementDefs::LoadFunctions ( void ) CLuaCFunctions::AddFunction ( "setElementAlpha", CLuaElementDefs::setElementAlpha ); CLuaCFunctions::AddFunction ( "setElementHealth", CLuaElementDefs::setElementHealth ); CLuaCFunctions::AddFunction ( "setElementModel", CLuaElementDefs::setElementModel ); + CLuaCFunctions::AddFunction ( "setElementSyncer", CLuaElementDefs::setElementSyncer ); } @@ -1744,3 +1745,30 @@ int CLuaElementDefs::setElementModel ( lua_State* luaVM ) lua_pushboolean ( luaVM, false ); return 1; } + +int CLuaElementDefs::setElementSyncer ( lua_State* luaVM ) +{ + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA && lua_type ( luaVM, 2 ) == LUA_TLIGHTUSERDATA ) + { + CElement* pElement = lua_toelement ( luaVM, 1 ); + CPlayer* pPlayer = lua_toplayer ( luaVM, 2 ); + + if ( pElement ) + { + if ( pPlayer ) + { + lua_pushboolean ( luaVM, CStaticFunctionDefinitions::SetElementSyncer ( pElement, pPlayer ) ); + return 1; + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "setElementSyncer", "player", 2 ); + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "setElementSyncer", "element", 1 ); + } + else + m_pScriptDebugging->LogBadType ( luaVM, "setElementSyncer" ); + + lua_pushboolean ( luaVM, false ); + return 1; +} diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index c04c67dac9..ac4ba45eca 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -85,6 +85,7 @@ class CLuaElementDefs: public CLuaDefs static int setElementAlpha ( lua_State* luaVM ); static int setElementHealth ( lua_State* luaVM ); static int setElementModel ( lua_State* luaVM ); + static int setElementSyncer ( lua_State* luaVM ); }; #endif From ac8a60b99fd1e9bfee00c0abe993b67849df5226 Mon Sep 17 00:00:00 2001 From: ccw808 Date: Mon, 12 Apr 2010 03:59:53 +0100 Subject: [PATCH 02/20] Completed setElementSyncer and added option to disable syncing --- .../mods/deathmatch/logic/CPedSync.cpp | 25 ++++++++++++++++--- .../logic/CStaticFunctionDefinitions.cpp | 9 ++++--- .../logic/CStaticFunctionDefinitions.h | 2 +- .../logic/CUnoccupiedVehicleSync.cpp | 17 +++++++++++++ .../mods/deathmatch/logic/CVehicle.cpp | 1 + MTA10_Server/mods/deathmatch/logic/CVehicle.h | 4 +++ .../logic/luadefs/CLuaElementDefs.cpp | 11 +++++--- 7 files changed, 57 insertions(+), 12 deletions(-) diff --git a/MTA10_Server/mods/deathmatch/logic/CPedSync.cpp b/MTA10_Server/mods/deathmatch/logic/CPedSync.cpp index 0b4ee9a5c6..1640566008 100644 --- a/MTA10_Server/mods/deathmatch/logic/CPedSync.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CPedSync.cpp @@ -26,7 +26,7 @@ CPedSync::CPedSync ( CPlayerManager* pPlayerManager, CPedManager* pPedManager ) void CPedSync::DoPulse ( void ) { - // Time to check for players that should no longer be syncing a vehicle or vehicles that should be synced? + // Time to check for players that should no longer be syncing a ped or peds that should be synced? unsigned long ulCurrentTime = GetTime (); if ( ulCurrentTime >= m_ulLastSweepTime + 500 ) { @@ -71,7 +71,7 @@ void CPedSync::Update ( unsigned long ulCurrentTime ) for ( ; iter != m_pPedManager->IterEnd (); iter++ ) { // It is a ped, yet not a player - if ( IS_PED ( *iter ) && !IS_PLAYER ( *iter ) && ( *iter )->IsSyncable() ) + if ( IS_PED ( *iter ) && !IS_PLAYER ( *iter ) ) UpdatePed ( *iter ); } } @@ -81,10 +81,22 @@ void CPedSync::UpdatePed ( CPed* pPed ) { CPlayer* pSyncer = pPed->GetSyncer (); - // This vehicle got a syncer? + // Handle no syncing + if ( !pPed->IsSyncable () ) + { + // This ped got a syncer? + if ( pSyncer ) + { + // Tell the syncer to stop syncing + StopSync ( pPed ); + } + return; + } + + // This ped got a syncer? if ( pSyncer ) { - // He isn't close enough to the vehicle and in the right dimension? + // He isn't close enough to the ped and in the right dimension? if ( ( !IsPointNearPoint3D ( pSyncer->GetPosition (), pPed->GetPosition (), MAX_PLAYER_SYNC_DISTANCE ) ) || ( pPed->GetDimension () != pSyncer->GetDimension () ) ) { @@ -105,6 +117,8 @@ void CPedSync::UpdatePed ( CPed* pPed ) void CPedSync::FindSyncer ( CPed* pPed ) { + assert ( pPed->IsSyncable () ); + // Find a player close enough to him CPlayer* pPlayer = FindPlayerCloseToPed ( pPed, MAX_PLAYER_SYNC_DISTANCE - 20.0f ); if ( pPlayer ) @@ -117,6 +131,9 @@ void CPedSync::FindSyncer ( CPed* pPed ) void CPedSync::StartSync ( CPlayer* pPlayer, CPed* pPed ) { + if ( !pPed->IsSyncable () ) + return; + // Tell the player pPlayer->Send ( CPedStartSyncPacket ( pPed ) ); diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index fe8cfc4d4c..3cc76908e4 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1491,24 +1491,25 @@ bool CStaticFunctionDefinitions::ClearElementVisibleTo ( CElement* pElement ) return true; } -bool CStaticFunctionDefinitions::SetElementSyncer ( CElement* pElement, CPlayer* pPlayer ) +bool CStaticFunctionDefinitions::SetElementSyncer ( CElement* pElement, CPlayer* pPlayer, bool bEnable ) { assert ( pElement ); - assert ( pPlayer ); switch ( pElement->GetType () ) { case CElement::PED: { CPed* pPed = static_cast < CPed* > ( pElement ); - pPed->SetSyncer ( pPlayer ); + pPed->SetSyncable ( bEnable ); + g_pGame->GetPedSync()->OverrideSyncer ( pPed, pPlayer ); return true; break; } case CElement::VEHICLE: { CVehicle* pVehicle = static_cast < CVehicle* > ( pElement ); - pVehicle->SetSyncer ( pPlayer ); + pVehicle->SetUnoccupiedSyncable ( bEnable ); + g_pGame->GetUnoccupiedVehicleSync()->OverrideSyncer ( pVehicle, pPlayer ); return true; break; } diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 72edee7f4e..058e9acdf9 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -92,7 +92,7 @@ class CStaticFunctionDefinitions static bool SetElementHealth ( CElement* pElement, float fHealth ); static bool SetElementModel ( CElement* pElement, unsigned short usModel ); static bool SetElementAttachedOffsets ( CElement* pElement, CVector & vecPosition, CVector & vecRotation ); - static bool SetElementSyncer ( CElement* pElement, CPlayer* pPlayer ); + static bool SetElementSyncer ( CElement* pElement, CPlayer* pPlayer, bool bEnable = true ); // Scoreboard static bool AddScoreboardColumn ( const char* szID, const char* szName, float fWidth ); diff --git a/MTA10_Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp b/MTA10_Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp index 23402cc7a5..c029cecafb 100644 --- a/MTA10_Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp @@ -85,6 +85,18 @@ void CUnoccupiedVehicleSync::UpdateVehicle ( CVehicle* pVehicle ) CPlayer* pSyncer = pVehicle->GetSyncer (); CPed* pController = pVehicle->GetController (); + // Handle no syncing when not occupied + if ( !pVehicle->IsUnoccupiedSyncable () ) + { + // This vehicle got a syncer? + if ( pSyncer ) + { + // Tell the syncer to stop syncing + StopSync ( pVehicle ); + } + return; + } + // If someones driving it, or its being towed by someone driving (and not just entering/exiting) if ( pController && IS_PLAYER ( pController ) && pController->GetVehicleAction () == CPlayer::VEHICLEACTION_NONE ) { @@ -122,6 +134,8 @@ void CUnoccupiedVehicleSync::UpdateVehicle ( CVehicle* pVehicle ) void CUnoccupiedVehicleSync::FindSyncer ( CVehicle* pVehicle ) { + assert ( pVehicle->IsUnoccupiedSyncable () ); + // This vehicle got any passengers? CPed* pPassenger = pVehicle->GetFirstOccupant (); if ( pPassenger && IS_PLAYER ( pPassenger ) && !pPassenger->IsBeingDeleted() ) @@ -144,6 +158,9 @@ void CUnoccupiedVehicleSync::FindSyncer ( CVehicle* pVehicle ) void CUnoccupiedVehicleSync::StartSync ( CPlayer* pPlayer, CVehicle* pVehicle ) { + if ( !pVehicle->IsUnoccupiedSyncable () ) + return; + // Tell the player pPlayer->Send ( CUnoccupiedVehicleStartSyncPacket ( pVehicle ) ); diff --git a/MTA10_Server/mods/deathmatch/logic/CVehicle.cpp b/MTA10_Server/mods/deathmatch/logic/CVehicle.cpp index 996367d2da..cbb1d1b335 100644 --- a/MTA10_Server/mods/deathmatch/logic/CVehicle.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CVehicle.cpp @@ -35,6 +35,7 @@ CVehicle::CVehicle ( CVehicleManager* pVehicleManager, CElement* pParent, CXMLNo m_bLandingGearDown = true; m_usAdjustableProperty = 0; m_bIsFrozen = false; + m_bUnoccupiedSyncable = true; m_pSyncer = NULL; GetInitialDoorStates ( m_ucDoorStates ); memset ( m_ucWheelStates, 0, sizeof ( m_ucWheelStates ) ); diff --git a/MTA10_Server/mods/deathmatch/logic/CVehicle.h b/MTA10_Server/mods/deathmatch/logic/CVehicle.h index 1ebfc6f0ad..b0f2981113 100644 --- a/MTA10_Server/mods/deathmatch/logic/CVehicle.h +++ b/MTA10_Server/mods/deathmatch/logic/CVehicle.h @@ -196,6 +196,9 @@ class CVehicle : public CElement inline class CPlayer* GetSyncer ( void ) { return m_pSyncer; }; void SetSyncer ( class CPlayer* pPlayer ); + bool IsUnoccupiedSyncable ( void ) { return m_bUnoccupiedSyncable; }; + void SetUnoccupiedSyncable ( bool bUnoccupiedSynced ) { m_bUnoccupiedSyncable = bUnoccupiedSynced; }; + unsigned char GetMaxPassengers ( void ); unsigned char GetFreePassengerSeat ( void ); @@ -301,6 +304,7 @@ class CVehicle : public CElement CVehicleColor m_Color; bool m_bIsFrozen; + bool m_bUnoccupiedSyncable; CVehicleUpgrades* m_pUpgrades; diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 5e84eff301..cef96ace66 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -1748,16 +1748,21 @@ int CLuaElementDefs::setElementModel ( lua_State* luaVM ) int CLuaElementDefs::setElementSyncer ( lua_State* luaVM ) { - if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA && lua_type ( luaVM, 2 ) == LUA_TLIGHTUSERDATA ) + int iArgument2 = lua_type ( luaVM, 2 ); + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA && ( iArgument2 == LUA_TLIGHTUSERDATA || iArgument2 == LUA_TNIL ) ) { CElement* pElement = lua_toelement ( luaVM, 1 ); CPlayer* pPlayer = lua_toplayer ( luaVM, 2 ); + bool bEnable = true; + + if ( lua_type ( luaVM, 3 ) == LUA_TBOOLEAN ) + bEnable = lua_toboolean ( luaVM, 3 ) ? true : false; if ( pElement ) { - if ( pPlayer ) + if ( pPlayer || iArgument2 == LUA_TNIL ) { - lua_pushboolean ( luaVM, CStaticFunctionDefinitions::SetElementSyncer ( pElement, pPlayer ) ); + lua_pushboolean ( luaVM, CStaticFunctionDefinitions::SetElementSyncer ( pElement, pPlayer, bEnable ) ); return 1; } else From c60ab3a4bea5a5093963d4b446d1de2a3ea9156e Mon Sep 17 00:00:00 2001 From: jte Date: Wed, 7 Apr 2010 08:18:32 -0700 Subject: [PATCH 03/20] Added fStartX, fStartY, fEndX and fEndY to sDrawQueueTexture and DrawTextureQueued. --- MTA10/core/CGraphics.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MTA10/core/CGraphics.h b/MTA10/core/CGraphics.h index faac379c5e..7dd77a596e 100644 --- a/MTA10/core/CGraphics.h +++ b/MTA10/core/CGraphics.h @@ -114,6 +114,10 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > float fRotation, float fRotCenOffX, float fRotCenOffY, + float fStartX, + float fStartY, + float fEndX, + float fEndY, unsigned long ulColor, bool bPostGUI ); @@ -247,6 +251,10 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > float fRotation; float fRotCenOffX; float fRotCenOffY; + float fStartX; + float fStartY; + float fEndX; + float fEndY; unsigned long ulColor; }; From 130d6fb9c337a4d5f46e7bd842812b7a2b1283f7 Mon Sep 17 00:00:00 2001 From: jte Date: Wed, 7 Apr 2010 08:44:00 -0700 Subject: [PATCH 04/20] Modified DrawTextureQueued and DrawQueueItem. --- MTA10/core/CGraphics.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/MTA10/core/CGraphics.cpp b/MTA10/core/CGraphics.cpp index 9655f91d3d..072240d6e2 100644 --- a/MTA10/core/CGraphics.cpp +++ b/MTA10/core/CGraphics.cpp @@ -590,6 +590,10 @@ bool CGraphics::DrawTextureQueued ( float fX, float fY, float fRotation, float fRotCenOffX, float fRotCenOffY, + float fStartX, + float fStartY, + float fEndX, + float fEndY, unsigned long ulColor, bool bPostGUI ) { @@ -604,6 +608,10 @@ bool CGraphics::DrawTextureQueued ( float fX, float fY, Item.Texture.fRotation = fRotation; Item.Texture.fRotCenOffX = fRotCenOffX; Item.Texture.fRotCenOffY = fRotCenOffY; + Item.Texture.fStartX = fStartX; + Item.Texture.fStartY = fStartY; + Item.Texture.fEndX = fEndX; + Item.Texture.fEndY = fEndY; Item.Texture.ulColor = ulColor; if ( !Item.Texture.texture ) @@ -999,9 +1007,10 @@ void CGraphics::DrawQueueItem ( const sDrawQueueItem& Item ) D3DXVECTOR2 scaling ( Item.Texture.fWidth / texureWidth, Item.Texture.fHeight / texureHeight ); D3DXVECTOR2 rotationCenter ( Item.Texture.fWidth * 0.5f + Item.Texture.fRotCenOffX, Item.Texture.fHeight * 0.5f + Item.Texture.fRotCenOffY ); D3DXVECTOR2 position ( Item.Texture.fX, Item.Texture.fY ); + RECT cutImagePos ( Item.Texture.fStartX, Item.Texture.fStartY, Item.Texture.fEndX, Item.Texture.fEndY ); D3DXMatrixTransformation2D ( &matrix, NULL, 0.0f, &scaling, &rotationCenter, fRotationRad, &position ); m_pDXSprite->SetTransform ( &matrix ); - m_pDXSprite->Draw ( Item.Texture.texture, NULL, NULL, NULL, Item.Texture.ulColor ); + m_pDXSprite->Draw ( Item.Texture.texture, cutImagePos, NULL, NULL, Item.Texture.ulColor ); break; } // Circle type? From 0e2fa45ef4118314e0c870da017a7a93cc1d87fa Mon Sep 17 00:00:00 2001 From: jte Date: Wed, 7 Apr 2010 08:54:13 -0700 Subject: [PATCH 05/20] Modified dxDrawImage. --- .../lua/CLuaFunctionDefs.Drawing.cpp | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp index 11eed0d5d9..def538387a 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp @@ -296,7 +296,7 @@ int CLuaFunctionDefs::dxDrawRectangle ( lua_State* luaVM ) int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) { // dxDrawImage ( float x,float y,float width,float height,string filename,[float rotation, - // float rotCenOffX, float rotCenOffY, int color=0xffffffff, bool postgui] ) + // float rotCenOffX, float rotCenOffY, float startX 9, float startY, float endX, float endY 12, int color=0xffffffff, bool postgui] ) // Grab all argument types int iArgument1 = lua_type ( luaVM, 1 ); @@ -318,6 +318,10 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) float fRotation = 0; float fRotCenOffX = 0; float fRotCenOffY = 0; + float fStartX = 0; + float fStartY = 0; + float fEndX = 0; + float fEndY = 0; unsigned long ulColor = 0xFFFFFFFF; int iArgument6 = lua_type ( luaVM, 6 ); @@ -337,19 +341,38 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) { fRotCenOffY = static_cast < float > ( lua_tonumber ( luaVM, 8 ) ); } - - int iArgument9 = lua_type ( luaVM, 9 ); - if ( ( iArgument9 == LUA_TNUMBER || iArgument9 == LUA_TSTRING ) ) + int iArgument9 = lua_type( luaVM, 9); + if((iArgument9 == LUA_TNUMBER || iArgument9 == LUA_TSTRING)) + { + fStartX = static_cast(lua_tonumber(luaVM, 9)); + } + int iArgument10 = lua_type( luaVM, 10); + if((iArgument10 == LUA_TNUMBER || iArgument10 == LUA_TSTRING)) + { + fStartY = static_cast(lua_tonumber(luaVM, 10)); + } + int iArgument11 = lua_type( luaVM, 11); + if((iArgument11 == LUA_TNUMBER || iArgument11 == LUA_TSTRING)) + { + fEndX = static_cast(lua_tonumber(luaVM, 11)); + } + int iArgument12 = lua_type( luaVM, 12); + if((iArgument12 == LUA_TNUMBER || iArgument12 == LUA_TSTRING)) + { + fEndY = static_cast(lua_tonumber(luaVM, 12)); + } + int iArgument13 = lua_type ( luaVM, 13 ); + if ( ( iArgument13 == LUA_TNUMBER || iArgument13 == LUA_TSTRING ) ) { - ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 9 ) ); + ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 13 ) ); } // Got a post gui specifier? bool bPostGUI = false; - int iArgument10 = lua_type ( luaVM, 10 ); - if ( iArgument10 == LUA_TBOOLEAN ) + int iArgument14 = lua_type ( luaVM, 14 ); + if ( iArgument14 == LUA_TBOOLEAN ) { - bPostGUI = ( lua_toboolean ( luaVM, 10 ) ) ? true:false; + bPostGUI = ( lua_toboolean ( luaVM, 14 ) ) ? true:false; } CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); From 35d189423b521a5f62e6535c185d29b25b62595c Mon Sep 17 00:00:00 2001 From: ccw808 Date: Fri, 16 Apr 2010 14:21:24 +0100 Subject: [PATCH 06/20] Fixed 5258: (Drawing part of an image using dxDrawImage) --- MTA10/core/CGraphics.cpp | 32 +++-- MTA10/core/CGraphics.h | 16 +-- .../lua/CLuaFunctionDefs.Drawing.cpp | 118 ++++++++++++++---- .../mods/shared_logic/lua/CLuaFunctionDefs.h | 1 + MTA10/mods/shared_logic/lua/CLuaManager.cpp | 1 + MTA10/sdk/core/CGraphicsInterface.h | 3 + 6 files changed, 131 insertions(+), 40 deletions(-) diff --git a/MTA10/core/CGraphics.cpp b/MTA10/core/CGraphics.cpp index 072240d6e2..a256712c1f 100644 --- a/MTA10/core/CGraphics.cpp +++ b/MTA10/core/CGraphics.cpp @@ -586,14 +586,13 @@ void CGraphics::DrawRectQueued ( float fX, float fY, bool CGraphics::DrawTextureQueued ( float fX, float fY, float fWidth, float fHeight, + float fU, float fV, + float fSizeU, float fSizeV, + bool bRelativeUV, const string& strFilename, float fRotation, float fRotCenOffX, float fRotCenOffY, - float fStartX, - float fStartY, - float fEndX, - float fEndY, unsigned long ulColor, bool bPostGUI ) { @@ -604,14 +603,15 @@ bool CGraphics::DrawTextureQueued ( float fX, float fY, Item.Texture.fY = fY; Item.Texture.fWidth = fWidth; Item.Texture.fHeight = fHeight; + Item.Texture.fU = fU; + Item.Texture.fV = fV; + Item.Texture.fSizeU = fSizeU; + Item.Texture.fSizeV = fSizeV; + Item.Texture.bRelativeUV = bRelativeUV; Item.Texture.texture = CacheTexture( strFilename ); Item.Texture.fRotation = fRotation; Item.Texture.fRotCenOffX = fRotCenOffX; Item.Texture.fRotCenOffY = fRotCenOffY; - Item.Texture.fStartX = fStartX; - Item.Texture.fStartY = fStartY; - Item.Texture.fEndX = fEndX; - Item.Texture.fEndY = fEndY; Item.Texture.ulColor = ulColor; if ( !Item.Texture.texture ) @@ -900,7 +900,11 @@ void CGraphics::DrawQueue ( std::vector < sDrawQueueItem >& Queue ) { bSpriteMode = IsDrawQueueItemSprite ( *iter ); if ( bSpriteMode ) + { m_pDXSprite->Begin ( D3DXSPRITE_ALPHABLEND ); + m_pDevice->SetSamplerState ( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP ); + m_pDevice->SetSamplerState ( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP ); + } else m_pDXSprite->End (); } @@ -1004,13 +1008,19 @@ void CGraphics::DrawQueueItem ( const sDrawQueueItem& Item ) float texureHeight = texureDesc.Height; float fRotationRad = Item.Texture.fRotation * (6.2832f/360.f); D3DXMATRIX matrix; - D3DXVECTOR2 scaling ( Item.Texture.fWidth / texureWidth, Item.Texture.fHeight / texureHeight ); + RECT cutImagePos; + cutImagePos.left = ( Item.Texture.fU ) * ( Item.Texture.bRelativeUV ? texureWidth : 1 ); + cutImagePos.top = ( Item.Texture.fV ) * ( Item.Texture.bRelativeUV ? texureHeight : 1 ); + cutImagePos.right = ( Item.Texture.fU + Item.Texture.fSizeU ) * ( Item.Texture.bRelativeUV ? texureWidth : 1 ); + cutImagePos.bottom = ( Item.Texture.fV + Item.Texture.fSizeV ) * ( Item.Texture.bRelativeUV ? texureHeight : 1 ); + float fCutWidth = cutImagePos.right - cutImagePos.left; + float fCutHeight = cutImagePos.bottom - cutImagePos.top; + D3DXVECTOR2 scaling ( Item.Texture.fWidth / fCutWidth, Item.Texture.fHeight / fCutHeight ); D3DXVECTOR2 rotationCenter ( Item.Texture.fWidth * 0.5f + Item.Texture.fRotCenOffX, Item.Texture.fHeight * 0.5f + Item.Texture.fRotCenOffY ); D3DXVECTOR2 position ( Item.Texture.fX, Item.Texture.fY ); - RECT cutImagePos ( Item.Texture.fStartX, Item.Texture.fStartY, Item.Texture.fEndX, Item.Texture.fEndY ); D3DXMatrixTransformation2D ( &matrix, NULL, 0.0f, &scaling, &rotationCenter, fRotationRad, &position ); m_pDXSprite->SetTransform ( &matrix ); - m_pDXSprite->Draw ( Item.Texture.texture, cutImagePos, NULL, NULL, Item.Texture.ulColor ); + m_pDXSprite->Draw ( Item.Texture.texture, &cutImagePos, NULL, NULL, Item.Texture.ulColor ); break; } // Circle type? diff --git a/MTA10/core/CGraphics.h b/MTA10/core/CGraphics.h index 7dd77a596e..017357f05d 100644 --- a/MTA10/core/CGraphics.h +++ b/MTA10/core/CGraphics.h @@ -110,14 +110,13 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > bool DrawTextureQueued ( float fX, float fY, float fWidth, float fHeight, + float fU, float fV, + float fSizeU, float fSizeV, + bool bRelativeUV, const std::string& strFilename, float fRotation, float fRotCenOffX, float fRotCenOffY, - float fStartX, - float fStartY, - float fEndX, - float fEndY, unsigned long ulColor, bool bPostGUI ); @@ -248,14 +247,15 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > float fY; float fWidth; float fHeight; + float fU; + float fV; + float fSizeU; + float fSizeV; float fRotation; float fRotCenOffX; float fRotCenOffY; - float fStartX; - float fStartY; - float fEndX; - float fEndY; unsigned long ulColor; + bool bRelativeUV; }; struct sDrawQueueItem diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp index def538387a..d9ee6fb4d2 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp @@ -296,7 +296,7 @@ int CLuaFunctionDefs::dxDrawRectangle ( lua_State* luaVM ) int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) { // dxDrawImage ( float x,float y,float width,float height,string filename,[float rotation, - // float rotCenOffX, float rotCenOffY, float startX 9, float startY, float endX, float endY 12, int color=0xffffffff, bool postgui] ) + // float rotCenOffX, float rotCenOffY, int color=0xffffffff, bool postgui] ) // Grab all argument types int iArgument1 = lua_type ( luaVM, 1 ); @@ -318,10 +318,6 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) float fRotation = 0; float fRotCenOffX = 0; float fRotCenOffY = 0; - float fStartX = 0; - float fStartY = 0; - float fEndX = 0; - float fEndY = 0; unsigned long ulColor = 0xFFFFFFFF; int iArgument6 = lua_type ( luaVM, 6 ); @@ -341,26 +337,107 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) { fRotCenOffY = static_cast < float > ( lua_tonumber ( luaVM, 8 ) ); } - int iArgument9 = lua_type( luaVM, 9); - if((iArgument9 == LUA_TNUMBER || iArgument9 == LUA_TSTRING)) + + int iArgument9 = lua_type ( luaVM, 9 ); + if ( ( iArgument9 == LUA_TNUMBER || iArgument9 == LUA_TSTRING ) ) { - fStartX = static_cast(lua_tonumber(luaVM, 9)); + ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 9 ) ); } - int iArgument10 = lua_type( luaVM, 10); - if((iArgument10 == LUA_TNUMBER || iArgument10 == LUA_TSTRING)) + + // Got a post gui specifier? + bool bPostGUI = false; + int iArgument10 = lua_type ( luaVM, 10 ); + if ( iArgument10 == LUA_TBOOLEAN ) { - fStartY = static_cast(lua_tonumber(luaVM, 10)); + bPostGUI = ( lua_toboolean ( luaVM, 10 ) ) ? true:false; } - int iArgument11 = lua_type( luaVM, 11); - if((iArgument11 == LUA_TNUMBER || iArgument11 == LUA_TSTRING)) + + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); + CResource* pResource = pLuaMain ? pLuaMain->GetResource() : NULL; + + // Check for a valid (and sane) file path + if ( pResource && szFile ) { - fEndX = static_cast(lua_tonumber(luaVM, 11)); + // Get the correct directory + SString strPath; + if ( CResourceManager::ParseResourcePathInput( szFile, pResource, strPath ) && + g_pCore->GetGraphics ()->DrawTextureQueued ( fX, fY, fWidth, fHeight, 0, 0, 1, 1, true, strPath, fRotation, fRotCenOffX, fRotCenOffY, ulColor, bPostGUI ) ) + { + // Success + lua_pushboolean ( luaVM, true ); + return 1; + } + + m_pScriptDebugging->LogError ( luaVM, "dxDrawImage can't load %s", szFile ); } - int iArgument12 = lua_type( luaVM, 12); - if((iArgument12 == LUA_TNUMBER || iArgument12 == LUA_TSTRING)) + } + else + m_pScriptDebugging->LogBadType ( luaVM, "dxDrawImage" ); + + // Failed + lua_pushboolean ( luaVM, false ); + return 1; +} + + +int CLuaFunctionDefs::dxDrawImageSection ( lua_State* luaVM ) +{ + // dxDrawImageSection ( float x,float y,float width,float height,float u, float v, float usize, float vsize, filename,[float rotation=0, + // float rotCenOffX=0, float rotCenOffY=0, int color=0xffffffff, bool postgui=false] ) + + + // Grab all argument types + int iArgument1 = lua_type ( luaVM, 1 ); + int iArgument2 = lua_type ( luaVM, 2 ); + int iArgument3 = lua_type ( luaVM, 3 ); + int iArgument4 = lua_type ( luaVM, 4 ); + int iArgument5 = lua_type ( luaVM, 5 ); + int iArgument6 = lua_type ( luaVM, 6 ); + int iArgument7 = lua_type ( luaVM, 7 ); + int iArgument8 = lua_type ( luaVM, 8 ); + int iArgument9 = lua_type ( luaVM, 9 ); + if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) && + ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) && + ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) && + ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) && + ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) && + ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) && + ( iArgument7 == LUA_TNUMBER || iArgument7 == LUA_TSTRING ) && + ( iArgument8 == LUA_TNUMBER || iArgument8 == LUA_TSTRING ) && + ( iArgument9 == LUA_TSTRING ) ) + { + float fX = static_cast < float > ( lua_tonumber ( luaVM, 1 ) ); + float fY = static_cast < float > ( lua_tonumber ( luaVM, 2 ) ); + float fWidth = static_cast < float > ( lua_tonumber ( luaVM, 3 ) ); + float fHeight = static_cast < float > ( lua_tonumber ( luaVM, 4 ) ); + float fU = static_cast < float > ( lua_tonumber ( luaVM, 5 ) ); + float fV = static_cast < float > ( lua_tonumber ( luaVM, 6 ) ); + float fSizeU = static_cast < float > ( lua_tonumber ( luaVM, 7 ) ); + float fSizeV = static_cast < float > ( lua_tonumber ( luaVM, 8 ) ); + const char * szFile = lua_tostring ( luaVM, 9 ); + float fRotation = 0; + float fRotCenOffX = 0; + float fRotCenOffY = 0; + unsigned long ulColor = 0xFFFFFFFF; + + int iArgument10 = lua_type ( luaVM, 10 ); + if ( ( iArgument10 == LUA_TNUMBER || iArgument10 == LUA_TSTRING ) ) + { + fRotation = static_cast < float > ( lua_tonumber ( luaVM, 10 ) ); + } + + int iArgument11 = lua_type ( luaVM, 11 ); + if ( ( iArgument11 == LUA_TNUMBER || iArgument11 == LUA_TSTRING ) ) + { + fRotCenOffX = static_cast < float > ( lua_tonumber ( luaVM, 11 ) ); + } + + int iArgument12 = lua_type ( luaVM, 12 ); + if ( ( iArgument12 == LUA_TNUMBER || iArgument12 == LUA_TSTRING ) ) { - fEndY = static_cast(lua_tonumber(luaVM, 12)); + fRotCenOffY = static_cast < float > ( lua_tonumber ( luaVM, 12 ) ); } + int iArgument13 = lua_type ( luaVM, 13 ); if ( ( iArgument13 == LUA_TNUMBER || iArgument13 == LUA_TSTRING ) ) { @@ -384,18 +461,18 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) // Get the correct directory SString strPath; if ( CResourceManager::ParseResourcePathInput( szFile, pResource, strPath ) && - g_pCore->GetGraphics ()->DrawTextureQueued ( fX, fY, fWidth, fHeight, strPath, fRotation, fRotCenOffX, fRotCenOffY, ulColor, bPostGUI ) ) + g_pCore->GetGraphics ()->DrawTextureQueued ( fX, fY, fWidth, fHeight, fU, fV, fSizeU, fSizeV, false, strPath, fRotation, fRotCenOffX, fRotCenOffY, ulColor, bPostGUI ) ) { // Success lua_pushboolean ( luaVM, true ); return 1; } - m_pScriptDebugging->LogError ( luaVM, "dxDrawImage can't load %s", szFile ); + m_pScriptDebugging->LogError ( luaVM, "dxDrawImageSection can't load %s", szFile ); } } else - m_pScriptDebugging->LogBadType ( luaVM, "dxDrawImage" ); + m_pScriptDebugging->LogBadType ( luaVM, "dxDrawImageSection" ); // Failed lua_pushboolean ( luaVM, false ); @@ -403,7 +480,6 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM ) } - int CLuaFunctionDefs::dxGetTextWidth ( lua_State* luaVM ) { // dxGetTextWidth ( string text, [float scale=1,string font="default"] ) diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h index fa1ac48fd0..5ff290c776 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h @@ -451,6 +451,7 @@ class CLuaFunctionDefs LUA_DECLARE ( dxDrawText ); LUA_DECLARE ( dxDrawRectangle ); LUA_DECLARE ( dxDrawImage ); + LUA_DECLARE ( dxDrawImageSection ); LUA_DECLARE ( dxGetTextWidth ); LUA_DECLARE ( dxGetFontHeight ); diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp index 804e371369..3d906368ed 100644 --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp @@ -554,6 +554,7 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "dxDrawText", CLuaFunctionDefs::dxDrawText ); CLuaCFunctions::AddFunction ( "dxDrawRectangle", CLuaFunctionDefs::dxDrawRectangle ); CLuaCFunctions::AddFunction ( "dxDrawImage", CLuaFunctionDefs::dxDrawImage ); + CLuaCFunctions::AddFunction ( "dxDrawImageSection", CLuaFunctionDefs::dxDrawImageSection ); CLuaCFunctions::AddFunction ( "dxGetTextWidth", CLuaFunctionDefs::dxGetTextWidth ); CLuaCFunctions::AddFunction ( "dxGetFontHeight", CLuaFunctionDefs::dxGetFontHeight ); diff --git a/MTA10/sdk/core/CGraphicsInterface.h b/MTA10/sdk/core/CGraphicsInterface.h index 3d2650210b..b273458700 100644 --- a/MTA10/sdk/core/CGraphicsInterface.h +++ b/MTA10/sdk/core/CGraphicsInterface.h @@ -97,6 +97,9 @@ class CGraphicsInterface virtual bool DrawTextureQueued ( float fX, float fY, float fWidth, float fHeight, + float fU, float fV, + float fSizeU, float fSizeV, + bool bRelativeUV, const std::string& strFilename, float fRotation, float fRotCenOffX, From 3d24532b7d64c739a03d56e4af1ea19b07aafb59 Mon Sep 17 00:00:00 2001 From: ccw808 Date: Fri, 16 Apr 2010 14:28:01 +0100 Subject: [PATCH 07/20] Fixed 5284: (Crash on click on a button...) --- MTA10/gui/CGUIElement_Impl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MTA10/gui/CGUIElement_Impl.cpp b/MTA10/gui/CGUIElement_Impl.cpp index 35509ed2a6..68cb84faa3 100644 --- a/MTA10/gui/CGUIElement_Impl.cpp +++ b/MTA10/gui/CGUIElement_Impl.cpp @@ -32,6 +32,9 @@ void CGUIElement_Impl::DestroyElement ( void ) { m_pManager->RemoveFromRedrawQueue ( reinterpret_cast < CGUIElement* > ( ( m_pWindow )->getUserData () ) ); + // Clear pointer back to this + m_pWindow->setUserData ( NULL ); + // Destroy the control m_pManager->GetWindowManager ()->destroyWindow ( m_pWindow ); From 838334602dd1ba4ae4854c2050a4f668ebfaf59f Mon Sep 17 00:00:00 2001 From: ccw808 Date: Fri, 16 Apr 2010 14:47:30 +0100 Subject: [PATCH 08/20] Fixed 5291: (Events can freeze the client) --- MTA10/mods/shared_logic/lua/CLuaArgument.cpp | 1 + MTA10/mods/shared_logic/lua/CLuaArguments.cpp | 36 +++++++++++++++++++ MTA10/mods/shared_logic/lua/CLuaArguments.h | 1 + .../deathmatch/logic/lua/CLuaArgument.cpp | 1 + .../deathmatch/logic/lua/CLuaArguments.cpp | 36 +++++++++++++++++++ .../mods/deathmatch/logic/lua/CLuaArguments.h | 1 + Shared/sdk/SharedUtil.h | 12 ++++++- 7 files changed, 87 insertions(+), 1 deletion(-) diff --git a/MTA10/mods/shared_logic/lua/CLuaArgument.cpp b/MTA10/mods/shared_logic/lua/CLuaArgument.cpp index 3dc25c5bd8..9325ae76ae 100644 --- a/MTA10/mods/shared_logic/lua/CLuaArgument.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaArgument.cpp @@ -519,6 +519,7 @@ bool CLuaArgument::ReadFromBitStream ( NetBitStreamInterface& bitStream, std::ve m_pTableData = new CLuaArguments ( bitStream, pKnownTables ); m_bWeakTableRef = false; m_iType = LUA_TTABLE; + m_pTableData->ValidateTableKeys (); break; } diff --git a/MTA10/mods/shared_logic/lua/CLuaArguments.cpp b/MTA10/mods/shared_logic/lua/CLuaArguments.cpp index da9550cf66..c59a8eda3e 100644 --- a/MTA10/mods/shared_logic/lua/CLuaArguments.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaArguments.cpp @@ -363,6 +363,42 @@ void CLuaArguments::DeleteArguments ( void ) } +void CLuaArguments::ValidateTableKeys ( void ) +{ + // Iterate over m_Arguments as pairs + // If first is LUA_TNIL, then remove pair + vector < CLuaArgument* > ::iterator iter = m_Arguments.begin (); + for ( ; iter != m_Arguments.end () ; ) + { + // Check first in pair + if ( (*iter)->GetType () == LUA_TNIL ) + { + // Remove pair + delete *iter; + iter = m_Arguments.erase ( iter ); + if ( iter != m_Arguments.end () ) + { + delete *iter; + iter = m_Arguments.erase ( iter ); + } + // Check if end + if ( iter == m_Arguments.end () ) + break; + } + else + { + // Skip second in pair + iter++; + // Check if end + if ( iter == m_Arguments.end () ) + break; + + iter++; + } + } +} + + bool CLuaArguments::ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables ) { bool bKnownTablesCreated = false; diff --git a/MTA10/mods/shared_logic/lua/CLuaArguments.h b/MTA10/mods/shared_logic/lua/CLuaArguments.h index 98cd5797f6..f8d5d52ce0 100644 --- a/MTA10/mods/shared_logic/lua/CLuaArguments.h +++ b/MTA10/mods/shared_logic/lua/CLuaArguments.h @@ -73,6 +73,7 @@ class CLuaArguments bool ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables = NULL ); bool WriteToBitStream ( NetBitStreamInterface& bitStream, std::map < CLuaArguments*, unsigned long > * pKnownTables = NULL ) const; + void ValidateTableKeys ( void ); unsigned int Count ( void ) const { return static_cast < unsigned int > ( m_Arguments.size () ); }; std::vector < CLuaArgument* > ::const_iterator IterBegin ( void ) { return m_Arguments.begin (); }; diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaArgument.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaArgument.cpp index 838861f55f..2f778f7386 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaArgument.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaArgument.cpp @@ -538,6 +538,7 @@ bool CLuaArgument::ReadFromBitStream ( NetBitStreamInterface& bitStream, std::ve m_pTableData = new CLuaArguments ( bitStream, pKnownTables ); m_bWeakTableRef = false; m_iType = LUA_TTABLE; + m_pTableData->ValidateTableKeys (); break; } diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.cpp index aa7b699370..a7645a1b84 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.cpp @@ -490,6 +490,42 @@ void CLuaArguments::DeleteArguments ( void ) } +void CLuaArguments::ValidateTableKeys ( void ) +{ + // Iterate over m_Arguments as pairs + // If first is LUA_TNIL, then remove pair + vector < CLuaArgument* > ::iterator iter = m_Arguments.begin (); + for ( ; iter != m_Arguments.end () ; ) + { + // Check first in pair + if ( (*iter)->GetType () == LUA_TNIL ) + { + // Remove pair + delete *iter; + iter = m_Arguments.erase ( iter ); + if ( iter != m_Arguments.end () ) + { + delete *iter; + iter = m_Arguments.erase ( iter ); + } + // Check if end + if ( iter == m_Arguments.end () ) + break; + } + else + { + // Skip second in pair + iter++; + // Check if end + if ( iter == m_Arguments.end () ) + break; + + iter++; + } + } +} + + bool CLuaArguments::ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables ) { bool bKnownTablesCreated = false; diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.h b/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.h index f99721604f..77dbe1cd6f 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.h +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.h @@ -86,6 +86,7 @@ class CLuaArguments CLuaArgument* PushTable ( CLuaArguments * table ); void DeleteArguments ( void ); + void ValidateTableKeys ( void ); bool ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables = NULL ); bool ReadFromJSONString ( const char* szJSON ); diff --git a/Shared/sdk/SharedUtil.h b/Shared/sdk/SharedUtil.h index 737eb11fcc..5bd1cd4b5b 100644 --- a/Shared/sdk/SharedUtil.h +++ b/Shared/sdk/SharedUtil.h @@ -215,7 +215,17 @@ namespace SharedUtil V* MapFind ( std::map < T, V, TR >& collection, const T2& key ) { typename std::map < T, V, TR > ::iterator it = collection.find ( key ); - if ( it != collection.end () ) + if ( it == collection.end () ) + return NULL; + return &it->second; + } + + // Find value in const collection + template < class T, class V, class TR, class T2 > + const V* MapFind ( const std::map < T, V, TR >& collection, const T2& key ) + { + typename std::map < T, V, TR > ::const_iterator it = collection.find ( key ); + if ( it == collection.end () ) return NULL; return &it->second; } From 95b5a6bbb8692dde9a9868fc1448581ead4a5e03 Mon Sep 17 00:00:00 2001 From: Gamesnert Date: Sun, 18 Apr 2010 13:09:06 +0200 Subject: [PATCH 09/20] Added more projectile functions (getProjectileTarget, getProjectileCreator, getProjectileForce) --- .../lua/CLuaFunctionDefs.Projectile.cpp | 65 ++++++++++++++++++- .../mods/shared_logic/lua/CLuaFunctionDefs.h | 3 + MTA10/mods/shared_logic/lua/CLuaManager.cpp | 3 + 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Projectile.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Projectile.cpp index 3a787dbd2a..b0d6009f55 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Projectile.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Projectile.cpp @@ -153,7 +153,7 @@ int CLuaFunctionDefs::GetProjectileType ( lua_State* luaVM ) return 1; } else - m_pScriptDebugging->LogBadPointer ( luaVM, "getProjectileType", "pickup", 1 ); + m_pScriptDebugging->LogBadPointer ( luaVM, "getProjectileType", "projectile", 1 ); } else m_pScriptDebugging->LogBadType ( luaVM, "getProjectileType" ); @@ -162,6 +162,69 @@ int CLuaFunctionDefs::GetProjectileType ( lua_State* luaVM ) return 1; } +int CLuaFunctionDefs::GetProjectileTarget ( lua_State* luaVM ) +{ + // Verify the argument + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA ) + { + CClientProjectile* pProjectile = lua_toprojectile ( luaVM, 1 ); + if ( pProjectile ) + { + unsigned char ucWeapon = pProjectile->GetWeaponType(); + if (ucWeapon == WEAPONTYPE_ROCKET_HS) + { + lua_pushelement ( luaVM, pProjectile->GetTargetEntity() ); + return 1; + } + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "getProjectileTarget", "projectile", 1 ); + } + else + m_pScriptDebugging->LogBadType ( luaVM, "getProjectileTarget" ); + lua_pushboolean ( luaVM, false ); + return 1; +} +int CLuaFunctionDefs::GetProjectileCreator ( lua_State* luaVM ) +{ + // Verify the argument + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA ) + { + CClientProjectile* pProjectile = lua_toprojectile ( luaVM, 1 ); + if ( pProjectile ) + { + lua_pushelement ( luaVM, pProjectile->GetCreator() ); + return 1; + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "getProjectileCreator", "projectile", 1 ); + } + else + m_pScriptDebugging->LogBadType ( luaVM, "getProjectileCreator" ); + + lua_pushboolean ( luaVM, false ); + return 1; +} +int CLuaFunctionDefs::GetProjectileForce ( lua_State* luaVM ) +{ + // Verify the argument + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA ) + { + CClientProjectile* pProjectile = lua_toprojectile ( luaVM, 1 ); + if ( pProjectile ) + { + lua_pushnumber ( luaVM, static_cast < lua_Number > ( pProjectile->GetForce() ) ); + return 1; + } + else + m_pScriptDebugging->LogBadPointer ( luaVM, "getProjectileForce", "projectile", 1 ); + } + else + m_pScriptDebugging->LogBadType ( luaVM, "getProjectileForce" ); + + lua_pushboolean ( luaVM, false ); + return 1; +} diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h index 5ff290c776..c24cde4e6f 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h @@ -655,6 +655,9 @@ class CLuaFunctionDefs // Projectile funcs LUA_DECLARE ( CreateProjectile ); LUA_DECLARE ( GetProjectileType ); + LUA_DECLARE ( GetProjectileTarget ); + LUA_DECLARE ( GetProjectileCreator ); + LUA_DECLARE ( GetProjectileForce ); // Shape create funcs LUA_DECLARE ( CreateColCircle ); diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp index 3d906368ed..598cbbdeb8 100644 --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp @@ -851,6 +851,9 @@ void CLuaManager::LoadCFunctions ( void ) // Projectile funcs CLuaCFunctions::AddFunction ( "createProjectile", CLuaFunctionDefs::CreateProjectile ); CLuaCFunctions::AddFunction ( "getProjectileType", CLuaFunctionDefs::GetProjectileType ); + CLuaCFunctions::AddFunction ( "getProjectileTarget", CLuaFunctionDefs::GetProjectileTarget ); + CLuaCFunctions::AddFunction ( "getProjectileCreator", CLuaFunctionDefs::GetProjectileCreator ); + CLuaCFunctions::AddFunction ( "getProjectileForce", CLuaFunctionDefs::GetProjectileForce ); // Shape create funcs CLuaCFunctions::AddFunction ( "createColCircle", CLuaFunctionDefs::CreateColCircle ); From 606d3baf6441cc87ab3abc30fd98d9622b7288c8 Mon Sep 17 00:00:00 2001 From: ccw808 Date: Sun, 18 Apr 2010 19:43:01 +0100 Subject: [PATCH 10/20] Revert "Added 5267: ([Request and Patch] serverside set/getElementRotation)" This reverts commit 45d42cd09f4c6324513a9b55773f15ec0e79cecf. --- .../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, 8 insertions(+), 159 deletions(-) diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 7d0538ceb0..b6d23199bf 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -302,14 +302,12 @@ 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 ee598e2d05..26be23d5a2 100644 --- a/MTA10/mods/shared_logic/CClientPed.cpp +++ b/MTA10/mods/shared_logic/CClientPed.cpp @@ -543,12 +543,13 @@ void CClientPed::GetRotationRadians ( CVector& vecRotation ) const void CClientPed::SetRotationDegrees ( const CVector& vecRotation ) { // Convert from degrees to radians - float fTempRotation = vecRotation.fZ * 3.1415926535897932384626433832795f / 180.0f; + 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; - // Set the rotation - SetCurrentRotation ( fTempRotation ); - if ( !IS_PLAYER ( this ) ) - SetCameraRotation ( fTempRotation ); + // Set the rotation as radians + SetRotationRadians ( vecTemp ); } diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Element.cpp index ce2aea3e88..8248fd0cb0 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 rotation + // Grab the position 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 3cc76908e4..78e586efbc 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -947,43 +947,6 @@ 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 ); @@ -1052,40 +1015,6 @@ 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 058e9acdf9..6d60730070 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -59,7 +59,6 @@ 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 ); @@ -81,7 +80,6 @@ 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 cef96ace66..966911aa2f 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -43,7 +43,6 @@ 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 ); @@ -74,7 +73,6 @@ 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 ); @@ -515,38 +513,6 @@ 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 @@ -1381,47 +1347,6 @@ 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 ac4ba45eca..da27a62b22 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -41,7 +41,6 @@ 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 ); @@ -78,7 +77,6 @@ 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 ); From 8446db7af4eab3621cf4a3085658b1d23f4da5de Mon Sep 17 00:00:00 2001 From: x86 Date: Sun, 11 Apr 2010 23:26:22 +0200 Subject: [PATCH 11/20] Fixed #4374: (singleplayer is started when minimizing mta on loading screen). --- MTA10/game_sa/CGameSA.cpp | 4 ++++ MTA10/game_sa/CGameSA.h | 2 ++ MTA10/multiplayer_sa/CMultiplayerSA.cpp | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/MTA10/game_sa/CGameSA.cpp b/MTA10/game_sa/CGameSA.cpp index afb6cf4a3a..b621e18d2d 100644 --- a/MTA10/game_sa/CGameSA.cpp +++ b/MTA10/game_sa/CGameSA.cpp @@ -10,6 +10,7 @@ * Cecill Etheredge * Stanislav Bobrov * Alberto Alonso +* Sebas Lamers * * Multi Theft Auto is available from http://www.multitheftauto.com/ * @@ -405,6 +406,9 @@ void CGameSA::Initialize ( void ) { // Initialize garages m_pGarages->Initialize(); + + // *Sebas* Hide the GTA:SA Main menu. + *(BYTE *)(CLASS_CMenu+0x5C) = 0; } eGameVersion CGameSA::GetGameVersion ( void ) diff --git a/MTA10/game_sa/CGameSA.h b/MTA10/game_sa/CGameSA.h index 6fe0846904..135bf9f1a4 100644 --- a/MTA10/game_sa/CGameSA.h +++ b/MTA10/game_sa/CGameSA.h @@ -10,6 +10,7 @@ * Cecill Etheredge * Stanislav Bobrov * Alberto Alonso +* Sebas Lamers * * Multi Theft Auto is available from http://www.multitheftauto.com/ * @@ -27,6 +28,7 @@ #define CLASS_CPad 0xB73458 // ##SA## #define CLASS_CGarages 0x96C048 // ##SA## #define CLASS_CFx 0xa9ae00 // ##SA## +#define CLASS_CMenu 0xBA6748 #define CLASS_RwCamera 0xB6F97C diff --git a/MTA10/multiplayer_sa/CMultiplayerSA.cpp b/MTA10/multiplayer_sa/CMultiplayerSA.cpp index 8654f5612e..2cd6d3ae3f 100644 --- a/MTA10/multiplayer_sa/CMultiplayerSA.cpp +++ b/MTA10/multiplayer_sa/CMultiplayerSA.cpp @@ -11,6 +11,7 @@ * Stanislav Bobrov * Alberto Alonso * Peter <> +* Sebas Lamers * * Multi Theft Auto is available from http://www.multitheftauto.com/ * @@ -1017,6 +1018,12 @@ void CMultiplayerSA::InitHooks() // Allow all screen aspect ratios in multi-monitor dialog *(WORD *)0x7459E1 = 0x9090; + + // Show the GTA:SA Main menu, this fixes some issues (#4374 and MAYBE #4000). + // We are hiding the menu in "void CGameSA::Initialize ( void )". + // + // - Sebas + *(BYTE *)((0xBA6748)+0x5C) = 1; } @@ -1100,7 +1107,7 @@ CShotSyncData * CMultiplayerSA::GetLocalShotSyncData ( ) return GetLocalPedShotSyncData(); } -void CMultiplayerSA::DisablePadHandler( bool bDisabled ) +void CMultiplayerSA::DisablePadHandler ( bool bDisabled ) { // DISABLE GAMEPADS (testing) if ( bDisabled ) From 8371804ff246aa8ffce5ff2bccf511f204f16485 Mon Sep 17 00:00:00 2001 From: x86 Date: Sun, 18 Apr 2010 13:42:27 +0200 Subject: [PATCH 12/20] Fixed the server information output. --- MTA10_Server/mods/deathmatch/logic/CGame.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MTA10_Server/mods/deathmatch/logic/CGame.cpp b/MTA10_Server/mods/deathmatch/logic/CGame.cpp index 406d8805da..d150095d1d 100644 --- a/MTA10_Server/mods/deathmatch/logic/CGame.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CGame.cpp @@ -449,13 +449,13 @@ bool CGame::Start ( int iArgumentCount, char* szArguments [] ) "= Multi Theft Auto: San Andreas v%s\n" \ "===========================================================\n" \ "= Server name : %s\n" \ - "= Server IP address : %s\n" \ + "= Server IP address: %s\n" \ "= Server port : %u\n" \ "= \n" \ - "= Log file : %s\n" \ + "= Log file : %s\n" \ "= Maximum players : %u\n" \ "= MTU packet size : %u\n" \ - "= HTTP port : %u\n" \ + "= HTTP port : %u\n" \ "===========================================================\n", MTA_DM_BUILDTAG_SHORT, From ce058f4b2afdd689878f7853c6c4423b6f9099fd Mon Sep 17 00:00:00 2001 From: x86 Date: Sun, 18 Apr 2010 13:43:40 +0200 Subject: [PATCH 13/20] Fixed the server information output. #2 (Tabs -> Spaces) --- MTA10_Server/mods/deathmatch/logic/CGame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MTA10_Server/mods/deathmatch/logic/CGame.cpp b/MTA10_Server/mods/deathmatch/logic/CGame.cpp index d150095d1d..dd3929d0bc 100644 --- a/MTA10_Server/mods/deathmatch/logic/CGame.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CGame.cpp @@ -455,7 +455,7 @@ bool CGame::Start ( int iArgumentCount, char* szArguments [] ) "= Log file : %s\n" \ "= Maximum players : %u\n" \ "= MTU packet size : %u\n" \ - "= HTTP port : %u\n" \ + "= HTTP port : %u\n" \ "===========================================================\n", MTA_DM_BUILDTAG_SHORT, From 5971f60a16fd8c358c7d662695aa34ba0d35aa75 Mon Sep 17 00:00:00 2001 From: ccw808 Date: Mon, 19 Apr 2010 18:41:22 +0100 Subject: [PATCH 14/20] Fixed dxDrawImageSection sizes --- MTA10/core/CGraphics.cpp | 64 ++++++++++++++++++++++++++-------------- MTA10/core/CGraphics.h | 23 ++++++++------- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/MTA10/core/CGraphics.cpp b/MTA10/core/CGraphics.cpp index a256712c1f..bfb6516ccc 100644 --- a/MTA10/core/CGraphics.cpp +++ b/MTA10/core/CGraphics.cpp @@ -608,13 +608,13 @@ bool CGraphics::DrawTextureQueued ( float fX, float fY, Item.Texture.fSizeU = fSizeU; Item.Texture.fSizeV = fSizeV; Item.Texture.bRelativeUV = bRelativeUV; - Item.Texture.texture = CacheTexture( strFilename ); + Item.Texture.info = CacheTexture( strFilename ); Item.Texture.fRotation = fRotation; Item.Texture.fRotCenOffX = fRotCenOffX; Item.Texture.fRotCenOffY = fRotCenOffY; Item.Texture.ulColor = ulColor; - if ( !Item.Texture.texture ) + if ( !Item.Texture.info.d3dTexture ) return false; // Add it to the queue @@ -1002,25 +1002,25 @@ void CGraphics::DrawQueueItem ( const sDrawQueueItem& Item ) } case QUEUE_TEXTURE: { - D3DSURFACE_DESC texureDesc; - Item.Texture.texture->GetLevelDesc( 0, &texureDesc ); - float texureWidth = texureDesc.Width; - float texureHeight = texureDesc.Height; - float fRotationRad = Item.Texture.fRotation * (6.2832f/360.f); - D3DXMATRIX matrix; RECT cutImagePos; - cutImagePos.left = ( Item.Texture.fU ) * ( Item.Texture.bRelativeUV ? texureWidth : 1 ); - cutImagePos.top = ( Item.Texture.fV ) * ( Item.Texture.bRelativeUV ? texureHeight : 1 ); - cutImagePos.right = ( Item.Texture.fU + Item.Texture.fSizeU ) * ( Item.Texture.bRelativeUV ? texureWidth : 1 ); - cutImagePos.bottom = ( Item.Texture.fV + Item.Texture.fSizeV ) * ( Item.Texture.bRelativeUV ? texureHeight : 1 ); - float fCutWidth = cutImagePos.right - cutImagePos.left; - float fCutHeight = cutImagePos.bottom - cutImagePos.top; - D3DXVECTOR2 scaling ( Item.Texture.fWidth / fCutWidth, Item.Texture.fHeight / fCutHeight ); - D3DXVECTOR2 rotationCenter ( Item.Texture.fWidth * 0.5f + Item.Texture.fRotCenOffX, Item.Texture.fHeight * 0.5f + Item.Texture.fRotCenOffY ); - D3DXVECTOR2 position ( Item.Texture.fX, Item.Texture.fY ); + const float fSurfaceWidth = Item.Texture.info.uiSurfaceWidth; + const float fSurfaceHeight = Item.Texture.info.uiSurfaceHeight; + const float fFileWidth = Item.Texture.info.uiFileWidth; + const float fFileHeight = Item.Texture.info.uiFileHeight; + cutImagePos.left = ( Item.Texture.fU ) * ( Item.Texture.bRelativeUV ? fSurfaceWidth : fSurfaceWidth / fFileWidth ); + cutImagePos.top = ( Item.Texture.fV ) * ( Item.Texture.bRelativeUV ? fSurfaceHeight : fSurfaceHeight / fFileHeight ); + cutImagePos.right = ( Item.Texture.fU + Item.Texture.fSizeU ) * ( Item.Texture.bRelativeUV ? fSurfaceWidth : fSurfaceWidth / fFileWidth ); + cutImagePos.bottom = ( Item.Texture.fV + Item.Texture.fSizeV ) * ( Item.Texture.bRelativeUV ? fSurfaceHeight : fSurfaceHeight / fFileHeight ); + const float fCutWidth = cutImagePos.right - cutImagePos.left; + const float fCutHeight = cutImagePos.bottom - cutImagePos.top; + const D3DXVECTOR2 scaling ( Item.Texture.fWidth / fCutWidth, Item.Texture.fHeight / fCutHeight ); + const D3DXVECTOR2 rotationCenter ( Item.Texture.fWidth * 0.5f + Item.Texture.fRotCenOffX, Item.Texture.fHeight * 0.5f + Item.Texture.fRotCenOffY ); + const D3DXVECTOR2 position ( Item.Texture.fX, Item.Texture.fY ); + const float fRotationRad = Item.Texture.fRotation * (6.2832f/360.f); + D3DXMATRIX matrix; D3DXMatrixTransformation2D ( &matrix, NULL, 0.0f, &scaling, &rotationCenter, fRotationRad, &position ); m_pDXSprite->SetTransform ( &matrix ); - m_pDXSprite->Draw ( Item.Texture.texture, &cutImagePos, NULL, NULL, Item.Texture.ulColor ); + m_pDXSprite->Draw ( Item.Texture.info.d3dTexture, &cutImagePos, NULL, NULL, Item.Texture.ulColor ); break; } // Circle type? @@ -1033,7 +1033,7 @@ void CGraphics::DrawQueueItem ( const sDrawQueueItem& Item ) // Cache a texture for current and future use. -IDirect3DTexture9* CGraphics::CacheTexture ( const string& strFilename ) +SCachedTextureInfo& CGraphics::CacheTexture ( const string& strFilename ) { // Find exisiting map < string, SCachedTextureInfo >::iterator iter = m_CachedTextureInfoMap.find ( strFilename ); @@ -1045,13 +1045,33 @@ IDirect3DTexture9* CGraphics::CacheTexture ( const string& strFilename ) iter = m_CachedTextureInfoMap.find ( strFilename ); SCachedTextureInfo& info = iter->second; - info.texture = LoadTexture( strFilename.c_str () ); + info.d3dTexture = LoadTexture( strFilename.c_str () ); + info.uiFileWidth = 1; + info.uiFileHeight = 1; + info.uiSurfaceWidth = 1; + info.uiSurfaceHeight = 1; + + if ( info.d3dTexture ) + { + D3DXIMAGE_INFO imageInfo; + if ( SUCCEEDED ( D3DXGetImageInfoFromFile( strFilename.c_str (), &imageInfo ) ) ) + { + info.uiFileWidth = imageInfo.Width; + info.uiFileHeight = imageInfo.Height; + } + D3DSURFACE_DESC surfaceDesc; + if ( SUCCEEDED ( info.d3dTexture->GetLevelDesc( 0, &surfaceDesc ) ) ) + { + info.uiSurfaceWidth = surfaceDesc.Width; + info.uiSurfaceHeight = surfaceDesc.Height; + } + } } SCachedTextureInfo& info = iter->second; info.ulTimeLastUsed = GetTickCount(); - return info.texture; + return info; } @@ -1072,7 +1092,7 @@ void CGraphics::ExpireCachedTextures ( bool bExpireAll ) unsigned long ulAge = GetTickCount() - info.ulTimeLastUsed; if ( ulAge > ulMaxAgeSeconds * 1000 || bExpireAll ) { - SAFE_RELEASE ( info.texture ); + SAFE_RELEASE ( info.d3dTexture ); iter = m_CachedTextureInfoMap.erase ( iter ); } else diff --git a/MTA10/core/CGraphics.h b/MTA10/core/CGraphics.h index 017357f05d..381cb60d45 100644 --- a/MTA10/core/CGraphics.h +++ b/MTA10/core/CGraphics.h @@ -26,6 +26,16 @@ class CGraphics; struct IDirect3DDevice9; struct IDirect3DSurface9; +struct SCachedTextureInfo +{ + IDirect3DTexture9* d3dTexture; + unsigned long ulTimeLastUsed; + unsigned int uiSurfaceWidth; + unsigned int uiSurfaceHeight; + unsigned int uiFileWidth; + unsigned int uiFileHeight; +}; + class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > { friend class CDirect3DEvents9; @@ -138,7 +148,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > void OnDeviceCreate ( IDirect3DDevice9 * pDevice ); void OnDeviceInvalidate ( IDirect3DDevice9 * pDevice ); void OnDeviceRestore ( IDirect3DDevice9 * pDevice ); - IDirect3DTexture9* CacheTexture ( const std::string& strFilename ); + SCachedTextureInfo& CacheTexture ( const std::string& strFilename ); void ExpireCachedTextures ( bool bExpireAll = false ); ID3DXFont* GetBigFont ( ID3DXFont* pDXFont ); @@ -242,7 +252,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > struct sDrawQueueTexture { - IDirect3DTexture9* texture; + SCachedTextureInfo info; float fX; float fY; float fWidth; @@ -295,16 +305,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics > // Drawing types struct ID3DXLine* m_pLineInterface; - - // Texures cached with DrawTextureQueued - struct SCachedTextureInfo - { - IDirect3DTexture9* texture; - unsigned long ulTimeLastUsed; - }; - std::map < std::string, SCachedTextureInfo > m_CachedTextureInfoMap; - }; #endif From ab6549b3c6136f5255299b69e3453be49d999010 Mon Sep 17 00:00:00 2001 From: ccw808 Date: Mon, 19 Apr 2010 18:52:53 +0100 Subject: [PATCH 15/20] Changed player announce key from 'Score' to 'score' --- MTA10_Server/mods/deathmatch/logic/ASE.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MTA10_Server/mods/deathmatch/logic/ASE.cpp b/MTA10_Server/mods/deathmatch/logic/ASE.cpp index 0b9ed01731..018cd322d9 100644 --- a/MTA10_Server/mods/deathmatch/logic/ASE.cpp +++ b/MTA10_Server/mods/deathmatch/logic/ASE.cpp @@ -250,7 +250,7 @@ std::string ASE::QueryFull ( void ) // skin (skip) reply << ( unsigned char ) 1; // score - const std::string& strScore = pPlayer->GetAnnounceValue ( "Score" ); + const std::string& strScore = pPlayer->GetAnnounceValue ( "score" ); reply << ( unsigned char ) ( strScore.length () + 1 ); reply << strScore.c_str (); // ping From e4467e1179853ca20ba717783160bf2d92a5e65f Mon Sep 17 00:00:00 2001 From: Flobu Date: Tue, 6 Apr 2010 03:39:40 +0200 Subject: [PATCH 16/20] Added 5272: ([request] getTimer) --- .../lua/CLuaFunctionDefs.Util.cpp | 21 ++++++++++++++++++ .../mods/shared_logic/lua/CLuaFunctionDefs.h | 1 + MTA10/mods/shared_logic/lua/CLuaManager.cpp | 1 + MTA10/mods/shared_logic/lua/CLuaTimer.cpp | 8 +++++++ MTA10/mods/shared_logic/lua/CLuaTimer.h | 2 ++ .../logic/lua/CLuaFunctionDefinitions.cpp | 22 +++++++++++++++++++ .../logic/lua/CLuaFunctionDefinitions.h | 1 + .../mods/deathmatch/logic/lua/CLuaManager.cpp | 1 + .../mods/deathmatch/logic/lua/CLuaTimer.cpp | 8 +++++++ .../mods/deathmatch/logic/lua/CLuaTimer.h | 2 ++ 10 files changed, 67 insertions(+) diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp index 29d9842230..ce6a528ac2 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp @@ -233,6 +233,27 @@ int CLuaFunctionDefs::IsTimer ( lua_State* luaVM ) return 1; } +int CLuaFunctionDefs::GetTimer ( lua_State* luaVM ) +{ + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); + if ( pLuaMain ) + { + CLuaTimer* pLuaTimer = lua_totimer ( luaVM, 1 ); + if ( pLuaTimer ) + { + lua_pushnumber( luaVM, pLuaTimer->GetTimeLeft () ); + lua_pushnumber( luaVM, pLuaTimer->GetRepeats () ); + lua_pushnumber( luaVM, pLuaTimer->GetDelay () ); + return 3; + } + else + m_pScriptDebugging->LogBadType ( luaVM, "getTimer" ); + } + + lua_pushboolean ( luaVM, false ); + return 1; +} + int CLuaFunctionDefs::GetTickCount_ ( lua_State* luaVM ) { diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h index c24cde4e6f..337b286266 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h @@ -464,6 +464,7 @@ class CLuaFunctionDefs LUA_DECLARE ( ResetTimer ); LUA_DECLARE ( GetTimers ); LUA_DECLARE ( IsTimer ); + LUA_DECLARE ( GetTimer ); LUA_DECLARE ( GetTickCount_ ); LUA_DECLARE ( GetCTime ); LUA_DECLARE ( tocolor ); diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp index 598cbbdeb8..53fae01351 100644 --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp @@ -762,6 +762,7 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "killTimer", CLuaFunctionDefs::KillTimer ); CLuaCFunctions::AddFunction ( "getTimers", CLuaFunctionDefs::GetTimers ); CLuaCFunctions::AddFunction ( "isTimer", CLuaFunctionDefs::IsTimer ); + CLuaCFunctions::AddFunction ( "getTimer", CLuaFunctionDefs::GetTimer ); CLuaCFunctions::AddFunction ( "getTickCount", CLuaFunctionDefs::GetTickCount_ ); CLuaCFunctions::AddFunction ( "getRealTime", CLuaFunctionDefs::GetCTime ); CLuaCFunctions::AddFunction ( "tocolor", CLuaFunctionDefs::tocolor ); diff --git a/MTA10/mods/shared_logic/lua/CLuaTimer.cpp b/MTA10/mods/shared_logic/lua/CLuaTimer.cpp index fdbe661e4c..74e13c0bf7 100644 --- a/MTA10/mods/shared_logic/lua/CLuaTimer.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaTimer.cpp @@ -48,3 +48,11 @@ void CLuaTimer::ExecuteTimer ( CLuaMain* pLuaMain ) if ( m_iLuaFunction != LUA_REFNIL && m_pArguments ) m_pArguments->Call ( pLuaMain, m_iLuaFunction ); } + + +unsigned long CLuaTimer::GetTimeLeft ( void ) +{ + unsigned long ulCurrentTime = timeGetTime (); + unsigned long ulTimeLeft = m_ulStartTime + m_ulDelay - ulCurrentTime; + return ulTimeLeft; +} diff --git a/MTA10/mods/shared_logic/lua/CLuaTimer.h b/MTA10/mods/shared_logic/lua/CLuaTimer.h index 629866cd2a..709e49a7b7 100644 --- a/MTA10/mods/shared_logic/lua/CLuaTimer.h +++ b/MTA10/mods/shared_logic/lua/CLuaTimer.h @@ -46,6 +46,8 @@ class CLuaTimer void ExecuteTimer ( class CLuaMain* pLuaMain ); + unsigned long GetTimeLeft ( void ); + inline bool IsBeingDeleted ( void ) { return m_bBeingDeleted; } inline void SetBeingDeleted ( bool bBeingDeleted ) { m_bBeingDeleted = bBeingDeleted; } private: diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp index cf25aca5c1..75d4f956d8 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp @@ -9429,6 +9429,28 @@ int CLuaFunctionDefinitions::GetTimers ( lua_State* luaVM ) } +int CLuaFunctionDefinitions::GetTimer ( lua_State* luaVM ) +{ + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); + if ( pLuaMain ) + { + CLuaTimer* pLuaTimer = lua_totimer ( luaVM, 1 ); + if ( pLuaTimer ) + { + lua_pushnumber( luaVM, pLuaTimer->GetTimeLeft () ); + lua_pushnumber( luaVM, pLuaTimer->GetRepeats () ); + lua_pushnumber( luaVM, pLuaTimer->GetDelay () ); + return 3; + } + else + m_pScriptDebugging->LogBadType ( luaVM, "getTimer" ); + } + + lua_pushboolean ( luaVM, false ); + return 1; +} + + int CLuaFunctionDefinitions::GetColorFromString ( lua_State* luaVM ) { unsigned char ucColorRed, ucColorGreen, ucColorBlue, ucColorAlpha; diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h index 38510df99d..f696c3a4cf 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h @@ -418,6 +418,7 @@ class CLuaFunctionDefinitions static int ResetTimer ( lua_State* luaVM ); static int GetTimers ( lua_State* luaVM ); static int IsTimer ( lua_State* luaVM ); + static int GetTimer ( lua_State* luaVM ); static int GetColorFromString ( lua_State* luaVM ); static int Reference ( lua_State* luaVM ); static int Dereference ( lua_State* luaVM ); diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp index 841c83a3dc..3dd8473696 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp @@ -586,6 +586,7 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "resetTimer", CLuaFunctionDefinitions::ResetTimer ); CLuaCFunctions::AddFunction ( "getTimers", CLuaFunctionDefinitions::GetTimers ); CLuaCFunctions::AddFunction ( "isTimer", CLuaFunctionDefinitions::IsTimer ); + CLuaCFunctions::AddFunction ( "getTimer", CLuaFunctionDefinitions::GetTimer ); CLuaCFunctions::AddFunction ( "getColorFromString", CLuaFunctionDefinitions::GetColorFromString ); CLuaCFunctions::AddFunction ( "ref", CLuaFunctionDefinitions::Reference ); CLuaCFunctions::AddFunction ( "deref", CLuaFunctionDefinitions::Dereference ); diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.cpp index a344750467..97eec8a7e4 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.cpp @@ -44,3 +44,11 @@ void CLuaTimer::ExecuteTimer ( CLuaMain* pLuaMain ) m_Arguments.Call ( pLuaMain, m_iLuaFunction ); } } + + +unsigned long CLuaTimer::GetTimeLeft ( void ) +{ + unsigned long ulCurrentTime = GetTime (); + unsigned long ulTimeLeft = m_ulStartTime + m_ulDelay - ulCurrentTime; + return ulTimeLeft; +} diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.h b/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.h index dcb7479964..b37f8ce0b2 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.h +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.h @@ -46,6 +46,8 @@ class CLuaTimer void ExecuteTimer ( class CLuaMain* pLuaMain ); + unsigned long GetTimeLeft ( void ); + inline bool IsBeingDeleted ( void ) { return m_bBeingDeleted; } inline void SetBeingDeleted ( bool bBeingDeleted ) { m_bBeingDeleted = bBeingDeleted; } private: From 47392c8aeb44429c900176669da4bcbb04597211 Mon Sep 17 00:00:00 2001 From: Gamesnert Date: Tue, 20 Apr 2010 22:29:24 +0200 Subject: [PATCH 17/20] Fixed setSoundMaxDistance not having any effect whatsoever --- MTA10/mods/shared_logic/CClientSound.cpp | 7 ++++--- MTA10/mods/shared_logic/CClientSound.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MTA10/mods/shared_logic/CClientSound.cpp b/MTA10/mods/shared_logic/CClientSound.cpp index 82aded483e..beb79ec16b 100644 --- a/MTA10/mods/shared_logic/CClientSound.cpp +++ b/MTA10/mods/shared_logic/CClientSound.cpp @@ -30,6 +30,7 @@ CClientSound::CClientSound ( CClientManager* pManager, ElementID ID ) : CClientE m_fVolume = 1.0f; m_fSpeed = 1.0f; m_fMinDistance = 2.0f; + m_fMaxDistance = 10.0f; m_usDimension = 0; m_b3D = false; } @@ -211,6 +212,7 @@ float CClientSound::GetMinDistance ( void ) void CClientSound::SetMaxDistance ( float fDistance ) { + m_fMaxDistance = fDistance; if ( m_pSound ) { m_pSound->setMaxDistance ( fDistance ); @@ -255,20 +257,19 @@ void CClientSound::Process3D ( CVector vecPosition, CVector vecLookAt ) // Volume float fDistance = DistanceBetweenPoints3D ( vecPosition, m_vecPosition ); - float fSilenceDistance = m_fMinDistance * 20.0f; float fVolume = 1.0; if ( fDistance <= m_fMinDistance ) { fVolume = 1.0f; } - else if ( fDistance >= fSilenceDistance ) + else if ( fDistance >= m_fMaxDistance ) { fVolume = 0.0f; } else { - float fLinear = (fSilenceDistance - fDistance) / fSilenceDistance; + float fLinear = (m_fMaxDistance - fDistance) / m_fMaxDistance; fVolume = sqrt ( fLinear ) * fLinear; } diff --git a/MTA10/mods/shared_logic/CClientSound.h b/MTA10/mods/shared_logic/CClientSound.h index a0183c53a0..a533d2f973 100644 --- a/MTA10/mods/shared_logic/CClientSound.h +++ b/MTA10/mods/shared_logic/CClientSound.h @@ -79,6 +79,7 @@ class CClientSound : public CClientEntity float m_fVolume; float m_fSpeed; float m_fMinDistance; + float m_fMaxDistance; CVector m_vecPosition; From fe5d17e577c4cfdca38a7fae4f72385a7a62344f Mon Sep 17 00:00:00 2001 From: ccw808 Date: Fri, 23 Apr 2010 07:53:06 +0100 Subject: [PATCH 18/20] Simplified setElementSyncer() arguments. Fixed getElementSyncer() --- .../deathmatch/logic/CStaticFunctionDefinitions.cpp | 4 ++-- .../deathmatch/logic/luadefs/CLuaElementDefs.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 78e586efbc..9d78b39aed 100644 --- a/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -779,13 +779,13 @@ CElement* CStaticFunctionDefinitions::GetElementSyncer ( CElement* pElement ) case CElement::PED: { CPed* pPed = static_cast < CPed* > ( pElement ); - return static_cast < CElement* > ( pPed->GetSyncer() ); + return pPed->IsSyncable () ? static_cast < CElement* > ( pPed->GetSyncer() ) : NULL; break; } case CElement::VEHICLE: { CVehicle* pVehicle = static_cast < CVehicle* > ( pElement ); - return static_cast < CElement* > ( pVehicle->GetSyncer() ); + return pVehicle->IsUnoccupiedSyncable () ? static_cast < CElement* > ( pVehicle->GetSyncer() ) : NULL; break; } } diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 966911aa2f..f0b93c3be6 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -1674,18 +1674,20 @@ int CLuaElementDefs::setElementModel ( lua_State* luaVM ) int CLuaElementDefs::setElementSyncer ( lua_State* luaVM ) { int iArgument2 = lua_type ( luaVM, 2 ); - if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA && ( iArgument2 == LUA_TLIGHTUSERDATA || iArgument2 == LUA_TNIL ) ) + if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA && ( iArgument2 == LUA_TLIGHTUSERDATA || iArgument2 == LUA_TBOOLEAN ) ) { CElement* pElement = lua_toelement ( luaVM, 1 ); - CPlayer* pPlayer = lua_toplayer ( luaVM, 2 ); + CPlayer* pPlayer = NULL; bool bEnable = true; - if ( lua_type ( luaVM, 3 ) == LUA_TBOOLEAN ) - bEnable = lua_toboolean ( luaVM, 3 ) ? true : false; + if ( iArgument2 == LUA_TLIGHTUSERDATA ) + pPlayer = lua_toplayer ( luaVM, 2 ); + if ( iArgument2 == LUA_TBOOLEAN ) + bEnable = lua_toboolean ( luaVM, 2 ) ? true : false; if ( pElement ) { - if ( pPlayer || iArgument2 == LUA_TNIL ) + if ( pPlayer || iArgument2 == LUA_TBOOLEAN ) { lua_pushboolean ( luaVM, CStaticFunctionDefinitions::SetElementSyncer ( pElement, pPlayer, bEnable ) ); return 1; From 6f0f560f78772bd9d6eef544771e994fcc89582b Mon Sep 17 00:00:00 2001 From: Flobu Date: Fri, 23 Apr 2010 15:02:49 +0200 Subject: [PATCH 19/20] Rename getTimer to getTimerDetails --- MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp | 4 ++-- MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h | 2 +- MTA10/mods/shared_logic/lua/CLuaManager.cpp | 2 +- .../mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp | 4 ++-- .../mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h | 2 +- MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp index ce6a528ac2..d15c2deb09 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp @@ -233,7 +233,7 @@ int CLuaFunctionDefs::IsTimer ( lua_State* luaVM ) return 1; } -int CLuaFunctionDefs::GetTimer ( lua_State* luaVM ) +int CLuaFunctionDefs::GetTimerDetails ( lua_State* luaVM ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) @@ -247,7 +247,7 @@ int CLuaFunctionDefs::GetTimer ( lua_State* luaVM ) return 3; } else - m_pScriptDebugging->LogBadType ( luaVM, "getTimer" ); + m_pScriptDebugging->LogBadType ( luaVM, "getTimerDetails" ); } lua_pushboolean ( luaVM, false ); diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h index 337b286266..4e90078b5c 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h @@ -464,7 +464,7 @@ class CLuaFunctionDefs LUA_DECLARE ( ResetTimer ); LUA_DECLARE ( GetTimers ); LUA_DECLARE ( IsTimer ); - LUA_DECLARE ( GetTimer ); + LUA_DECLARE ( GetTimerDetails ); LUA_DECLARE ( GetTickCount_ ); LUA_DECLARE ( GetCTime ); LUA_DECLARE ( tocolor ); diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp index 53fae01351..86bfc43518 100644 --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp @@ -762,7 +762,7 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "killTimer", CLuaFunctionDefs::KillTimer ); CLuaCFunctions::AddFunction ( "getTimers", CLuaFunctionDefs::GetTimers ); CLuaCFunctions::AddFunction ( "isTimer", CLuaFunctionDefs::IsTimer ); - CLuaCFunctions::AddFunction ( "getTimer", CLuaFunctionDefs::GetTimer ); + CLuaCFunctions::AddFunction ( "getTimerDetails", CLuaFunctionDefs::GetTimerDetails ); CLuaCFunctions::AddFunction ( "getTickCount", CLuaFunctionDefs::GetTickCount_ ); CLuaCFunctions::AddFunction ( "getRealTime", CLuaFunctionDefs::GetCTime ); CLuaCFunctions::AddFunction ( "tocolor", CLuaFunctionDefs::tocolor ); diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp index 75d4f956d8..13f6f398e5 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp @@ -9429,7 +9429,7 @@ int CLuaFunctionDefinitions::GetTimers ( lua_State* luaVM ) } -int CLuaFunctionDefinitions::GetTimer ( lua_State* luaVM ) +int CLuaFunctionDefinitions::GetTimerDetails ( lua_State* luaVM ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) @@ -9443,7 +9443,7 @@ int CLuaFunctionDefinitions::GetTimer ( lua_State* luaVM ) return 3; } else - m_pScriptDebugging->LogBadType ( luaVM, "getTimer" ); + m_pScriptDebugging->LogBadType ( luaVM, "getTimerDetails" ); } lua_pushboolean ( luaVM, false ); diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h index f696c3a4cf..b031d3fd42 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.h @@ -418,7 +418,7 @@ class CLuaFunctionDefinitions static int ResetTimer ( lua_State* luaVM ); static int GetTimers ( lua_State* luaVM ); static int IsTimer ( lua_State* luaVM ); - static int GetTimer ( lua_State* luaVM ); + static int GetTimerDetails ( lua_State* luaVM ); static int GetColorFromString ( lua_State* luaVM ); static int Reference ( lua_State* luaVM ); static int Dereference ( lua_State* luaVM ); diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp index 3dd8473696..df5d2ed8f6 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp @@ -586,7 +586,7 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "resetTimer", CLuaFunctionDefinitions::ResetTimer ); CLuaCFunctions::AddFunction ( "getTimers", CLuaFunctionDefinitions::GetTimers ); CLuaCFunctions::AddFunction ( "isTimer", CLuaFunctionDefinitions::IsTimer ); - CLuaCFunctions::AddFunction ( "getTimer", CLuaFunctionDefinitions::GetTimer ); + CLuaCFunctions::AddFunction ( "getTimerDetails", CLuaFunctionDefinitions::GetTimerDetails ); CLuaCFunctions::AddFunction ( "getColorFromString", CLuaFunctionDefinitions::GetColorFromString ); CLuaCFunctions::AddFunction ( "ref", CLuaFunctionDefinitions::Reference ); CLuaCFunctions::AddFunction ( "deref", CLuaFunctionDefinitions::Dereference ); From 66c06ef4db75de13b07b85468d0c54f1b89ccc3d Mon Sep 17 00:00:00 2001 From: Flobu Date: Sat, 24 Apr 2010 05:12:23 +0200 Subject: [PATCH 20/20] Added 5267: ([Request and Patch] serverside set/getElementRotation) --- .../logic/CStaticFunctionDefinitions.cpp | 7 +- MTA10/mods/shared_logic/CClientPed.cpp | 5 ++ .../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, 161 insertions(+), 3 deletions(-) diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index b6d23199bf..8c888a20e8 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -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: diff --git a/MTA10/mods/shared_logic/CClientPed.cpp b/MTA10/mods/shared_logic/CClientPed.cpp index 26be23d5a2..872b911928 100644 --- a/MTA10/mods/shared_logic/CClientPed.cpp +++ b/MTA10/mods/shared_logic/CClientPed.cpp @@ -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 ); } 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 9d78b39aed..c44ae6ddff 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 6d60730070..058e9acdf9 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 f0b93c3be6..fa775c1eb7 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 ); @@ -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 @@ -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 diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index da27a62b22..ac4ba45eca 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 );