Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPlayerTeamChange Event #3370

Merged
merged 13 commits into from
May 23, 2024
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerProjectileCreation", "weaponType, posX, posY, posZ, force, target, rotX, rotY, rotZ, velX, velY, velZ", nullptr, false);
m_Events.AddEvent("onPlayerDetonateSatchels", "", nullptr, false);
m_Events.AddEvent("onPlayerTriggerEventThreshold", "", nullptr, false);
m_Events.AddEvent("onPlayerTeamChange", "oldTeam, newTeam", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down
14 changes: 12 additions & 2 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9203,13 +9203,23 @@ bool CStaticFunctionDefinitions::SetTeamColor(CTeam* pTeam, unsigned char ucRed,
bool CStaticFunctionDefinitions::SetPlayerTeam(CPlayer* pPlayer, CTeam* pTeam)
{
assert(pPlayer);

CTeam* currentTeam = pPlayer->GetTeam();
esmail9900 marked this conversation as resolved.
Show resolved Hide resolved
// If its a different team
if (pTeam != pPlayer->GetTeam())
if (pTeam != currentTeam)
{
// Change his team
pPlayer->SetTeam(pTeam, true);

// Call the Event
CLuaArguments Arguments;
if (currentTeam){
Arguments.PushString(currentTeam->GetTeamName());
} else {
Arguments.PushBoolean(false);
}
Arguments.PushString(pTeam->GetTeamName());
pPlayer->CallEvent("onPlayerTeamChange", Arguments);

esmail9900 marked this conversation as resolved.
Show resolved Hide resolved
// Tell everyone his new team
CBitStream BitStream;
BitStream.pBitStream->Write(pTeam ? pTeam->GetID() : INVALID_ELEMENT_ID);
Expand Down