PHP Code:
/*================================================================================
--------------------------------
-*- [ZP] Rewards: Ammo Packs -*-
--------------------------------
This plugin is part of Zombie Plague Mod and is distributed under the
terms of the GNU General Public License. Check ZP_ReadMe.txt for details.
================================================================================*/
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <cs_ham_bots_api>
#include <zp50_gamemodes>
#define LIBRARY_NEMESIS "zp50_class_nemesis"
#include <zp50_class_nemesis>
#define LIBRARY_SURVIVOR "zp50_class_survivor"
#include <zp50_class_survivor>
#include <zp50_ammopacks>
#include <zombielite_para>
#include <dhudmessage>
#include <nvault>
#define MAXPLAYERS 32
new g_MaxPlayers
new lvlspr
new Level[33] = 0
new MaxEXP[33] = 500
new g_Vault
new AMMO[33]
new AMMOS[33]
new save[33]
new Float:g_DamageDealtToZombies[MAXPLAYERS+1]
new Float:g_DamageDealtToHumans[MAXPLAYERS+1]
new Float:g_DamageEXP[MAXPLAYERS+1]
new cvar_ammop_winner, cvar_ammop_loser
new cvar_ammop_damage, cvar_ammop_zombie_damaged_hp, cvar_ammop_human_damaged_hp
new cvar_ammop_zombie_killed, cvar_ammop_human_killed
new cvar_ammop_human_infected
new cvar_ammop_nemesis_ignore, cvar_ammop_survivor_ignore
new const lvlup[] = "zl/fun/levelup.wav"
public plugin_init()
{
register_plugin("[ZP] Rewards: Ammo Packs", ZP_VERSION_STRING, "ZP Dev Team")
cvar_ammop_winner = register_cvar("zp_ammop_winner", "3")
cvar_ammop_loser = register_cvar("zp_ammop_loser", "1")
cvar_ammop_damage = register_cvar("zp_ammop_damage", "1")
cvar_ammop_zombie_damaged_hp = register_cvar("zp_ammop_zombie_damaged_hp", "500")
cvar_ammop_human_damaged_hp = register_cvar("zp_ammop_human_damaged_hp", "250")
cvar_ammop_zombie_killed = register_cvar("zp_ammop_zombie_killed", "1")
cvar_ammop_human_killed = register_cvar("zp_ammop_human_killed", "1")
cvar_ammop_human_infected = register_cvar("zp_ammop_human_infected", "1")
// Nemesis Class loaded?
if (LibraryExists(LIBRARY_NEMESIS, LibType_Library))
cvar_ammop_nemesis_ignore = register_cvar("zp_ammop_nemesis_ignore", "0")
// Survivor Class loaded?
if (LibraryExists(LIBRARY_SURVIVOR, LibType_Library))
cvar_ammop_survivor_ignore = register_cvar("zp_ammop_survivor_ignore", "0")
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage_Post", 1)
RegisterHamBots(Ham_TakeDamage, "fw_TakeDamage_Post", 1)
RegisterHam(Ham_Killed, "player", "fw_PlayerKilled_Post", 1)
RegisterHamBots(Ham_Killed, "fw_PlayerKilled_Post", 1)
register_forward(FM_PlayerPreThink, "fw_PlayerPreThink");
g_MaxPlayers = get_maxplayers()
// Открываем файл и сохраняем указатель в g_Vault
g_Vault = nvault_open("zombielite")
// Прекращаем работу плагина, если файл не удалось открыть
if (g_Vault == INVALID_HANDLE)
set_fail_state("Error opening nVault!")
nvault_prune(g_Vault, 0, get_systime() - (15 * 86400))
}
public saverz(id)
{
new s_Key[255]
new datas[255]
new Names[33]
get_user_name(id, Names, 32)
formatex(s_Key, charsmax(s_Key) , "%s-Name", Names)
formatex(datas, 255, "%i#%i#%i#%i", AMMO[id], Level[id], g_DamageEXP[id], MaxEXP[id])
nvault_set(g_Vault, s_Key, datas)
}
public loadz(id)
{
new Names[33]
get_user_name(id, Names, 32)
new s_Key[255], datas[255], s_APS[32], s_LevelS[32], s_DamageS[32], s_DamageMaxS[32]
formatex(s_Key, charsmax(s_Key) , "%s-Name", Names)
formatex(datas, 255, "%i#%i#%i#%i", AMMO[id], Level[id], g_DamageEXP[id], MaxEXP[id])
nvault_get (g_Vault, s_Key, datas, 255)
replace_all(datas , 255, "#", " ")
parse (datas, s_APS, 31, s_LevelS, 31, s_DamageS, 31, s_DamageMaxS, 31)
AMMOS[id] = str_to_num (s_APS)
Level[id] = str_to_num (s_LevelS)
g_DamageEXP[id] = str_to_num (s_DamageS)
MaxEXP[id] = str_to_num (s_DamageMaxS)
return PLUGIN_CONTINUE
}
public plugin_end()
{
nvault_close(g_Vault)
}
public plugin_natives()
{
set_module_filter("module_filter")
set_native_filter("native_filter")
register_native("zl_ap_damage", "native_zl_ap_damage", 1)
register_native("zl_ap_level", "native_zl_ap_level", 1)
register_native("zl_ap_maxexp", "native_zl_ap_maxexp", 1)
}
public module_filter(const module[])
{
if (equal(module, LIBRARY_NEMESIS) || equal(module, LIBRARY_SURVIVOR))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public native_filter(const name[], index, trap)
{
if (!trap)
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public zp_fw_core_infect_post(id, attacker)
{
// Reward ammo packs to zombies infecting humans?
if (is_user_connected(attacker) && attacker != id && get_pcvar_num(cvar_ammop_human_infected) > 0)
zp_ammopacks_set(attacker, zp_ammopacks_get(attacker) + get_pcvar_num(cvar_ammop_human_infected))
//Save_MySql(id)
}
/*
public client_connect(id)
{
get_user_name(id, Names[id], 33)
}
*/
public client_putinserver(id)
{
loadz(id);
if(Level[id] == 0) MaxEXP[id] = 500
save[id] = true
zp_ammopacks_set(id, AMMOS[id])
// client_print(id, print_chat, "AMMO: %d | Level: %d | Damage: %d | DamageMax: %d", AMMOS[id], Level[id], floatround(g_DamageEXP[id]), MaxEXP[id])
}
/*
public Loads2(id)
{
id-=772
save[id] = true
zp_ammopacks_set(id, AMMOS[id])
client_print(id, print_chat, "AMMO: %d | Level: %d | Damage: %d | DamageMax: %d", AMMOS[id], Level[id], floatround(g_DamageEXP[id]), MaxEXP[id])
}
*/
public fw_PlayerPreThink()
{
for(new id;id<=get_maxplayers();id++)
{
if(save[id])
{
saverz(id)
new ammo_packs = zp_ammopacks_get(id)
AMMO[id] = ammo_packs
}
}
}
/*
take_packs(id, amnt)
{
//zp_ammopacks_set(id, APS)
zp_ammopacks_set(id, zp_ammopacks_get(id) + APS[id])
zp_ammopacks_set(id, zp_ammopacks_get(id) + amnt);
}
*/
// Ham Take Damage Post Forward
public fw_TakeDamage_Post(victim, inflictor, attacker, Float:damage, damage_type)
{
// Non-player damage or self damage
if (victim == attacker || !is_user_alive(attacker))
return;
// Ignore ammo pack rewards for Nemesis?
if (LibraryExists(LIBRARY_NEMESIS, LibType_Library) && zp_class_nemesis_get(attacker) && get_pcvar_num(cvar_ammop_nemesis_ignore))
return;
// Ignore ammo pack rewards for Survivor?
if (LibraryExists(LIBRARY_SURVIVOR, LibType_Library) && zp_class_survivor_get(attacker) && get_pcvar_num(cvar_ammop_survivor_ignore))
return;
// Zombie attacking human...
if (zp_core_is_zombie(attacker) && !zp_core_is_zombie(victim))
{
// Reward ammo packs to zombies for damaging humans?
if (get_pcvar_num(cvar_ammop_damage) > 0)
{
// Store damage dealt
g_DamageDealtToHumans[attacker] += damage
// Give rewards according to damage dealt
new how_many_rewards = floatround(g_DamageDealtToHumans[attacker] / get_pcvar_float(cvar_ammop_human_damaged_hp), floatround_floor)
if (how_many_rewards > 0)
{
zp_ammopacks_set(attacker, zp_ammopacks_get(attacker) + (get_pcvar_num(cvar_ammop_damage) * how_many_rewards))
g_DamageDealtToHumans[attacker] -= get_pcvar_float(cvar_ammop_human_damaged_hp) * how_many_rewards
}
}
}
// Human attacking zombie...
else if (!zp_core_is_zombie(attacker) && zp_core_is_zombie(victim))
{
// Reward ammo packs to humans for damaging zombies?
if (get_pcvar_num(cvar_ammop_damage) > 0)
{
// Store damage dealt
g_DamageDealtToZombies[attacker] += damage
// Give rewards according to damage dealt
new how_many_rewards = floatround(g_DamageDealtToZombies[attacker] / get_pcvar_float(cvar_ammop_zombie_damaged_hp), floatround_floor)
if (how_many_rewards > 0)
{
//Level[attacker]++
zp_ammopacks_set(attacker, zp_ammopacks_get(attacker) + (get_pcvar_num(cvar_ammop_damage) * how_many_rewards))
g_DamageDealtToZombies[attacker] -= get_pcvar_float(cvar_ammop_zombie_damaged_hp) * how_many_rewards
}
g_DamageEXP[attacker]+=damage
new exp = floatround(g_DamageEXP[attacker])
new aname[33]
get_user_name(attacker, aname, sizeof aname - 1)
if(exp >= MaxEXP[attacker])
{
set_hudmessage(250, 250, 250, 0.1, -0.7, 0, 0.0, 3.0, 2.0, 1.0, -1)
Level[attacker]++
MaxEXP[attacker] *= 2
g_DamageEXP[attacker] = 0.0
levelsystem(attacker)
show_hudmessage(0, "%s получил %d уровень", aname, Level[attacker])
}
}
}
}
public levelsystem(id)
{
if(0 <= Level[id] < 10)
{
zl_parachute_false(id)
}
if(10 <= Level[id] < 11)
{
set_dhudmessage(255, 255, 0, -1.0, -0.7, 0, 0.0, 5.0, 1.0, 1.0)
show_dhudmessage(id, "Level 10^nПарашют доступен!") // 3
Linial(id)
emit_sound(id, CHAN_VOICE, lvlup, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
zl_parachute_true(id)
}
}
public levelsystem2(id)
{
if(0 <= Level[id] < 10)
{
zl_parachute_false(id)
}
if(10 <= Level[id] < 11)
{
zl_parachute_true(id)
}
}
public Linial(id)
{
static origin[3]
get_user_origin(id, origin)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMCYLINDER)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2])
write_coord(origin[0]+450)
write_coord(origin[1]+450)
write_coord(origin[2]+450)
write_short(lvlspr)
write_byte(0)
write_byte(255)
write_byte(10)
write_byte(60)
write_byte(255)
write_byte(255)
write_byte(0)
write_byte(0)
write_byte(255)
write_byte(0)
message_end()
}
// Ham Player Killed Post Forward
public fw_PlayerKilled_Post(victim, attacker, shouldgib)
{
// Non-player kill or self kill
if (victim == attacker || !is_user_connected(attacker))
return;
// Ignore ammo pack rewards for Nemesis?
if (LibraryExists(LIBRARY_NEMESIS, LibType_Library) && zp_class_nemesis_get(attacker) && get_pcvar_num(cvar_ammop_nemesis_ignore))
return;
// Ignore ammo pack rewards for Survivor?
if (LibraryExists(LIBRARY_SURVIVOR, LibType_Library) && zp_class_survivor_get(attacker) && get_pcvar_num(cvar_ammop_survivor_ignore))
return;
// Reward ammo packs to attacker for the kill
if (zp_core_is_zombie(victim))
zp_ammopacks_set(attacker, zp_ammopacks_get(attacker) + get_pcvar_num(cvar_ammop_zombie_killed))
else
zp_ammopacks_set(attacker, zp_ammopacks_get(attacker) + get_pcvar_num(cvar_ammop_human_killed))
}
public zp_fw_gamemodes_end()
{
// Determine round winner and money rewards
if (!zp_core_get_zombie_count())
{
// Human team wins
new id
for (id = 1; id <= g_MaxPlayers; id++)
{
if (!is_user_connected(id))
continue;
if (zp_core_is_zombie(id))
zp_ammopacks_set(id, zp_ammopacks_get(id) + get_pcvar_num(cvar_ammop_loser))
else
zp_ammopacks_set(id, zp_ammopacks_get(id) + get_pcvar_num(cvar_ammop_winner))
}
}
else if (!zp_core_get_human_count())
{
// Zombie team wins
new id
for (id = 1; id <= g_MaxPlayers; id++)
{
if (!is_user_connected(id))
continue;
if (zp_core_is_zombie(id))
zp_ammopacks_set(id, zp_ammopacks_get(id) + get_pcvar_num(cvar_ammop_winner))
else
zp_ammopacks_set(id, zp_ammopacks_get(id) + get_pcvar_num(cvar_ammop_loser))
}
}
else
{
// No one wins
new id
for (id = 1; id <= g_MaxPlayers; id++)
{
if (!is_user_connected(id))
continue;
zp_ammopacks_set(id, zp_ammopacks_get(id) + get_pcvar_num(cvar_ammop_loser))
}
}
//new id
//for (id = 1; id <= g_MaxPlayers; id++)
//Save_MySql(id)
}
public plugin_precache()
{
lvlspr = precache_model("sprites/3dmflaora.spr")
precache_sound(lvlup)
}
public client_disconnect(id)
{
// Clear damage after disconnecting
g_DamageDealtToZombies[id] = 0.0
g_DamageDealtToHumans[id] = 0.0
saverz(id)
//Save_MySql(id)
}
public native_zl_ap_damage(id)
{
return floatround(g_DamageEXP[id])
}
public native_zl_ap_level(id)
{
return Level[id]
}
public native_zl_ap_maxexp(id)
{
return MaxEXP[id]
}