2009-04-12 08:04:00 +02:00
|
|
|
/**
|
|
|
|
* ====================
|
|
|
|
* Zombie:Reloaded
|
|
|
|
* File: weapons.inc
|
|
|
|
* Author: Greyscale
|
|
|
|
* ====================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum length of a weapon name string
|
|
|
|
*/
|
|
|
|
#define WEAPONS_MAX_LENGTH 32
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array to store keyvalue data.
|
|
|
|
*/
|
|
|
|
new Handle:kvWeapons = INVALID_HANDLE;
|
|
|
|
|
|
|
|
#include "zr/weapons/restrict"
|
|
|
|
#include "zr/weapons/markethandler"
|
|
|
|
#include "zr/weapons/menu_weapons"
|
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
WeaponsInit()
|
|
|
|
{
|
|
|
|
// Forward event to sub-module
|
|
|
|
RestrictInit();
|
|
|
|
}
|
|
|
|
|
2009-04-12 08:04:00 +02:00
|
|
|
/**
|
|
|
|
* Loads weapon data from file.
|
|
|
|
*/
|
|
|
|
WeaponsOnMapStart()
|
|
|
|
{
|
|
|
|
// Load weapon data
|
|
|
|
if (kvWeapons != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
CloseHandle(kvWeapons);
|
|
|
|
}
|
|
|
|
|
|
|
|
kvWeapons = CreateKeyValues("weapons");
|
|
|
|
|
|
|
|
decl String:path[PLATFORM_MAX_PATH];
|
|
|
|
BuildPath(Path_SM, path, sizeof(path), "configs/zr/weapons/weapons.txt");
|
|
|
|
|
|
|
|
// If file isn't found, stop plugin
|
|
|
|
if (!FileToKeyValues(kvWeapons, path))
|
|
|
|
{
|
|
|
|
SetFailState("\"%s\" missing from server", path);
|
|
|
|
}
|
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
// Validate weapons config
|
|
|
|
WeaponsValidateWeaponsConfig();
|
|
|
|
|
|
|
|
// Forward event to sub-module
|
|
|
|
RestrictOnMapStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
WeaponsValidateWeaponsConfig()
|
|
|
|
{
|
2009-04-12 08:04:00 +02:00
|
|
|
KvRewind(kvWeapons);
|
|
|
|
if (KvGotoFirstSubKey(kvWeapons))
|
|
|
|
{
|
|
|
|
decl String:weapon[WEAPONS_MAX_LENGTH];
|
|
|
|
decl String:restrict[8];
|
|
|
|
decl String:menu[8];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvWeapons, weapon, sizeof(weapon));
|
|
|
|
KvGetString(kvWeapons, "restrict", restrict, sizeof(restrict), "no");
|
|
|
|
KvGetString(kvWeapons, "menu", menu, sizeof(menu), "yes");
|
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
// VALIDATE
|
2009-04-12 08:04:00 +02:00
|
|
|
|
|
|
|
} while (KvGotoNextKey(kvWeapons));
|
|
|
|
}
|
2009-04-13 20:33:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WeaponsClientInit(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-module
|
|
|
|
RestrictClientInit(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
WeaponsOnClientDisconnect(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-module
|
|
|
|
RestrictOnClientDisconnect(client);
|
2009-04-12 08:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array of all listed weapons in weapons.txt.
|
|
|
|
* @param arrayWeapons The handle of the array, don't forget to call CloseHandle
|
|
|
|
* on it when finished!
|
|
|
|
* @return The size of the array.
|
|
|
|
*/
|
|
|
|
WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH)
|
|
|
|
{
|
|
|
|
arrayWeapons = CreateArray(maxlen);
|
|
|
|
new count = 0;
|
|
|
|
|
|
|
|
KvRewind(kvWeapons);
|
|
|
|
if (KvGotoFirstSubKey(kvWeapons))
|
|
|
|
{
|
|
|
|
decl String:weapon[maxlen];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvWeapons, weapon, maxlen);
|
|
|
|
|
|
|
|
PushArrayString(arrayWeapons, weapon);
|
|
|
|
count++;
|
|
|
|
} while (KvGotoNextKey(kvWeapons));
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-13 20:33:13 +02:00
|
|
|
* Checks if a weapon is valid (aka listed in weapons.txt)
|
|
|
|
* @param weapon The weapon name.
|
|
|
|
* @return Returns true if valid, false it not.
|
2009-04-12 08:04:00 +02:00
|
|
|
*/
|
2009-04-13 20:33:13 +02:00
|
|
|
bool:WeaponsIsValidWeapon(const String:weapon[])
|
2009-04-12 08:04:00 +02:00
|
|
|
{
|
2009-04-13 20:33:13 +02:00
|
|
|
KvRewind(kvWeapons);
|
|
|
|
if (KvGotoFirstSubKey(kvWeapons))
|
2009-04-12 08:04:00 +02:00
|
|
|
{
|
2009-04-13 20:33:13 +02:00
|
|
|
decl String:validweapon[WEAPONS_MAX_LENGTH];
|
2009-04-12 08:04:00 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-04-13 20:33:13 +02:00
|
|
|
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
|
2009-04-12 08:04:00 +02:00
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
if (StrEqual(validweapon, weapon, false))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (KvGotoNextKey(kvWeapons));
|
2009-04-12 08:04:00 +02:00
|
|
|
}
|
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
return false;
|
2009-04-12 08:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-13 20:33:13 +02:00
|
|
|
* Looks up a weapon in weapons.txt and returns exact display name
|
2009-04-12 08:04:00 +02:00
|
|
|
* @param weapon The weapon name.
|
2009-04-13 20:33:13 +02:00
|
|
|
* @param display Returns with the display name, is not changed if weapon is invalid.
|
2009-04-12 08:04:00 +02:00
|
|
|
*/
|
2009-04-13 20:33:13 +02:00
|
|
|
WeaponGetDisplayName(const String:weapon[], String:display[])
|
2009-04-12 08:04:00 +02:00
|
|
|
{
|
2009-04-13 20:33:13 +02:00
|
|
|
KvRewind(kvWeapons);
|
|
|
|
if (KvGotoFirstSubKey(kvWeapons))
|
|
|
|
{
|
|
|
|
decl String:validweapon[WEAPONS_MAX_LENGTH];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
|
|
|
|
|
|
|
|
if (StrEqual(validweapon, weapon, false))
|
|
|
|
{
|
|
|
|
strcopy(display, WEAPONS_MAX_LENGTH, validweapon);
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (KvGotoNextKey(kvWeapons));
|
|
|
|
}
|
2009-04-12 08:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a weapon is restricted by default.
|
|
|
|
* @param weapon The weapon name.
|
|
|
|
* @return Returns true if restricted, false it not.
|
|
|
|
*/
|
2009-04-13 20:33:13 +02:00
|
|
|
bool:WeaponsIsRestrict(const String:weapon[])
|
2009-04-12 08:04:00 +02:00
|
|
|
{
|
2009-04-13 20:33:13 +02:00
|
|
|
KvRewind(kvWeapons);
|
|
|
|
if (KvGotoFirstSubKey(kvWeapons))
|
|
|
|
{
|
|
|
|
decl String:validweapon[WEAPONS_MAX_LENGTH];
|
|
|
|
decl String:restrict[8];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
|
|
|
|
|
|
|
|
if (StrEqual(validweapon, weapon, false))
|
|
|
|
{
|
|
|
|
KvGetString(kvWeapons, validweapon, restrict, sizeof(restrict), "no");
|
|
|
|
|
|
|
|
return ConfigOptionToBool(restrict);
|
|
|
|
}
|
|
|
|
} while (KvGotoNextKey(kvWeapons));
|
|
|
|
}
|
2009-04-12 08:04:00 +02:00
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
return false;
|
2009-04-12 08:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a weapon restriction can be toggled by the admin menu.
|
|
|
|
* @param weapon The weapon name.
|
|
|
|
* @return Returns true if restricted, false it not.
|
|
|
|
*/
|
|
|
|
bool:WeaponsIsWeaponMenu(const String:weapon[])
|
|
|
|
{
|
2009-04-13 20:33:13 +02:00
|
|
|
KvRewind(kvWeapons);
|
|
|
|
if (KvGotoFirstSubKey(kvWeapons))
|
|
|
|
{
|
|
|
|
decl String:validweapon[WEAPONS_MAX_LENGTH];
|
|
|
|
decl String:menu[8];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
|
|
|
|
|
|
|
|
if (StrEqual(validweapon, weapon, false))
|
|
|
|
{
|
|
|
|
KvGetString(kvWeapons, validweapon, menu, sizeof(menu), "yes");
|
|
|
|
|
|
|
|
return ConfigOptionToBool(menu);
|
|
|
|
}
|
|
|
|
} while (KvGotoNextKey(kvWeapons));
|
|
|
|
}
|
2009-04-12 08:04:00 +02:00
|
|
|
|
2009-04-13 20:33:13 +02:00
|
|
|
return false;
|
2009-04-12 08:04:00 +02:00
|
|
|
}
|