Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions MTA10/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,11 @@ void CClientGame::UpdateFireKey ( void )
Arguments.PushElement ( pTargetPed );
if ( m_pLocalPlayer->CallEvent ( "onClientPlayerStealthKill", Arguments, false ) )
{
if ( pTargetPed->IsLocalEntity () ) {
CStaticFunctionDefinitions::KillPed ( *pTargetPed, m_pLocalPlayer, 4 /*WEAPONTYPE_KNIFE*/, 9/*BODYPART_HEAD*/, true );
return;
}

// Lets request a stealth kill
CBitStream bitStream;
bitStream.pBitStream->Write ( pTargetPed->GetID () );
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ void CPacketHandler::Packet_PlayerWasted ( NetBitStreamInterface& bitStream )
// Caz: Issue 8148 - Desync when calling spawnPlayer from an event handler remotely triggered from within onClientPlayerWasted

// Is this a stealth kill? and do we have a killer ped?
// TODO: Make things dry. Refer to CStaticFunctionDefinitions:KillPed
if ( bStealth && pKiller && IS_PED ( pKiller ) )
{
// Make our killer ped do the stealth kill animation
Expand Down
52 changes: 52 additions & 0 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,58 @@ bool CStaticFunctionDefinitions::SetPlayerNametagShowing ( CClientEntity& Entity
return false;
}

bool CStaticFunctionDefinitions::KillPed ( CClientEntity& Entity, CClientEntity* pKiller = NULL, unsigned char ucKillerWeapon = 0xFF, unsigned char ucBodyPart = 0xFF, bool bStealth = false )
{
RUN_CHILDREN ( KillPed ( **iter, pKiller, ucKillerWeapon, ucBodyPart ) )

if ( !IS_PED ( &Entity ) )
{
return false;
}

CClientPed& pPed = static_cast < CClientPed& > ( Entity );

// Is the ped alive and a local entity?
if ( pPed.IsDead () || !pPed.IsLocalEntity() )
{
return false;
}

// Remove him from any occupied vehicle
pPed.SetVehicleInOutState ( VEHICLE_INOUT_NONE );
pPed.RemoveFromVehicle ();

// Is this a stealth kill? and do we have a killer ped?
// TODO: Make things dry. Refer to CPacketHandler::Packet_PlayerWasted
if ( bStealth && pKiller && IS_PED ( pKiller ) )
{
// Make our killer ped do the stealth kill animation
CClientPed* pKillerPed = static_cast < CClientPed * > ( pKiller );
pKillerPed->StealthKill ( &pPed );
}

// Kill the ped
pPed.Kill ( (eWeaponType) ucKillerWeapon,
ucBodyPart,
bStealth, false, 0, 15 );
// magic numbers 0, 15 found from CPlayerWastedPacket

// Tell our scripts the ped has died
CLuaArguments Arguments;
if ( pKiller ) Arguments.PushElement ( pKiller );
else Arguments.PushBoolean ( false );
if ( ucKillerWeapon != 0xFF ) Arguments.PushNumber ( ucKillerWeapon );
else Arguments.PushBoolean ( false );
if ( ucBodyPart != 0xFF ) Arguments.PushNumber ( ucBodyPart );
else Arguments.PushBoolean ( false );
Arguments.PushBoolean ( bStealth );

pPed.CallEvent ( "onClientPedWasted", Arguments, false );
pPed.RemoveAllWeapons ();

return true;
}


bool CStaticFunctionDefinitions::SetPedRotation ( CClientEntity& Entity, float fRotation, bool bNewWay )
{
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class CStaticFunctionDefinitions

// Ped funcs
static CClientPed* CreatePed ( CResource& Resource, unsigned long ulModel, const CVector& vecPosition, float fRotation );
static bool KillPed ( CClientEntity& Entity, CClientEntity* pKiller, unsigned char ucKillerWeapon, unsigned char ucBodyPart, bool bStealth );

static CClientEntity* GetPedTarget ( CClientPed& Ped );
static bool GetPedTargetCollision ( CClientPed& Ped, CVector& vecOrigin );
Expand Down
37 changes: 37 additions & 0 deletions MTA10/mods/shared_logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
void CLuaPedDefs::LoadFunctions ( void ) {
CLuaCFunctions::AddFunction ( "createPed", CreatePed );
CLuaCFunctions::AddFunction ( "detonateSatchels", DetonateSatchels );
CLuaCFunctions::AddFunction ( "killPed", KillPed );

CLuaCFunctions::AddFunction ( "getPedVoice", GetPedVoice );
CLuaCFunctions::AddFunction ( "setPedVoice", SetPedVoice );
Expand Down Expand Up @@ -90,6 +91,7 @@ void CLuaPedDefs::AddClass ( lua_State* luaVM )
lua_newclass ( luaVM );

lua_classfunction ( luaVM, "create", "createPed" );
lua_classfunction ( luaVM, "kill", "killPed" );

lua_classfunction ( luaVM, "getBodyPartName", "getBodyPartName" );
lua_classfunction ( luaVM, "getClothesTypeName", "getClothesTypeName" );
Expand Down Expand Up @@ -2078,6 +2080,41 @@ int CLuaPedDefs::SetPedAimTarget ( lua_State* luaVM )
}


int CLuaPedDefs::KillPed ( lua_State* luaVM )
{
CClientEntity* pEntity = NULL;
CClientEntity *pKiller = NULL;
unsigned char ucKillerWeapon;
unsigned char ucBodyPart;
bool bStealth;

CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pEntity );
argStream.ReadUserData ( pKiller, NULL );
argStream.ReadNumber ( ucKillerWeapon, 0xFF );
argStream.ReadNumber ( ucBodyPart, 0xFF );
argStream.ReadBool ( bStealth, false );

if ( !argStream.HasErrors () )
if ( !pEntity->IsLocalEntity () )
argStream.SetCustomError ( "This client side function will only work with client created peds" );

if ( !argStream.HasErrors () )
{
if ( CStaticFunctionDefinitions::KillPed ( *pEntity, pKiller, ucKillerWeapon, ucBodyPart, bStealth ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

lua_pushboolean ( luaVM, false );
return 1;
}


int CLuaPedDefs::SetPedRotation ( lua_State* luaVM )
{
// setPedRotation ( element ped, float rotation [, bool fixPedRotation = false ] )
Expand Down
2 changes: 1 addition & 1 deletion MTA10/mods/shared_logic/luadefs/CLuaPedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CLuaPedDefs : public CLuaDefs
static void AddClass ( lua_State* luaVM );

LUA_DECLARE ( CreatePed );

LUA_DECLARE ( KillPed );
LUA_DECLARE ( DetonateSatchels );

LUA_DECLARE ( GetPedVoice );
Expand Down