Fix rebuy exploit by keeping current clip.

Add zr_infect_knife_cooldown
Convert includes to new syntax.
This commit is contained in:
BotoX 2017-07-05 23:00:50 +02:00
parent b09747346f
commit 6478d995b9
8 changed files with 48 additions and 25 deletions

View File

@ -35,7 +35,7 @@
#include <zr/respawn.zr>
#include <zr/class.zr>
public SharedPlugin:__pl_zombiereloaded =
public SharedPlugin __pl_zombiereloaded =
{
name = "zombiereloaded",
file = "zombiereloaded.smx",
@ -47,7 +47,7 @@ public SharedPlugin:__pl_zombiereloaded =
};
#if !defined REQUIRE_PLUGIN
public __pl_zombiereloaded_SetNTVOptional()
public void __pl_zombiereloaded_SetNTVOptional()
{
MarkNativeAsOptional("ZR_IsValidClassIndex");
MarkNativeAsOptional("ZR_GetActiveClass");

View File

@ -54,7 +54,7 @@ enum ClassSelectResult
*
* @return True if valid, false otherwise.
*/
native bool:ZR_IsValidClassIndex(classIndex);
native bool ZR_IsValidClassIndex(int classIndex);
/**
* Gets the currently active class index that the player is using.
@ -63,7 +63,7 @@ native bool:ZR_IsValidClassIndex(classIndex);
*
* @return The active class index.
*/
native bool:ZR_GetActiveClass(client);
native bool ZR_GetActiveClass(int client);
/**
* Gets the current human class index that the player is using.
@ -72,7 +72,7 @@ native bool:ZR_GetActiveClass(client);
*
* @return The human class index.
*/
native bool:ZR_GetHumanClass(client);
native bool ZR_GetHumanClass(int client);
/**
* Gets the current zombie class index that the player is using.
@ -81,7 +81,7 @@ native bool:ZR_GetHumanClass(client);
*
* @return The zombie class index.
*/
native bool:ZR_GetZombieClass(client);
native bool ZR_GetZombieClass(int client);
/**
* Selects a class for a player.
@ -101,7 +101,7 @@ native bool:ZR_GetZombieClass(client);
*
* @return Class selection result. See enum ClassSelectResult.
*/
native ClassSelectResult:ZR_SelectClientClass(client, classIndex, bool:applyIfPossible = true, bool:saveIfEnabled = true);
native ClassSelectResult ZR_SelectClientClass(int client, int classIndex, bool applyIfPossible = true, bool saveIfEnabled = true);
/**
* Gets the class index of the class with the specified name.
@ -114,7 +114,7 @@ native ClassSelectResult:ZR_SelectClientClass(client, classIndex, bool:applyIfPo
*
* @return Class index, or -1 if none found.
*/
native ZR_GetClassByName(const String:className[], cacheType = ZR_CLASS_CACHE_MODIFIED);
native int ZR_GetClassByName(const char[] className, int cacheType = ZR_CLASS_CACHE_MODIFIED);
/**
* Gets the class name displayed in the class menu.
@ -126,4 +126,4 @@ native ZR_GetClassByName(const String:className[], cacheType = ZR_CLASS_CACHE_MO
* @param cacheType Optional. Specifies which class cache to read from.
* @return Number of cells written. -1 on error.
*/
native ZR_GetClassDisplayName(index, String:buffer[], maxlen, cacheType = ZR_CLASS_CACHE_MODIFIED);
native int ZR_GetClassDisplayName(int index, char[] buffer, int maxlen, int cacheType = ZR_CLASS_CACHE_MODIFIED);

View File

@ -33,7 +33,7 @@
* @return True if zombie, false if not.
* @error Invalid client index, not connected or not alive.
*/
native bool:ZR_IsClientZombie(client);
native bool ZR_IsClientZombie(int client);
/**
* Returns true if the player is a human, false if not.
@ -43,7 +43,7 @@ native bool:ZR_IsClientZombie(client);
* @return True if human, false if not.
* @error Invalid client index, not connected or not alive.
*/
native bool:ZR_IsClientHuman(client);
native bool ZR_IsClientHuman(int client);
/**
* Infects a player.
@ -58,7 +58,7 @@ native bool:ZR_IsClientHuman(client);
*
* @error Invalid client index, not connected or not alive.
*/
native ZR_InfectClient(client, attacker = -1, bool:motherInfect = false, bool:respawnOverride = false, bool:respawn = false);
native int ZR_InfectClient(int client, int attacker = -1, bool motherInfect = false, bool respawnOverride = false, bool respawn = false);
/**
* Turns a zombie back into a human.
@ -72,7 +72,7 @@ native ZR_InfectClient(client, attacker = -1, bool:motherInfect = false, bool:re
*
* @error Invalid client index, not connected or not alive.
*/
native ZR_HumanClient(client, bool:respawn = false, bool:protect = false);
native int ZR_HumanClient(int client, bool respawn = false, bool protect = false);
/**
* Called when a player is about to become a zombie.
@ -87,7 +87,7 @@ native ZR_HumanClient(client, bool:respawn = false, bool:protect = false);
* @return Plugin_Handled to block infection. Anything else
* (like Plugin_Continue) to allow infection.
*/
forward Action:ZR_OnClientInfect(&client, &attacker, &bool:motherInfect, &bool:respawnOverride, &bool:respawn);
forward Action ZR_OnClientInfect(int &client, int &attacker, bool &motherInfect, bool &respawnOverride, bool &respawn);
/**
* Called after a player has become a zombie.
@ -98,7 +98,7 @@ forward Action:ZR_OnClientInfect(&client, &attacker, &bool:motherInfect, &bool:r
* @param respawnOverride True if the respawn cvar was overridden.
* @param respawn The value that respawn was overridden with.
*/
forward ZR_OnClientInfected(client, attacker, bool:motherInfect, bool:respawnOverride, bool:respawn);
forward void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn);
/**
* Called when a player is about to become a human. (Through an admin command).
@ -111,7 +111,7 @@ forward ZR_OnClientInfected(client, attacker, bool:motherInfect, bool:respawnOve
* @return Plugin_Handled to block infection. Anything else
* (like Plugin_Continue) to allow acion.
*/
forward Action:ZR_OnClientHuman(&client, &bool:respawn, &bool:protect);
forward Action ZR_OnClientHuman(int &client, bool &respawn, bool &protect);
/**
* Called after a player has become a human. (Through an admin command.)
@ -120,4 +120,4 @@ forward Action:ZR_OnClientHuman(&client, &bool:respawn, &bool:protect);
* @param respawn Whether the client was respawned.
* @param protect Whether the client has spawn protection.
*/
forward ZR_OnClientHumanPost(client, bool:respawn, bool:protect);
forward void ZR_OnClientHumanPost(int client, bool respawn, bool protect);

