Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d358a4a
Events for server-side
Nico8340 Mar 30, 2024
91ad6d1
Events for client-side
Nico8340 Mar 30, 2024
c5d9a9c
Modify returns
Nico8340 Apr 3, 2024
463a385
Modify BitStream version
Nico8340 Apr 3, 2024
1daa79e
Merge branch 'master' into attach
Nico8340 Apr 3, 2024
1b85d92
Format & early returns
Nico8340 Apr 3, 2024
1a562d3
Merge branch 'attach' of https://github.com/Nico8340/mtasa-blue into …
Nico8340 Apr 3, 2024
0a94a1b
Merge branch 'master' into attach
Dutchman101 Apr 5, 2024
842dbdd
Merge branch 'master' into attach
Nico8340 Jun 1, 2024
75e6439
Merge branch 'master' into attach
Nico8340 Jun 2, 2024
3895d00
Merge branch 'master' into attach
Nico8340 Jun 5, 2024
2fddd18
Merge branch 'multitheftauto:master' into attach
Nico8340 Jun 6, 2024
4047184
Merge branch 'master' into attach
Nico8340 Jul 15, 2024
95280d6
Merge branch 'master' into attach
Nico8340 Aug 20, 2024
307d6ca
Merge branch 'master' into attach
Nico8340 Nov 21, 2024
26496f2
Merge branch 'master' into attach
Nico8340 Jan 6, 2025
cfdede2
Merge branch 'multitheftauto:master' into attach
Nico8340 Jan 16, 2025
0936201
Merge branch 'master' into attach
Nico8340 Feb 9, 2025
e5c06fd
Merge branch 'master' into attach
Nico8340 May 6, 2025
e254ad9
Merge branch 'master' into attach
Nico8340 May 8, 2025
e3c84aa
Merge branch 'master' into attach
Nico8340 May 31, 2025
09d6d3c
Merge branch 'master' into attach
Nico8340 Jun 4, 2025
f166f04
Merge branch 'master' into attach
Nico8340 Jul 15, 2025
ffef640
Merge branch 'master' into attach
Nico8340 Jul 28, 2025
9bfd7dc
Fix source code
botder Jul 31, 2025
3fe05ed
Merge branch 'master' into attach
botder Jul 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,8 @@ void CClientGame::AddBuiltInEvents()
m_Events.AddEvent("onClientElementModelChange", "oldModel, newModel", nullptr, false);
m_Events.AddEvent("onClientElementDimensionChange", "oldDimension, newDimension", nullptr, false);
m_Events.AddEvent("onClientElementInteriorChange", "oldInterior, newInterior", nullptr, false);
m_Events.AddEvent("onClientElementAttach", "attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ", nullptr, false);
m_Events.AddEvent("onClientElementDetach", "detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ", nullptr, false);

