SA-MP/saco/game/playerped.cpp

343 lines
7.5 KiB
C++
Raw Normal View History

2024-02-15 22:23:36 +08:00
#include "../main.h"
#include "util.h"
#include "keystuff.h"
#include "task.h"
extern CGame *pGame;
extern BYTE *pbyteCurrentPlayer;
2024-02-15 22:23:36 +08:00
//-----------------------------------------------------------
// Used for instancing the local player.
CPlayerPed::CPlayerPed()
{
m_dwGTAId = 1; // 0x001
m_pPed = GamePool_FindPlayerPed();
m_pEntity = (ENTITY_TYPE *)GamePool_FindPlayerPed();
m_bytePlayerNumber = 0;
SetPlayerPedPtrRecord(m_bytePlayerNumber,(DWORD)m_pPed);
ScriptCommand(&set_actor_weapon_droppable,m_dwGTAId,1);
ScriptCommand(&set_actor_can_be_decapitated,m_dwGTAId,0);
field_2A8 = 1;
field_2AC = 1;
m_dwArrow = 0;
2024-02-15 22:23:36 +08:00
field_2B9 = 0;
field_2F2 = 0;
field_2D2 = 0;
field_2DE = 0;
field_2E2 = 0;
field_48 = 0;
m_bGoggleState = FALSE;
2024-02-15 22:23:36 +08:00
field_2C1 = 0;
field_2C5 = 0;
field_2C9 = 0;
field_2F6 = 0;
field_2F7 = 0;
field_2F8 = 0;
int x=0;
while(x!=10) {
field_4C[x];
field_27C[x] = 0;
memset(&field_74[x], 0, sizeof(struc_97));
x++;
}
field_2F9 = 0;
}
//-----------------------------------------------------------
// If the game has internally destroyed the ped
// during this frame, the ped pointer should become 0
void CPlayerPed::ResetPointers()
{
m_pPed = GamePool_Ped_GetAt(m_dwGTAId);
m_pEntity = (ENTITY_TYPE *)m_pPed;
}
//-----------------------------------------------------------
void CPlayerPed::SetInitialState()
{
DWORD dwPedPtr = (DWORD)m_pPed;
//int iPlayerNumber = 0;
//DWORD dwPlayerActorID = 0;
_asm push 0
_asm mov ecx, dwPedPtr
_asm mov edx, 0x60CD20 ; internal_CPlayerPed_SetInitialState
_asm call edx
/* DESTROY METHOD
_asm mov ecx, dwPedPtr
_asm mov ebx, [ecx] ; vtable
_asm push 1
_asm call [ebx] ; destroy
*/
// CREATE PLAYER
/*
ScriptCommand(&create_player, &iPlayerNumber, x, y, z, &dwPlayerActorID);
ScriptCommand(&create_actor_from_player,&iPlayerNumber,&dwPlayerActorID);
m_dwGTAId = dwPlayerActorID;
m_pPed = GamePool_Ped_GetAt(m_dwGTAId);
m_bytePlayerNumber = 0;
m_pEntity = (ENTITY_TYPE *)GamePool_Ped_GetAt(m_dwGTAId);
*/
}
//-----------------------------------------------------------
BYTE CPlayerPed::GetSpecialKey()
{
GTA_CONTROLSET *pInternalKeys = GameGetInternalKeys();
if(pInternalKeys->wKeys1[11]) // yes
return 1;
else if(pInternalKeys->wKeys1[10]) // no
return 2;
else if(pInternalKeys->wKeys1[9]) // honk
return 3;
return 0;
}
//-----------------------------------------------------------
CAMERA_AIM * CPlayerPed::GetCurrentAim()
{
return GameGetInternalAim();
}
//-----------------------------------------------------------
void CPlayerPed::SetCurrentAim(CAMERA_AIM *pAim)
{
GameStoreRemotePlayerAim(m_bytePlayerNumber, pAim);
}
//-----------------------------------------------------------
BYTE CPlayerPed::GetCurrentWeapon()
{
if(!m_pPed) return 0;
if(GamePool_Ped_GetAt(m_dwGTAId) == 0) return 0;
DWORD dwRetVal;
ScriptCommand(&get_actor_armed_weapon,m_dwGTAId,&dwRetVal);
return (BYTE)dwRetVal;
}
//-----------------------------------------------------------
int CPlayerPed::GetCurrentVehicleID()
{
if(!m_pPed) return 0;
VEHICLE_TYPE *pVehicle = (VEHICLE_TYPE *)m_pPed->pVehicle;
return GamePool_Vehicle_GetIndex(pVehicle);
}
//-----------------------------------------------------------
void CPlayerPed::HideMarker()
{
if (m_dwArrow) ScriptCommand(&disable_marker, m_dwArrow);
m_dwArrow = NULL; // Just make sure
}
//-----------------------------------------------------------
BOOL CPlayerPed::IsOnScreen()
{
if(m_pPed) return GameIsEntityOnScreen((DWORD *)m_pPed);
return FALSE;
}
//-----------------------------------------------------------
void CPlayerPed::SetImmunities(BOOL bBullet, BOOL bFire, BOOL bExplosion, BOOL bDamage, BOOL bUnknown)
{
if(!m_pPed) return;
if(GamePool_Ped_GetAt(m_dwGTAId) == 0) return;
ScriptCommand(&set_actor_immunities, m_dwGTAId, bBullet, bFire, bExplosion, bDamage, bUnknown);
}
//-----------------------------------------------------------
void CPlayerPed::GiveWeapon(int iWeaponID, int iAmmo)
{
if(!m_pPed) return;
if(!GamePool_Ped_GetAt(m_dwGTAId)) return;
int iModelID = 0;
iModelID = GameGetWeaponModelIDFromWeaponID(iWeaponID);
if(iModelID == -1) return;
if(!pGame->IsModelLoaded(iModelID)) {
pGame->RequestModel(iModelID);
pGame->LoadRequestedModels();
while(!pGame->IsModelLoaded(iModelID)) Sleep(1);
}
//ScriptCommand(&give_actor_weapon,this->m_dwGTAId,iWeaponID,iAmmo);
*pbyteCurrentPlayer = m_bytePlayerNumber;
GameStoreLocalPlayerWeaponSkills();
GameSetRemotePlayerWeaponSkills(m_bytePlayerNumber);
DWORD dwPedPtr = (DWORD)m_pPed;
_asm mov ecx, dwPedPtr
_asm push 1
_asm push iAmmo
_asm push iWeaponID
_asm mov edx, 0x5E6080
_asm call edx
GameSetLocalPlayerWeaponSkills();
SetArmedWeapon(iWeaponID, false);
*pbyteCurrentPlayer = 0;
//pGame->RemoveModel(iModelID);
}
2024-02-15 22:23:36 +08:00
//-----------------------------------------------------------
void CPlayerPed::SetArmedWeapon(int iWeaponType, bool bUnk)
{
if(!m_pPed) return;
if(!GamePool_Ped_GetAt(m_dwGTAId)) return;
*pbyteCurrentPlayer = m_bytePlayerNumber;
GameStoreLocalPlayerWeaponSkills();
GameSetRemotePlayerWeaponSkills(m_bytePlayerNumber);
if(m_pPed && IN_VEHICLE(m_pPed) || bUnk)
{
DWORD dwPedPtr = (DWORD)m_pPed;
if(dwPedPtr) {
_asm mov ecx, dwPedPtr
_asm push iWeaponType
_asm mov edx, 0x5E6280
_asm call edx
}
}
else
ScriptCommand(&set_actor_armed_weapon,m_dwGTAId,iWeaponType);
GameSetLocalPlayerWeaponSkills();
*pbyteCurrentPlayer = 0;
}
//-----------------------------------------------------------
WEAPON_SLOT_TYPE * CPlayerPed::GetCurrentWeaponSlot()
{
if(m_pPed) {
return &m_pPed->WeaponSlots[m_pPed->byteCurWeaponSlot];
}
return NULL;
}
//-----------------------------------------------------------
BOOL CPlayerPed::HasAmmoForCurrentWeapon()
{
if(m_pPed) {
WEAPON_SLOT_TYPE * WeaponSlot = GetCurrentWeaponSlot();
if(!WeaponSlot) return TRUE;
// Melee types always have ammo.
if( WeaponSlot->dwType <= WEAPON_CANE ||
WeaponSlot->dwType == WEAPON_PARACHUTE ) return TRUE;
if(!WeaponSlot->dwAmmo) return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------
WORD CPlayerPed::GetAmmo()
{
if(m_pPed) {
WEAPON_SLOT_TYPE * WeaponSlot = GetCurrentWeaponSlot();
if(!WeaponSlot) return -1;
// Melee types always have ammo.
if( WeaponSlot->dwType <= WEAPON_CANE ||
WeaponSlot->dwType == WEAPON_PARACHUTE ) return -1;
return (WORD)WeaponSlot->dwAmmo;
}
return 0;
}
//-----------------------------------------------------------
WEAPON_SLOT_TYPE * CPlayerPed::FindWeaponSlot(DWORD dwWeapon)
{
if (m_pPed)
{
BYTE i;
for (i = 0; i < 13; i++)
{
if (m_pPed->WeaponSlots[i].dwType == dwWeapon) return &m_pPed->WeaponSlots[i];
}
}
return NULL;
}
//-----------------------------------------------------------
void CPlayerPed::StartGoggles()
{
if (HasGoggles()) return;
if (FindWeaponSlot( 44 ) == NULL && FindWeaponSlot( 45 ) == NULL)
GiveWeapon( 44, 1 ); // Prevents crashing due to lack of animations.
CTaskGoggles* pGoggles = new CTaskGoggles();
pGoggles->ApplyToPed( this );
m_bGoggleState = TRUE;
}
//-----------------------------------------------------------
void CPlayerPed::StopGoggles()
{
if (!m_pPed || !HasGoggles()) return;
m_bGoggleState = FALSE;
DWORD dwPedPointer = (DWORD)m_pPed;
_asm mov ecx, dwPedPointer
_asm mov eax, 0x5E6010
_asm call eax
}
//-----------------------------------------------------------
BOOL CPlayerPed::HasGoggles()
{
if (!m_pPed) return FALSE;
return (BOOL)(m_pPed->dwActiveVision != 0 || m_bGoggleState);
}
//-----------------------------------------------------------