View File

@ -44,7 +44,7 @@ enum ZR_RespawnCondition
* ZR settings. See ZR_RespawnCondition for details.
* @error Invalid client index, not connected or already alive.
*/
native ZR_RespawnClient(client, ZR_RespawnCondition:condition = ZR_Repsawn_Default);
native void ZR_RespawnClient(int client, ZR_RespawnCondition condition = ZR_Repsawn_Default);
/**
* Called right before ZR is about to respawn a player.
@ -56,7 +56,7 @@ native ZR_RespawnClient(client, ZR_RespawnCondition:condition = ZR_Repsawn_Defau
*
* @return Plugin_Handled to block respawn.
*/
forward Action:ZR_OnClientRespawn(&client, &ZR_RespawnCondition:condition);
forward Action ZR_OnClientRespawn(int &client, ZR_RespawnCondition &condition);
/**
* Called after ZR respawned a player.
@ -65,7 +65,7 @@ forward Action:ZR_OnClientRespawn(&client, &ZR_RespawnCondition:condition);
* @param condition Current condition of the respawned player. See
* ZR_RespawnCondition for details.
*/
forward ZR_OnClientRespawned(client, ZR_RespawnCondition:condition);
forward void ZR_OnClientRespawned(int client, ZR_RespawnCondition condition);
/**
* Set if a player died by a suicide or world damage.
@ -79,7 +79,7 @@ forward ZR_OnClientRespawned(client, ZR_RespawnCondition:condition);
*
* @error Invalid client index or not connected.
*/
native ZR_SetKilledByWorld(client, bool:suicide);
native void ZR_SetKilledByWorld(int client, bool suicide);
/**
* Get whether the player died by a suicide or world damage.
@ -92,4 +92,4 @@ native ZR_SetKilledByWorld(client, bool:suicide);
* another player.
* @error Invalid client index or not connected.
*/
native bool:ZR_GetKilledByWorld(client);
native bool ZR_GetKilledByWorld(int client);

View File

@ -103,13 +103,14 @@ enum CvarsList
Handle:CVAR_INFECT_SPAWNTIME_MAX,
Handle:CVAR_INFECT_CONSECUTIVE_BLOCK,
Handle:CVAR_INFECT_WEAPONS_DROP,
Handle:CVAR_INFECT_KNIFE_COOLDOWN,
Handle:CVAR_INFECT_MAX_DISTANCE,
Handle:CVAR_INFECT_MZOMBIE_MODE,
Handle:CVAR_INFECT_MZOMBIE_RATIO,
Handle:CVAR_INFECT_MZOMBIE_MIN,
Handle:CVAR_INFECT_MZOMBIE_MAX,
Handle:CVAR_INFECT_MZOMBIE_COUNTDOWN,
Handle:CVAR_INFECT_MZOMBIE_RESPAWN,
Handle:CVAR_INFECT_MAX_DISTANCE,
Handle:CVAR_INFECT_EXPLOSION,
Handle:CVAR_INFECT_FIREBALL,
Handle:CVAR_INFECT_SMOKE,
@ -328,6 +329,7 @@ CvarsCreate()
g_hCvarsList[CVAR_INFECT_SPAWNTIME_MAX] = CreateConVar("zr_infect_spawntime_max", "50.0", "Maximum time from the start of the round until picking the mother zombie(s).");
g_hCvarsList[CVAR_INFECT_CONSECUTIVE_BLOCK] = CreateConVar("zr_infect_consecutive_block", "1", "Prevent a player from being chosen as mother zombie two rounds in a row.");
g_hCvarsList[CVAR_INFECT_WEAPONS_DROP] = CreateConVar("zr_infect_weapons_drop", "1", "Force player to drop all weapons on infect, disabling this will strip weapons instead.");
g_hCvarsList[CVAR_INFECT_KNIFE_COOLDOWN] = CreateConVar("zr_infect_knife_cooldown", "1.0", "Time in seconds during which knife can not be used after becoming a zombie.");
g_hCvarsList[CVAR_INFECT_MAX_DISTANCE] = CreateConVar("zr_infect_max_distance", "80.0", "The maximum allowed distance between a client and an attacker for a successful infection. [0.0 = Disabled]");
// Effects

View File

@ -769,6 +769,10 @@ InfectHumanToZombie(client, attacker = -1, bool:motherinfect = false, bool:respa
// Remove all weapons but knife.
WeaponsRemoveAllClientWeapons(client, weaponsdrop);
// Zombie won't be able to use their knife for this amount of time
new Float:knifecooldown = GetConVarFloat(g_hCvarsList[CVAR_INFECT_KNIFE_COOLDOWN]);
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GetGameTime() + knifecooldown);
// Switch the player to terrorists.
// TODO: A solution to stop confusing bots? Respawn and teleport?
CS_SwitchTeam(client, CS_TEAM_T);

View File

@ -286,7 +286,8 @@ bool:ClassApplyNightVision(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER
}
ToolsSetClientNightVision(client, nvgs);
ToolsSetClientNightVision(client, nvgs, false);
if (!nvgs)
ToolsSetClientNightVision(client, nvgs, false);
return true;
}

View File

@ -1018,12 +1018,14 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
// Check if client is buying the weapon or ammo for it.
if (!hasweapon || slot == Slot_Projectile || slot == Slot_NVGs)
{
int oldclip = -1;
// If the item is a projectile or NVGs, then skip.
if (slot != Slot_Projectile && slot != Slot_NVGs)
{
// If there is already a weapon in the slot, then force client to drop it.
if (weapons[slot] > -1)
{
oldclip = GetEntProp(weapons[slot], Prop_Send, "m_iClip1");
if(rebuy)
{
// Kill weapon right away to decrease amount of entities on roundstart.
@ -1037,6 +1039,7 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
}
}
int entity = INVALID_ENT_REFERENCE;
if (StrEqual(weaponentity, "item_kevlar"))
{
SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
@ -1045,7 +1048,7 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
else
{
// Give client the weapon.
GivePlayerItem(client, weaponentity);
entity = GivePlayerItem(client, weaponentity);
}
if (!rebuy)
@ -1055,6 +1058,19 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
// If client isn't rebuying the weapon, then tell them the weapon has been purchased.
TranslationPrintToChat(client, "Weapons zmarket purchase", weapondisplay);
if (IsValidEntity(entity) && !WeaponsIsClientInBuyZone(client))
{
int newclip = 0;
if (oldclip != -1)
{
newclip = GetEntProp(entity, Prop_Send, "m_iClip1");
if(newclip > oldclip)
newclip = oldclip;
}
SetEntProp(entity, Prop_Send, "m_iClip1", newclip);
}
}
}
else if (!rebuy)