Merge pull request #847 from kidfearless/master

Add more functionality for checkpoint system.
This commit is contained in:
kidfearless 2019-12-13 16:22:54 -07:00 committed by GitHub
commit b8a7b449fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 177 additions and 33 deletions

View File

@ -19,9 +19,9 @@
{
"CCSPlayer::GetPlayerMaxSpeed"
{
"windows" "504"
"linux" "505"
"mac" "505"
"windows" "505"
"linux" "506"
"mac" "506"
}
}
}

View File

@ -216,6 +216,31 @@ enum struct timer_snapshot_t
int iPerfectJumps;
}
enum struct cp_cache_t
{
float fPosition[3];
float fAngles[3];
float fVelocity[3];
float fBaseVelocity[3];
MoveType iMoveType;
float fGravity;
float fSpeed;
float fStamina;
bool bDucked;
bool bDucking;
float fDucktime; // m_flDuckAmount in csgo
float fDuckSpeed; // m_flDuckSpeed in csgo; doesn't exist in css
int iFlags;
timer_snapshot_t aSnapshot;
int iTargetname;
int iClassname;
ArrayList aFrames;
bool bSegmented;
int iSerial;
bool bPractice;
int iGroundEntity;
}
#if defined USES_CHAT_COLORS
// hardcoded colors
char gS_GlobalColorNames[][] =
@ -613,16 +638,20 @@ forward void Shavit_OnChatConfigLoaded();
/**
* Called when a player teleports with checkpoints.
*
* @param client Client index.
* @param index Checkpoint that was teleported to.
* @return Plugin_Continue to allow teleporting, anything else to prevent.
*/
forward Action Shavit_OnTeleport(int client);
forward Action Shavit_OnTeleport(int client, int index);
/**
* Called when a player teleports with checkpoints.
*
* @param client Client index.
* @param index Checkpoint that was saved to.
* @return Plugin_Continue to allow teleporting, anything else to prevent.
*/
forward Action Shavit_OnSave(int client);
forward Action Shavit_OnSave(int client, int index);
/**
* Called when a player enters a zone.
@ -1519,6 +1548,66 @@ native int Shavit_PrintToChat(int client, const char[] format, any ...);
*/
native void Shavit_LogMessage(const char[] format, any ...);
/**
* Gets the total number of CPs that a client has saved
*
* @param client Client index
*
* @return Total number of checkpoints
*/
native int Shavit_GetTotalCheckpoints(int client);
/**
* Gets CP data for a client at specified index
*
* @param client Client index
* @param index Index of CP to get
* @param cpcache Buffer to store cp data in
*
* @noreturn
*/
native bool Shavit_GetCheckpoint(int client, int index, any cpcache[sizeof(cp_cache_t)]);
/**
* Sets checkpoint data at the given index for the given client
*
* @param client Client index
* @param index Index of CP to set, or -1 to push cp as last
* @param cpcache Buffer with cp data
*
* @noreturn
*/
native void Shavit_SetCheckpoint(int client, int index, any cpcache[sizeof(cp_cache_t)]);
/**
* Teleports client to the checkpoint at given index
*
* @param client Client index
* @param index Index of CP to teleport to
* @param suppress Supress checkpoint message
*
* @noreturn
*/
native void Shavit_TeleportToCheckpoint(int client, int index, bool suppress = false);
/**
* Clears all saved checkpoints for the specified client
*
* @param client Client index
*
* @noreturn
*/
native void Shavit_ClearCheckpoints(int client);
/**
* Opens checkpoint menu for a client
*
* @param client Client index
*
* @noreturn
*/
native void Shavit_OpenCheckpointMenu(int client);
// same as Shavit_PrintToChat() but loops through the whole server
// code stolen from the base halflife.inc file
stock void Shavit_PrintToChatAll(const char[] format, any ...)
@ -1634,5 +1723,11 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_WR_DeleteMap");
MarkNativeAsOptional("Shavit_ZoneExists");
MarkNativeAsOptional("Shavit_Zones_DeleteMap");
MarkNativeAsOptional("Shavit_GetTotalCheckpoints");
MarkNativeAsOptional("Shavit_GetCheckpoint");
MarkNativeAsOptional("Shavit_SetCheckpoint");
MarkNativeAsOptional("Shavit_TeleportToCheckpoint");
MarkNativeAsOptional("Shavit_ClearCheckpoints");
MarkNativeAsOptional("Shavit_OpenCheckpointMenu");
}
#endif

View File

@ -42,30 +42,6 @@
#define CP_DEFAULT (CP_ANGLES|CP_VELOCITY)
enum struct cp_cache_t
{
float fPosition[3];
float fAngles[3];
float fVelocity[3];
float fBaseVelocity[3];
MoveType iMoveType;
float fGravity;
float fSpeed;
float fStamina;
bool bDucked;
bool bDucking;
float fDucktime; // m_flDuckAmount in csgo
float fDuckSpeed; // m_flDuckSpeed in csgo; doesn't exist in css
int iFlags;
timer_snapshot_t aSnapshot;
int iTargetname;
int iClassname;
ArrayList aFrames;
bool bSegmented;
int iSerial;
bool bPractice;
int iGroundEntity;
}
enum struct player_cpcache_t
{
@ -204,6 +180,13 @@ public Plugin myinfo =
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("Shavit_GetCheckpoint", Native_GetCheckpoint);
CreateNative("Shavit_SetCheckpoint", Native_SetCheckpoint);
CreateNative("Shavit_ClearCheckpoints", Native_ClearCheckpoints);
CreateNative("Shavit_TeleportToCheckpoint", Native_TeleportToCheckpoint);
CreateNative("Shavit_GetTotalCheckpoints", Native_GetTotalCheckpoints);
CreateNative("Shavit_OpenCheckpointMenu", Native_OpenCheckpointMenu);
gB_Late = late;
return APLRes_Success;
@ -214,8 +197,8 @@ public void OnPluginStart()
// forwards
gH_Forwards_OnClanTagChangePre = CreateGlobalForward("Shavit_OnClanTagChangePre", ET_Event, Param_Cell, Param_String, Param_Cell);
gH_Forwards_OnClanTagChangePost = CreateGlobalForward("Shavit_OnClanTagChangePost", ET_Event, Param_Cell, Param_String, Param_Cell);
gH_Forwards_OnSave = CreateGlobalForward("Shavit_OnSave", ET_Event, Param_Cell);
gH_Forwards_OnTeleport = CreateGlobalForward("Shavit_OnTeleport", ET_Event, Param_Cell);
gH_Forwards_OnSave = CreateGlobalForward("Shavit_OnSave", ET_Event, Param_Cell, Param_Cell);
gH_Forwards_OnTeleport = CreateGlobalForward("Shavit_OnTeleport", ET_Event, Param_Cell, Param_Cell);
// cache
gEV_Type = GetEngineVersion();
@ -666,7 +649,7 @@ public Action Command_Jointeam(int client, const char[] command, int args)
int iTeam = StringToInt(arg1);
int iHumanTeam = GetHumanTeam();
if(iHumanTeam != 0)
if(iHumanTeam != 0 && iTeam != 0)
{
iTeam = iHumanTeam;
}
@ -2179,6 +2162,7 @@ bool SaveCheckpoint(int client, int index, bool overflow = false)
Action result = Plugin_Continue;
Call_StartForward(gH_Forwards_OnSave);
Call_PushCell(client);
Call_PushCell(index);
Call_Finish(result);
if(result != Plugin_Continue)
@ -2420,6 +2404,7 @@ void TeleportToCheckpoint(int client, int index, bool suppressMessage)
Action result = Plugin_Continue;
Call_StartForward(gH_Forwards_OnTeleport);
Call_PushCell(client);
Call_PushCell(index);
Call_Finish(result);
if(result != Plugin_Continue)
@ -3388,3 +3373,67 @@ int GetMaxCPs(int client)
{
return CanSegment(client)? gCV_MaxCP_Segmented.IntValue:gCV_MaxCP.IntValue;
}
public any Native_GetCheckpoint(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
int index = GetNativeCell(2);
cp_cache_t cpcache;
if(GetCheckpoint(client, index, cpcache))
{
SetNativeArray(3, cpcache, sizeof(cp_cache_t));
return true;
}
return false;
}
public any Native_SetCheckpoint(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
int position = GetNativeCell(2);
cp_cache_t cpcache;
GetNativeArray(3, cpcache, sizeof(cp_cache_t));
if(position == -1)
{
position = gA_CheckpointsCache[client].iCurrentCheckpoint;
}
if(SetCheckpoint(client, position, cpcache))
{
gA_CheckpointsCache[client].iCurrentCheckpoint = ++gA_CheckpointsCache[client].iCheckpoints;
return true;
}
return false;
}
public any Native_ClearCheckpoints(Handle plugin, int numParams)
{
ResetCheckpoints(GetNativeCell(1));
return 0;
}
public any Native_TeleportToCheckpoint(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
int position = GetNativeCell(2);
bool suppress = GetNativeCell(3);
TeleportToCheckpoint(client, position, suppress);
return 0;
}
public any Native_GetTotalCheckpoints(Handle plugin, int numParams)
{
return gA_CheckpointsCache[GetNativeCell(1)].iCheckpoints;
}
public any Native_OpenCheckpointMenu(Handle plugin, int numParams)
{
OpenNormalCPMenu(GetNativeCell(1));
return 0;
}

View File

@ -178,7 +178,7 @@ public Plugin myinfo =
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("Shavit_DeleteReplay", Native_DeleteReplay);
CreateNative("Shavit_GetReplayBotCurrentFrame", Native_GetReplayBotIndex);
CreateNative("Shavit_GetReplayBotCurrentFrame", Native_GetReplayBotCurrentFrame);
CreateNative("Shavit_GetClientFrameCount", Native_GetClientFrameCount);
CreateNative("Shavit_GetReplayBotFirstFrame", Native_GetReplayBotFirstFrame);
CreateNative("Shavit_GetReplayBotIndex", Native_GetReplayBotIndex);