From 7c86cb35932f865d4366e62898132f126be4e26c Mon Sep 17 00:00:00 2001 From: Kiss Attila Date: Sun, 31 Jan 2016 21:11:10 +0100 Subject: [PATCH] Added 3 new natives - 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 --- src/CPlayerData.cpp | 10 +++++++--- src/CPlayerData.h | 4 ++-- src/Scripting.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ src/Scripting.h | 3 +++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/CPlayerData.cpp b/src/CPlayerData.cpp index 9443e83..49d4e99 100644 --- a/src/CPlayerData.cpp +++ b/src/CPlayerData.cpp @@ -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)); @@ -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]) @@ -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); diff --git a/src/CPlayerData.h b/src/CPlayerData.h index ff10f4b..c6cc5aa 100644 --- a/src/CPlayerData.h +++ b/src/CPlayerData.h @@ -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]; diff --git a/src/Scripting.cpp b/src/Scripting.cpp index 8111601..0c98622 100644 --- a/src/Scripting.cpp +++ b/src/Scripting.cpp @@ -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) { @@ -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(params[1]); + if(!IsPlayerConnectedEx(playerid)) return 0; + + pPlayerData[playerid]->dwDisabledKeys = static_cast(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(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) @@ -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 @@ -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 }, diff --git a/src/Scripting.h b/src/Scripting.h index a94c3dd..073a66e 100644 --- a/src/Scripting.h +++ b/src/Scripting.h @@ -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 @@ -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);