Compare commits

...

3 Commits

4 changed files with 175 additions and 18 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
src/zr/hgversion.h.inc
cstrike/
build/
release/
docs/changes/

26
env/include/unloze_playtime.inc vendored Executable file
View File

@ -0,0 +1,26 @@
#if defined _unloze_playtime_included_
#endinput
#endif
#define _unloze_playtime_included_
/**
* @returns the average playtime of all connected players excluding autism bots, fakeclients, AFKS and nosteamers
*/
native int GetAveragePlayerTimeOnServer();
/**
* @returns the players rtv amount boost
*/
native int GetPlayerWorthRTV_boost_(int client);
/**
* returns a players hours for a specific server
*
* @int the actual client
* @int Game time hours that the client has on the server.
* @int Game time minutes the client has on the server.
*/
native int GetPlayerTier_native(int client); //just the clients tier
forward void GetPlayerHoursServer(int client, int hours, int minutes);
forward void GetPlayerTier(int client, int tier);

View File

@ -32,6 +32,7 @@
#tryinclude "AFKManager.inc"
#tryinclude "TeamManager.inc"
#include "unloze_playtime.inc"
/* Restore old REQUIRE_PLUGIN value if necessary */
#if defined TEMP_REQUIRE_PLUGIN
@ -234,6 +235,7 @@ InfectClientInit(client)
if(!IsClientInGame(x))
continue;
/*
#if defined _AFKManager_Included
if(g_AFKManagerLoaded)
{
@ -241,6 +243,7 @@ InfectClientInit(client)
continue;
}
#endif
*/
players++;
@ -704,18 +707,24 @@ public Action:InfectMotherZombie(Handle:timer)
// Infect one of the main candidates.
if (candidatesMain)
{
// Get a random array index.
new i = Math_GetRandomInt(0, candidatesMain - 1);
// Find lowest tier candidate.
new lowestIndex = 0;
new lowestTier = GetPlayerTier_native(GetArrayCell(aCandidatesMain, 0));
for (new n = 1; n < candidatesMain; n++)
{
new tier = GetPlayerTier_native(GetArrayCell(aCandidatesMain, n));
if (tier < lowestTier)
{
lowestTier = tier;
lowestIndex = n;
}
}
new client = GetArrayCell(aCandidatesMain, lowestIndex);
// Get the client stored in the random array index.
new client = GetArrayCell(aCandidatesMain, i);
// Infect player.
if (InfectHumanToZombie(client, _, true))
infected++;
// Remove player from eligible client list.
RemoveFromArray(aCandidatesMain, i);
RemoveFromArray(aCandidatesMain, lowestIndex);
candidatesMain--;
}
else
@ -735,18 +744,24 @@ public Action:InfectMotherZombie(Handle:timer)
// Infect one of the alternate candidates.
if (candidatesAlt)
{
// Get a random array index.
new i = Math_GetRandomInt(0, candidatesAlt - 1);
// Find lowest tier candidate.
new lowestIndex = 0;
new lowestTier = GetPlayerTier_native(GetArrayCell(aCandidatesAlt, 0));
for (new n = 1; n < candidatesAlt; n++)
{
new tier = GetPlayerTier_native(GetArrayCell(aCandidatesAlt, n));
if (tier < lowestTier)
{
lowestTier = tier;
lowestIndex = n;
}
}
new client = GetArrayCell(aCandidatesAlt, lowestIndex);
// Get the client stored in the random array index.
new client = GetArrayCell(aCandidatesAlt, i);
// Infect player.
if (InfectHumanToZombie(client, _, true))
infected++;
// Remove player from eligible client list.
RemoveFromArray(aCandidatesAlt, i);
RemoveFromArray(aCandidatesAlt, lowestIndex);
candidatesAlt--;
}
else // We have no candidates at all. time to fuck over random people!

View File