// Player events
m_Events.AddEvent("onClientPlayerJoin", "", NULL, false);
Expand Down
35 changes: 35 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,20 @@ bool CStaticFunctionDefinitions::AttachElements(CClientEntity& Entity, CClientEn
if (Entity.IsAttachToable() && AttachedToEntity.IsAttachable() && !AttachedToEntity.IsAttachedToElement(&Entity) &&
Entity.GetDimension() == AttachedToEntity.GetDimension())
{
CLuaArguments Arguments;
Arguments.PushElement(&AttachedToEntity);
Arguments.PushNumber(vecPosition.fX);
Arguments.PushNumber(vecPosition.fY);
Arguments.PushNumber(vecPosition.fZ);
Arguments.PushNumber(vecRotation.fX);
Arguments.PushNumber(vecRotation.fY);
Arguments.PushNumber(vecRotation.fZ);
bool bContinue = Entity.CallEvent("onClientElementAttach", Arguments, true);

if (!bContinue) {
return false;
}

ConvertDegreesToRadians(vecRotation);

Entity.SetAttachedOffsets(vecPosition, vecRotation);
Expand All @@ -1387,6 +1401,27 @@ bool CStaticFunctionDefinitions::DetachElements(CClientEntity& Entity, CClientEn
{
if (pAttachedToEntity == NULL || pActualAttachedToEntity == pAttachedToEntity)
{
CVector vecPosition;
CVector vecRotation;

Entity.GetPosition(vecPosition);
Entity.GetRotationDegrees(vecRotation);

CLuaArguments Arguments;
Arguments.PushElement(pActualAttachedToEntity);
Arguments.PushNumber(vecPosition.fX);
Arguments.PushNumber(vecPosition.fY);
Arguments.PushNumber(vecPosition.fZ);
Arguments.PushNumber(vecRotation.fX);
Arguments.PushNumber(vecRotation.fY);
Arguments.PushNumber(vecRotation.fZ);
bool bContinue = Entity.CallEvent("onClientElementDetach", Arguments, true);

if (!bContinue)
{
return false;
}

Entity.AttachTo(NULL);
return true;
}
Expand Down
62 changes: 56 additions & 6 deletions Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,25 @@ void CElementRPCs::AttachElements(CClientEntity* pSource, NetBitStreamInterface&
CClientEntity* pAttachedToEntity = CElementIDs::GetElement(usAttachedToID);
if (pAttachedToEntity)
{
pSource->SetAttachedOffsets(vecPosition, vecRotation);
pSource->AttachTo(pAttachedToEntity);
ConvertRadiansToDegrees(vecRotation);

CLuaArguments Arguments;
Arguments.PushElement(pAttachedToEntity);
Arguments.PushNumber(vecPosition.fX);
Arguments.PushNumber(vecPosition.fY);
Arguments.PushNumber(vecPosition.fZ);
Arguments.PushNumber(vecRotation.fX);
Arguments.PushNumber(vecRotation.fY);
Arguments.PushNumber(vecRotation.fZ);
bool bContinue = pSource->CallEvent("onClientElementAttach", Arguments, true);

if (bContinue)
{
ConvertDegreesToRadians(vecRotation);

pSource->SetAttachedOffsets(vecPosition, vecRotation);
pSource->AttachTo(pAttachedToEntity);
}
}
}
}
Expand All @@ -332,13 +349,46 @@ void CElementRPCs::DetachElements(CClientEntity* pSource, NetBitStreamInterface&
unsigned char ucTimeContext;
if (bitStream.Read(ucTimeContext))
{
pSource->SetSyncTimeContext(ucTimeContext);
pSource->AttachTo(NULL);
ElementID usAttachedToID;
CClientEntity* pAttachedToEntity = CElementIDs::GetElement(usAttachedToID);

CVector vecPosition;
if (bitStream.Read(vecPosition.fX) && bitStream.Read(vecPosition.fY) && bitStream.Read(vecPosition.fZ))
CVector vecRotation;

bitStream.Read(vecPosition.fX);
bitStream.Read(vecPosition.fY);
bitStream.Read(vecPosition.fZ);

bitStream.Read(vecRotation.fX);
bitStream.Read(vecRotation.fY);
bitStream.Read(vecRotation.fZ);

CLuaArguments Arguments;
Arguments.PushElement(pAttachedToEntity);
Arguments.PushNumber(vecPosition.fX);
Arguments.PushNumber(vecPosition.fY);
Arguments.PushNumber(vecPosition.fZ);

Arguments.PushNumber(vecRotation.fX);
Arguments.PushNumber(vecRotation.fY);
Arguments.PushNumber(vecRotation.fZ);

bool bContinue = pSource->CallEvent("onClientElementDetach", Arguments, true);

if (bContinue)
{
pSource->SetPosition(vecPosition);
pSource->SetSyncTimeContext(ucTimeContext);
pSource->AttachTo(NULL);

if (vecPosition.fX != 0.0f || vecPosition.fY != 0.0f || vecPosition.fZ != 0.0f)
{
pSource->SetPosition(vecPosition);
}

if (vecRotation.fX != 0.0f || vecRotation.fY != 0.0f || vecRotation.fZ != 0.0f)
{
pSource->SetRotationDegrees(vecRotation);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,8 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onElementModelChange", "oldModel, newModel", NULL, false);
m_Events.AddEvent("onElementDimensionChange", "oldDimension, newDimension", nullptr, false);
m_Events.AddEvent("onElementInteriorChange", "oldInterior, newInterior", nullptr, false);
m_Events.AddEvent("onElementAttach", "attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ", nullptr, false);
m_Events.AddEvent("onElementDetach", "detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ", nullptr, false);

// Radar area events

Expand Down
43 changes: 41 additions & 2 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,8 +1518,24 @@ bool CStaticFunctionDefinitions::AttachElements(CElement* pElement, CElement* pA
if (pElement->IsAttachToable() && pAttachedToElement->IsAttachable() && !pAttachedToElement->IsAttachedToElement(pElement) &&
pElement->GetDimension() == pAttachedToElement->GetDimension())
{
pElement->SetAttachedOffsets(vecPosition, vecRotation);
CLuaArguments Arguments;
Arguments.PushElement(pAttachedToElement);
Arguments.PushNumber(vecPosition.fX);
Arguments.PushNumber(vecPosition.fY);
Arguments.PushNumber(vecPosition.fZ);
Arguments.PushNumber(vecRotation.fX);
Arguments.PushNumber(vecRotation.fY);
Arguments.PushNumber(vecRotation.fZ);
bool bContinue = pElement->CallEvent("onElementAttach", Arguments);

if (!bContinue)
{
return false;
}

ConvertDegreesToRadians(vecRotation);

pElement->SetAttachedOffsets(vecPosition, vecRotation);
pElement->AttachTo(pAttachedToElement);

CBitStream BitStream;
Expand Down Expand Up @@ -1547,9 +1563,29 @@ bool CStaticFunctionDefinitions::DetachElements(CElement* pElement, CElement* pA
{
if (pAttachedToElement == NULL || pActualAttachedToElement == pAttachedToElement)
{
CVector vecPosition = pElement->GetPosition();
CVector vecRotation;

pElement->GetRotation(vecRotation);
ConvertRadiansToDegrees(vecRotation);

CLuaArguments Arguments;
Arguments.PushElement(pActualAttachedToElement);
Arguments.PushNumber(vecPosition.fX);
Arguments.PushNumber(vecPosition.fY);
Arguments.PushNumber(vecPosition.fZ);
Arguments.PushNumber(vecRotation.fX);
Arguments.PushNumber(vecRotation.fY);
Arguments.PushNumber(vecRotation.fZ);
bool bContinue = pElement->CallEvent("onElementDetach", Arguments);

if (!bContinue)
{
return false;
}

// Detach it. Also generate a new time context to prevent sync screwup from
// old packes arriving.
CVector vecPosition = pElement->GetPosition();
pElement->AttachTo(NULL);
pElement->GenerateSyncTimeContext();

Expand All @@ -1558,6 +1594,9 @@ bool CStaticFunctionDefinitions::DetachElements(CElement* pElement, CElement* pA
BitStream.pBitStream->Write(vecPosition.fX);
BitStream.pBitStream->Write(vecPosition.fY);
BitStream.pBitStream->Write(vecPosition.fZ);
BitStream.pBitStream->Write(vecRotation.fX);
BitStream.pBitStream->Write(vecRotation.fY);
BitStream.pBitStream->Write(vecRotation.fZ);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pElement, DETACH_ELEMENTS, *BitStream.pBitStream));

return true;
Expand Down