Added support for different speed methods, defaulted to prop method now. If you don't want to update class settings, use 'zr_classes_speed_method lmv' for backwards compatibility.
This commit is contained in:
@ -214,6 +214,7 @@ public OnConfigsExecuted()
|
||||
DamageLoad();
|
||||
VEffectsLoad();
|
||||
SEffectsLoad();
|
||||
ClassOnConfigsExecuted();
|
||||
ClassLoad();
|
||||
VolLoad();
|
||||
|
||||
@ -297,3 +298,20 @@ public OnClientDisconnect(client)
|
||||
ZSpawnOnClientDisconnect(client);
|
||||
VolOnPlayerDisconnect(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a clients movement buttons are being processed
|
||||
*
|
||||
* @param client Index of the client.
|
||||
* @param buttons Copyback buffer containing the current commands (as bitflags - see entity_prop_stocks.inc).
|
||||
* @param impulse Copyback buffer containing the current impulse command.
|
||||
* @param vel Players desired velocity.
|
||||
* @param angles Players desired view angles.
|
||||
* @param weapon Entity index of the new weapon if player switches weapon, 0 otherwise.
|
||||
* @return Plugin_Handled to block the commands from being processed, Plugin_Continue otherwise.
|
||||
*/
|
||||
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
|
||||
{
|
||||
Class_OnPlayerRunCmd(client, vel);
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ enum CvarsList
|
||||
Handle:CVAR_CLASSES_ZOMBIE_SELECT,
|
||||
Handle:CVAR_CLASSES_HUMAN_SELECT,
|
||||
Handle:CVAR_CLASSES_ADMIN_SELECT,
|
||||
Handle:CVAR_CLASSES_SPEED_METHOD,
|
||||
Handle:CVAR_WEAPONS,
|
||||
Handle:CVAR_WEAPONS_RESTRICT,
|
||||
Handle:CVAR_WEAPONS_RESTRICT_ENDEQUIP,
|
||||
@ -274,6 +275,7 @@ CvarsCreate()
|
||||
g_hCvarsList[CVAR_CLASSES_ZOMBIE_SELECT] = CreateConVar("zr_classes_zombie_select", "1", "Allow players to select zombie classes.");
|
||||
g_hCvarsList[CVAR_CLASSES_HUMAN_SELECT] = CreateConVar("zr_classes_human_select", "1", "Allow players to select human classes.");
|
||||
g_hCvarsList[CVAR_CLASSES_ADMIN_SELECT] = CreateConVar("zr_classes_admin_select", "1", "Allow admins to select admin mode classes. (Not to be confused by admin-only classes!)");
|
||||
g_hCvarsList[CVAR_CLASSES_SPEED_METHOD] = CreateConVar("zr_classes_speed_method", "prop", "Speed method to use when applying player speed. Do not touch this if you don't know what you're doing! [\"lmv\" = Lagged movement value | \"prop\" = Player speed property");
|
||||
|
||||
// Menu
|
||||
g_hCvarsList[CVAR_CLASSES_MENU_AUTOCLOSE] = CreateConVar("zr_classes_menu_autoclose", "1", "Automatically close class selection menu after selecting a class.");
|
||||
|
@ -25,6 +25,11 @@
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Array that stores the client's current speed.
|
||||
*/
|
||||
new Float:g_flClassApplySpeed[MAXPLAYERS + 1];
|
||||
|
||||
/**
|
||||
* Applies all class attributes on a player. Changing model, hp, speed, health,
|
||||
* effects etc. The players current team will be used to get the class index.
|
||||
@ -418,6 +423,80 @@ bool:ClassApplySpeed(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
|
||||
speed = ClassGetSpeed(classindex, cachetype);
|
||||
}
|
||||
|
||||
ToolsSetClientLMV(client, speed);
|
||||
ClassApplySpeedEx(client, speed);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the specified speed to the player.
|
||||
*
|
||||
* @param client Client to apply to.
|
||||
* @param speed Speed value.
|
||||
*/
|
||||
ClassApplySpeedEx(client, Float:speed)
|
||||
{
|
||||
// Check what speed method that's used and apply it.
|
||||
switch (ClassSpeedMethod)
|
||||
{
|
||||
case ClassSpeed_LMV:
|
||||
{
|
||||
ToolsSetClientLMV(client, speed);
|
||||
}
|
||||
case ClassSpeed_Prop:
|
||||
{
|
||||
g_flClassApplySpeed[client] = speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the client can "think"
|
||||
* Here we can change the client's speed through m_flMaxSpeed.
|
||||
*
|
||||
* @param client The client index.
|
||||
*/
|
||||
public ClassPreThinkPost(client)
|
||||
{
|
||||
// Only apply speed if the prop method is used.
|
||||
if (ClassSpeedMethod == ClassSpeed_Prop)
|
||||
{
|
||||
if (!IsPlayerAlive(client))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: Default is around 200.0 - 250.0
|
||||
new Float:newspeed = GetEntPropFloat(client, Prop_Data, "m_flMaxspeed") + g_flClassApplySpeed[client];
|
||||
SetEntPropFloat(client, Prop_Data, "m_flMaxspeed", newspeed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a clients movement buttons are being processed
|
||||
*
|
||||
* @param client Index of the client.
|
||||
* @param vel Players desired velocity.
|
||||
*/
|
||||
Class_OnPlayerRunCmd(client, Float:vel[3])
|
||||
{
|
||||
if (!IsPlayerAlive(client))
|
||||
return;
|
||||
|
||||
// Only modify speed if the prop method is used.
|
||||
if (ClassSpeedMethod == ClassSpeed_Prop)
|
||||
{
|
||||
// x-axis speed.
|
||||
if (vel[0] < 0.0)
|
||||
vel[0] = -5000.0;
|
||||
|
||||
else if (vel[0] > 0.0)
|
||||
vel[0] = 5000.0;
|
||||
|
||||
// y-axis speed.
|
||||
if (vel[1] < 0.0)
|
||||
vel[1] = -5000.0;
|
||||
|
||||
else if (vel[1] > 0.0)
|
||||
vel[1] = 5000.0;
|
||||
}
|
||||
}
|
||||
|
@ -67,11 +67,34 @@ ClassOnMapStart()
|
||||
ClassHealthRegenInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when all configs are executed.
|
||||
*/
|
||||
ClassOnConfigsExecuted()
|
||||
{
|
||||
new ClassSpeedMethods:speedMethod = ClassGetSpeedMethod();
|
||||
|
||||
if (speedMethod != ClassSpeed_Invalid)
|
||||
{
|
||||
// Set speed method.
|
||||
ClassSpeedMethod = speedMethod;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fall back on default to avoid errors.
|
||||
ClassSpeedMethod = ClassSpeed_Prop;
|
||||
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModules:LogModule_Playerclasses, "Config validation", "Warning: Invalid value in zr_classes_speed_method. Using default value.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Client has just connected to the server.
|
||||
*/
|
||||
ClassOnClientConnected(client)
|
||||
{
|
||||
// Unhook "PreThinkPost" on the client.
|
||||
SDKUnhook(client, SDKHook_PreThinkPost, ClassPreThinkPost);
|
||||
|
||||
// Initialize the admin checked variable.
|
||||
g_bAdminChecked[client] = false;
|
||||
}
|
||||
@ -81,6 +104,9 @@ ClassOnClientConnected(client)
|
||||
*/
|
||||
ClassClientInit(client)
|
||||
{
|
||||
// Hook "PreThinkPost" on the client.
|
||||
SDKHook(client, SDKHook_PreThinkPost, ClassPreThinkPost);
|
||||
|
||||
// Reset spawn flag.
|
||||
ClassPlayerSpawned[client] = false;
|
||||
}
|
||||
|
@ -267,7 +267,22 @@ stock ClassValidateAttributes(classindex)
|
||||
|
||||
// Speed.
|
||||
new Float:speed = ClassData[classindex][Class_Speed];
|
||||
if (!(speed >= ZR_CLASS_SPEED_MIN && speed <= ZR_CLASS_SPEED_MAX))
|
||||
new Float:min;
|
||||
new Float:max;
|
||||
switch (ClassSpeedMethod)
|
||||
{
|
||||
case ClassSpeed_LMV:
|
||||
{
|
||||
min = ZR_CLASS_SPEED_LMV_MIN;
|
||||
max = ZR_CLASS_SPEED_LMV_MAX;
|
||||
}
|
||||
case ClassSpeed_Prop:
|
||||
{
|
||||
min = ZR_CLASS_SPEED_PROP_MIN;
|
||||
max = ZR_CLASS_SPEED_PROP_MAX;
|
||||
}
|
||||
}
|
||||
if (!(speed >= min && speed <= max))
|
||||
{
|
||||
flags += ZR_CLASS_SPEED;
|
||||
}
|
||||
@ -419,7 +434,22 @@ stock ClassValidateEditableAttributes(attributes[ClassEditableAttributes])
|
||||
new Float:speed = attributes[ClassEdit_Speed];
|
||||
if (speed >= 0)
|
||||
{
|
||||
if (!(speed >= ZR_CLASS_SPEED_MIN && speed <= ZR_CLASS_SPEED_MAX))
|
||||
new Float:min;
|
||||
new Float:max;
|
||||
switch (ClassSpeedMethod)
|
||||
{
|
||||
case ClassSpeed_LMV:
|
||||
{
|
||||
min = ZR_CLASS_SPEED_LMV_MIN;
|
||||
max = ZR_CLASS_SPEED_LMV_MAX;
|
||||
}
|
||||
case ClassSpeed_Prop:
|
||||
{
|
||||
min = ZR_CLASS_SPEED_PROP_MIN;
|
||||
max = ZR_CLASS_SPEED_PROP_MAX;
|
||||
}
|
||||
}
|
||||
if (!(speed >= min && speed <= max))
|
||||
{
|
||||
flags += ZR_CLASS_SPEED;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@
|
||||
#define ZR_CLASS_DEFAULT_HEALTH_REGEN_AMOUNT 2
|
||||
#define ZR_CLASS_DEFAULT_HEALTH_INFECT_GAIN 800
|
||||
#define ZR_CLASS_DEFAULT_KILL_BONUS 2
|
||||
#define ZR_CLASS_DEFAULT_SPEED 360.0
|
||||
#define ZR_CLASS_DEFAULT_SPEED 0.0
|
||||
#define ZR_CLASS_DEFAULT_KNOCKBACK 2.0
|
||||
#define ZR_CLASS_DEFAULT_JUMP_HEIGHT 10.0
|
||||
#define ZR_CLASS_DEFAULT_JUMP_DISTANCE 0.2
|
||||
@ -163,8 +163,10 @@
|
||||
#define ZR_CLASS_HEALTH_INFECT_GAIN_MAX 20000
|
||||
#define ZR_CLASS_KILL_BONUS_MIN 0
|
||||
#define ZR_CLASS_KILL_BONUS_MAX 16
|
||||
#define ZR_CLASS_SPEED_MIN 10.0
|
||||
#define ZR_CLASS_SPEED_MAX 2000.0
|
||||
#define ZR_CLASS_SPEED_LMV_MIN 10.0
|
||||
#define ZR_CLASS_SPEED_LMV_MAX 2000.0
|
||||
#define ZR_CLASS_SPEED_PROP_MIN -200.0
|
||||
#define ZR_CLASS_SPEED_PROP_MAX 800.0
|
||||
#define ZR_CLASS_KNOCKBACK_MIN -30.0
|
||||
#define ZR_CLASS_KNOCKBACK_MAX 30.0
|
||||
#define ZR_CLASS_KNOCKBACK_IGNORE -31.0 /** Used by class editor volumetric feature. */
|
||||
@ -366,6 +368,16 @@ enum ClassFilter
|
||||
ClassFilter_Client /** The client to check for class group permissions. Use 0 to ignore group filter and negative to exclude classes with groups set. */
|
||||
}
|
||||
|
||||
/**
|
||||
* Speed methods for applying player speed.
|
||||
*/
|
||||
enum ClassSpeedMethods
|
||||
{
|
||||
ClassSpeed_Invalid = -1,
|
||||
ClassSpeed_LMV, /** Modifies lagged movement value. */
|
||||
ClassSpeed_Prop, /** Modifies players' max speed property(m_flMaxspeed). */
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty filter structure.
|
||||
*/
|
||||
@ -463,6 +475,11 @@ new String:ClassOriginalPlayerModel[MAXPLAYERS + 1][PLATFORM_MAX_PATH];
|
||||
*/
|
||||
new bool:ClassPlayerSpawned[MAXPLAYERS + 1];
|
||||
|
||||
/**
|
||||
* What method used to apply speed on players.
|
||||
*/
|
||||
new ClassSpeedMethods:ClassSpeedMethod = ClassSpeed_Prop;
|
||||
|
||||
#include "zr/playerclasses/filtertools"
|
||||
#include "zr/playerclasses/attributes"
|
||||
#include "zr/playerclasses/apply"
|
||||
@ -655,6 +672,30 @@ public ClassOnConfigReload(ConfigFile:config)
|
||||
ClassLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the speed method.
|
||||
*
|
||||
* @return Speed method, or ClassSpeed_Invalid on error.
|
||||
*/
|
||||
ClassSpeedMethods:ClassGetSpeedMethod()
|
||||
{
|
||||
decl String:speedMethod[16];
|
||||
speedMethod[0] = 0;
|
||||
|
||||
GetConVarString(g_hCvarsList[CVAR_CLASSES_SPEED_METHOD], speedMethod, sizeof(speedMethod));
|
||||
|
||||
if (StrEqual(speedMethod, "lmv", false))
|
||||
{
|
||||
return ClassSpeed_LMV;
|
||||
}
|
||||
else if (StrEqual(speedMethod, "prop", false))
|
||||
{
|
||||
return ClassSpeed_Prop;
|
||||
}
|
||||
|
||||
return ClassSpeed_Invalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the class data cache. Original values are retrieved from ClassData.
|
||||
*
|
||||
|
@ -124,15 +124,44 @@ SpawnProtectStart(client)
|
||||
return;
|
||||
}
|
||||
|
||||
// Set spawn protect flag on client.
|
||||
bInfectImmune[client][INFECT_TYPE_NORMAL] = true;
|
||||
|
||||
// Get spawn protect attribute cvars.
|
||||
new Float:speed = GetConVarFloat(g_hCvarsList[CVAR_SPAWNPROTECT_SPEED]);
|
||||
new alpha = GetConVarInt(g_hCvarsList[CVAR_SPAWNPROTECT_ALPHA]);
|
||||
|
||||
// Validate attributes
|
||||
new Float:min;
|
||||
new Float:max;
|
||||
switch (ClassSpeedMethod)
|
||||
{
|
||||
case ClassSpeed_LMV:
|
||||
{
|
||||
min = ZR_CLASS_SPEED_LMV_MIN;
|
||||
max = ZR_CLASS_SPEED_LMV_MAX;
|
||||
}
|
||||
case ClassSpeed_Prop:
|
||||
{
|
||||
min = ZR_CLASS_SPEED_PROP_MIN;
|
||||
max = ZR_CLASS_SPEED_PROP_MAX;
|
||||
}
|
||||
}
|
||||
if (speed < min && speed > max)
|
||||
{
|
||||
// Log a warning and abort.
|
||||
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModules:LogModule_Config, "Config validation", "Out of range value in cvar zr_spawnprotect_speed (%f). Aborting spawn protection.", speed);
|
||||
return;
|
||||
}
|
||||
if (alpha < ZR_CLASS_ALPHA_INITIAL_MIN && alpha > ZR_CLASS_ALPHA_INITIAL_MAX)
|
||||
{
|
||||
// Log a warning and abort.
|
||||
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModules:LogModule_Config, "Config validation", "Out of range value in cvar zr_spawnprotect_alpha (%d). Aborting spawn protection.", alpha);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set spawn protect flag on client.
|
||||
bInfectImmune[client][INFECT_TYPE_NORMAL] = true;
|
||||
|
||||
// Set spawn protect attributes.
|
||||
ToolsSetClientLMV(client, speed);
|
||||
ClassApplySpeedEx(client, speed);
|
||||
ToolsSetClientAlpha(client, alpha);
|
||||
|
||||
// Set time left to zr_protect_time's value.
|
||||
|
@ -70,7 +70,7 @@ stock ToolsClientVelocity(client, Float:vecVelocity[3], bool:apply = true, bool:
|
||||
/**
|
||||
* Set a client's lagged movement value.
|
||||
* @param client The client index.
|
||||
* @param value LMV value. (1.0 = default, 2.0 = double)
|
||||
* @param value LMV value. (300.0 = default, 600.0 = double)
|
||||
*/
|
||||
stock ToolsSetClientLMV(client, Float:fLMV)
|
||||
{
|
||||
|
Reference in New Issue
Block a user