@ -30,6 +30,7 @@
*/
#define ZMARKET_COOKIE_AUTOREBUY "zr_zmarket_autorebuy"
#define ZMARKET_COOKIE_REBUY "zr_zmarket_rebuy"
#define ZMARKET_COOKIE_RANDOMIZE "zr_zmarket_randomize"
/**
* @endsection
*/
@ -39,6 +40,14 @@
*/
#define ZMARKET_REBUY_WEAPONS_SLOTS_MAX 1
/**
* 2026 randomization of zmarket guns for round start.
*/
new Handle:g_hZMarketRandomizeCookie = INVALID_HANDLE;
new bool:g_bZMarketRandomize[MAXPLAYERS + 1];
new String:g_sZMarketRandomHistoryPrimary[MAXPLAYERS + 1][3][WEAPONS_MAX_LENGTH];
/**
* Array to store the client's current weapon type within menu.
*/
@ -90,6 +99,12 @@ ZMarketOnCookiesCreate()
g_hZMarketLoadoutCookie[x] = RegClientCookie(rebuycookiename, rebuycookiedesc, CookieAccess_Protected);
}
}
// Randomize toggle cookie.
if (g_hZMarketRandomizeCookie == INVALID_HANDLE)
{
g_hZMarketRandomizeCookie = RegClientCookie(ZMARKET_COOKIE_RANDOMIZE, "Whether weapon randomization is enabled", CookieAccess_Protected);
}
}
ZMarketLoad()
@ -207,6 +222,12 @@ ZMarketClientInit(client)
// No weapons bought automatically.
g_bZMarketWeaponsBought[client] = false;
// Clear randomize weapon history.
for (new i = 0; i < 3; i++)
{
g_sZMarketRandomHistoryPrimary[client][i][0] = '\0';
}
}
/**
@ -216,6 +237,10 @@ ZMarketClientInit(client)
*/
ZMarketOnCookiesCached(client)
{
decl String:value[4];
GetClientCookie(client, g_hZMarketRandomizeCookie, value, sizeof(value));
g_bZMarketRandomize[client] = (value[0] == '1');
// Rebuy wapons (if auto-rebuy is enabled, and not bought already).
if (!g_bZMarketWeaponsBought[client])
{
@ -371,6 +396,7 @@ bool:ZMarketMenuMain(client)
decl String:editloadout[MENU_LINE_REG_LENGTH];
decl String:rebuy[MENU_LINE_REG_LENGTH];
decl String:weaponslist[MENU_LINE_REG_LENGTH];
decl String:randomize[MENU_LINE_REG_LENGTH];
// Format menu options.
Format(title, sizeof(title), "%t\n ", "Weapons menu zmarket main title");
@ -378,6 +404,7 @@ bool:ZMarketMenuMain(client)
Format(editloadout, sizeof(editloadout), "%t", "Weapons menu zmarket main edit loadout");
Format(rebuy, sizeof(rebuy), "%t", "Weapons menu zmarket main rebuy");
Format(weaponslist, sizeof(weaponslist), "%t", "Weapons menu zmarket main weapons list");
Format(randomize, sizeof(randomize), "Randomize Weapons: %s", g_bZMarketRandomize[client] ? "ON" : "OFF");
// Add formatted options to menu.
SetMenuTitle(menu_zmarket_main, title);
@ -385,6 +412,7 @@ bool:ZMarketMenuMain(client)
AddMenuItem(menu_zmarket_main, "Edit Loadout", editloadout, MenuGetItemDraw(zmarketrebuy || zmarketrebuyauto));
AddMenuItem(menu_zmarket_main, "Rebuy", rebuy, MenuGetItemDraw(zmarketrebuy || zmarketrebuyauto));
AddMenuItem(menu_zmarket_main, "Weapons List", weaponslist);
AddMenuItem(menu_zmarket_main, "Randomize", randomize);
// Set exit back button.
SetMenuExitBackButton(menu_zmarket_main, true);
@ -440,6 +468,18 @@ public ZMarketMenuMainHandle(Handle:menu_zmarket_main, MenuAction:action, client
// Send the weapon types list.
ZMarketMenuTypes(client);
}
case 4:
{
// Toggle randomize.
g_bZMarketRandomize[client] = !g_bZMarketRandomize[client];
decl String:value[4];
Format(value, sizeof(value), "%d", g_bZMarketRandomize[client] ? 1 : 0);
SetClientCookie(client, g_hZMarketRandomizeCookie, value);
PrintToChat(client, "Weapons zmarket randomize toggled: %s", g_bZMarketRandomize[client] ? "ON" : "OFF");
ZMarketMenuMain(client);
}
}
}
// Client closed the menu.
@ -1305,6 +1345,75 @@ stock ZMarketSetRebuyCookie(client, WeaponsSlot:slot, const String:value[])
CloseHandle(rebuycookie);
}
/**
* Picks a random weapon name from the given slot, avoiding the client's
* last 3 picks for the primiary slot.
*
* @param client The client index.
* @param slot Slot_Primary
* @param buffer Output buffer for the weapon name.
* @param maxlen Size of buffer.
*/
stock ZMarketGetRandomWeaponForSlot(client, WeaponsSlot:slot, String:buffer[], maxlen)
{
new Handle:candidates = CreateArray(WEAPONS_MAX_LENGTH);
new size = GetArraySize(arrayWeapons);
decl String:weaponname[WEAPONS_MAX_LENGTH];
for (new i = 0; i < size; i++)
{
if (WeaponsGetSlot(i) != slot)
continue;
WeaponsGetName(i, weaponname, sizeof(weaponname));
// Skip if restricted.
if (RestrictIsWeaponRestricted(i))
continue;
// Skip if in the client's last-3 history for this slot.
new bool:inHistory = false;
for (new h = 0; h < 3; h++)
{
decl String:histEntry[WEAPONS_MAX_LENGTH];
if (slot == Slot_Primary)
strcopy(histEntry, sizeof(histEntry), g_sZMarketRandomHistoryPrimary[client][h]);
if (StrEqual(histEntry, weaponname))
{
inHistory = true;
break;
}
}
if (inHistory)
continue;
PushArrayString(candidates, weaponname);
}
new candidateCount = GetArraySize(candidates);
if (candidateCount == 0)
{
buffer[0] = '\0';
CloseHandle(candidates);
return;
}
new pick = Math_GetRandomInt(0, candidateCount - 1);
GetArrayString(candidates, pick, buffer, maxlen);
CloseHandle(candidates);
// Push into history (shift, then insert at front).
if (slot == Slot_Primary)
{
strcopy(g_sZMarketRandomHistoryPrimary[client][2], WEAPONS_MAX_LENGTH, g_sZMarketRandomHistoryPrimary[client][1]);
strcopy(g_sZMarketRandomHistoryPrimary[client][1], WEAPONS_MAX_LENGTH, g_sZMarketRandomHistoryPrimary[client][0]);
strcopy(g_sZMarketRandomHistoryPrimary[client][0], WEAPONS_MAX_LENGTH, buffer);
}
}
/**
* Force a client to rebuy their weapons.
*
@ -1340,9 +1449,14 @@ ZMarketRebuy(client, bool:autorebuy = false)
// x = Weapon slot.
for (new x = 0; x < ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1; x++)
{
// If slot is empty, then use the default value.
if (!rebuyweapons[x][0])
// If randomize is enabled, override any saved loadout for primary/secondary.
if (g_bZMarketRandomize[client] && (x == Slot_Primary || x == Slot_Secondary))
{
ZMarketGetRandomWeaponForSlot(client, WeaponsSlot:x, rebuyweapons[x], sizeof(rebuyweapons[]));
}
else if (!rebuyweapons[x][0])
{
// No saved loadout, fall back to cvar default.
switch(x)
{
case Slot_Primary: