Skip to content

Commit

Permalink
Added 3 new natives
Browse files Browse the repository at this point in the history
- Added RemoveLastClass*, SetPlayerDisabledKeysSync**,
GetPlayerDisabledKeysSync**

* This function only will decrease available classes, only will affect
newly connected players

**Disabled keys sync only work when player is onfoot or driver
  • Loading branch information
Kiss Attila committed Jan 31, 2016
1 parent 89953ae commit 7c86cb3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/CPlayerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ CPlayerData::CPlayerData( WORD playerid )
bFakePingToggle = false;
dwFakePingValue = 0;

pCustomSyncData = NULL;
memset(bCustomPos, false, MAX_PLAYERS);
memset(bCustomQuat, false, MAX_PLAYERS);
memset(vecCustomPos, NULL, sizeof(CVector));
Expand Down Expand Up @@ -345,7 +344,9 @@ void RebuildSyncData(RakNet::BitStream *bsSync, WORD toplayerid)
}

// Keys
bsSync->Write(p->syncData.wKeys);

WORD keys = p->syncData.wKeys &= ~pPlayerData[playerid]->dwDisabledKeys;
bsSync->Write(keys);

// Position
if(pPlayerData[toplayerid]->bCustomPos[playerid])
Expand Down Expand Up @@ -424,7 +425,10 @@ void RebuildSyncData(RakNet::BitStream *bsSync, WORD toplayerid)
bsSync->Write(p->vehicleSyncData.wVehicleId);
bsSync->Write(p->vehicleSyncData.wUDAnalog);
bsSync->Write(p->vehicleSyncData.wLRAnalog);
bsSync->Write(p->vehicleSyncData.wKeys);

WORD keys = p->vehicleSyncData.wKeys &= ~pPlayerData[playerid]->dwDisabledKeys;
bsSync->Write(keys);

bsSync->WriteNormQuat(p->vehicleSyncData.fQuaternionAngle, p->vehicleSyncData.vecQuaternion.fX, p->vehicleSyncData.vecQuaternion.fY, p->vehicleSyncData.vecQuaternion.fZ);
bsSync->Write((char*)&p->vehicleSyncData.vecPosition, sizeof(CVector));
bsSync->WriteVector(p->vehicleSyncData.vecVelocity.fX, p->vehicleSyncData.vecVelocity.fY, p->vehicleSyncData.vecVelocity.fZ);
Expand Down
4 changes: 2 additions & 2 deletions src/CPlayerData.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class CPlayerData
BYTE byteTeam;

// Special shits for store sync data
CSyncData *pCustomSyncData;
WORD dwDisabledKeys;

// Per-player pos
// Per-player pos
bool bCustomPos[MAX_PLAYERS];
bool bCustomQuat[MAX_PLAYERS];
CVector *vecCustomPos[MAX_PLAYERS];
Expand Down
48 changes: 48 additions & 0 deletions src/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,20 @@ static cell AMX_NATIVE_CALL Natives::GetAvailableClasses(AMX *amx, cell *params)
return pNetGame->iSpawnsAvailable;
}

// native RemoveLastClass();
static cell AMX_NATIVE_CALL Natives::RemoveLastClass(AMX *amx, cell *params)
{
// If unknown server version
if(!pServer)
return 0;

if(pNetGame->iSpawnsAvailable <= 1)
return 0;

pNetGame->iSpawnsAvailable--;
return 1;
}

// native GetPlayerClass(classid, &teamid, &modelid, &Float:spawn_x, &Float:spawn_y, &Float:spawn_z, &Float:z_angle, &weapon1, &weapon1_ammo, &weapon2, &weapon2_ammo,& weapon3, &weapon3_ammo);
static cell AMX_NATIVE_CALL Natives::GetPlayerClass(AMX *amx, cell *params)
{
Expand Down Expand Up @@ -2181,6 +2195,37 @@ static cell AMX_NATIVE_CALL Natives::IsPlayerCameraTargetEnabled( AMX* amx, cell
return pNetGame->pPlayerPool->pPlayer[playerid]->bCameraTarget;
}

// native SetPlayerDisabledKeysSync(playerid, keys);
static cell AMX_NATIVE_CALL Natives::SetPlayerDisabledKeysSync( AMX* amx, cell* params )
{
// If unknown server version
if(!pServer)
return 0;

CHECK_PARAMS(2, "SetPlayerDisabledKeySync");

int playerid = static_cast<int>(params[1]);
if(!IsPlayerConnectedEx(playerid)) return 0;

pPlayerData[playerid]->dwDisabledKeys = static_cast<WORD>(params[2]);
return 1;
}

// native GetPlayerDisabledKeysSync(playerid);
static cell AMX_NATIVE_CALL Natives::GetPlayerDisabledKeysSync( AMX* amx, cell* params )
{
// If unknown server version
if(!pServer)
return 0;

CHECK_PARAMS(1, "SetPlayerDisabledKeySync");

int playerid = static_cast<int>(params[1]);
if(!IsPlayerConnectedEx(playerid)) return 0;

return pPlayerData[playerid]->dwDisabledKeys;
}

// Scoreboard manipulation
// native TogglePlayerScoresPingsUpdate(playerid, bool:toggle);
static cell AMX_NATIVE_CALL Natives::TogglePlayerScoresPingsUpdate(AMX *amx, cell *params)
Expand Down Expand Up @@ -6113,6 +6158,7 @@ AMX_NATIVE_INFO YSINatives [] =

// Player classes
{ "GetAvailableClasses", Natives::GetAvailableClasses}, // R6
{ "RemoveLastClass", Natives::RemoveLastClass}, // R16
{ "GetPlayerClass", Natives::GetPlayerClass}, // R6
{ "EditPlayerClass", Natives::EditPlayerClass}, // R6

Expand Down Expand Up @@ -6156,6 +6202,8 @@ AMX_NATIVE_INFO YSINatives [] =
{ "SpawnForWorld", Natives::SpawnForWorld }, // R10
{ "BroadcastDeath", Natives::BroadcastDeath }, // R13
{ "IsPlayerCameraTargetEnabled", Natives::IsPlayerCameraTargetEnabled }, // R13
{ "SetPlayerDisabledKeysSync", Natives::SetPlayerDisabledKeysSync }, // R16
{ "GetPlayerDisabledKeysSync", Natives::GetPlayerDisabledKeysSync }, // R16

// Special things from syncdata
{ "GetPlayerSirenState", Natives::GetPlayerSirenState },
Expand Down
3 changes: 3 additions & 0 deletions src/Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace Natives
static cell AMX_NATIVE_CALL IsNickNameCharacterAllowed(AMX *amx, cell *params); // R7

static cell AMX_NATIVE_CALL GetAvailableClasses(AMX *amx, cell *params); // R6
static cell AMX_NATIVE_CALL RemoveLastClass(AMX *amx, cell *params); // R16
static cell AMX_NATIVE_CALL GetPlayerClass(AMX *amx, cell *params); // R6
static cell AMX_NATIVE_CALL EditPlayerClass(AMX *amx, cell *params); // R6

Expand Down Expand Up @@ -117,6 +118,8 @@ namespace Natives
static cell AMX_NATIVE_CALL SpawnForWorld(AMX *amx, cell *params); // R10
static cell AMX_NATIVE_CALL BroadcastDeath(AMX *amx, cell *params); // R13
static cell AMX_NATIVE_CALL IsPlayerCameraTargetEnabled(AMX *amx, cell *params); // R13
static cell AMX_NATIVE_CALL SetPlayerDisabledKeysSync(AMX *amx, cell *params); // R16
static cell AMX_NATIVE_CALL GetPlayerDisabledKeysSync(AMX *amx, cell *params); // R16

static cell AMX_NATIVE_CALL GetPlayerSirenState(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL GetPlayerLandingGearState(AMX *amx, cell *params);
Expand Down

0 comments on commit 7c86cb3

Please sign in to comment.