Код:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <fun>
#define PLUGIN "AlMod's Respawn"
#define VERSION "1.5"
#define AUTHOR "AlMod"
#define SPAWNTASK 384
new c_Mod, c_UsersCan, c_Money, c_RespTime
new g_Mod, g_UsersCan, g_Money, Float:g_SPK, c_SPK, g_Saving, c_Saving
new Float:g_RespTime
new bool:g_CanRespawnGlobal = false
new bool:g_CanBeSpawned[33] = false
new bool:g_GiveMoney[33] = false
new bool:g_ReturnWeapon[33] = false
new g_SavedPoints[33][3]
new const g_Objective_Ents[][] =
{
"func_bomb_target",
"info_bomb_target",
"hostage_entity",
"monster_scientist",
"func_hostage_rescue",
"info_hostage_rescue",
"info_vip_start",
"func_vip_safetyzone",
"func_escapezone",
"func_buyzone"
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
c_Mod = register_cvar("amx_respawn","1")
c_UsersCan = register_cvar("amx_respawn_allow_self","1")
c_Money = register_cvar("amx_respawn_money","3100")
c_RespTime = register_cvar("amx_respawn_time","3.0")
c_SPK = register_cvar("amx_respawn_spk","3.0")
c_Saving = register_cvar("amx_respawn_saving","1")
register_event("DeathMsg","on_death","a")
register_event("ResetHUD","on_ResetHUD","be")
register_clcmd("say /spawn","cmd_respawn",ADMIN_ALL,"Respawns you if not respawned yet")
register_clcmd("say_team /spawn","cmd_respawn",ADMIN_ALL,"Respawns you if not respawned yet")
register_clcmd("say /save","cmd_save",ADMIN_ALL,"Saves you position to respawn")
register_clcmd("say_team /save","cmd_save",ADMIN_ALL,"Saves you position to respawn")
register_clcmd("say /drop","cmd_drop",ADMIN_ALL,"Saves you position to respawn")
register_clcmd("say_team /drop","cmd_drop",ADMIN_ALL,"Saves you position to respawn")
register_clcmd("say /load","cmd_load",ADMIN_ALL,"Saves you position to respawn")
register_clcmd("say_team /load","cmd_load",ADMIN_ALL,"Saves you position to respawn")
register_forward(FM_PlayerPreThink, "player_prethink")
register_logevent("on_round_start",2,"0=World triggered","1=Round_Start")
register_logevent("on_round_end",2,"0=World triggered","1=Round_End")
}
public plugin_cfg()
{
get_settings()
}
public plugin_precache()
{
register_forward(FM_Spawn, "on_entity_spawn")
}
public on_entity_spawn(ent)
{
if (!pev_valid(ent))
return FMRES_IGNORED
static classname[32]
pev(ent, pev_classname, classname, sizeof classname - 1)
for (new i=0;i<sizeof g_Objective_Ents;i++)
{
if (equal(classname, g_Objective_Ents[i]))
{
engfunc(EngFunc_RemoveEntity, ent)
return FMRES_SUPERCEDE
}
}
return FMRES_IGNORED
}
public client_connect(id)
{
if (g_Mod!=1) return
g_CanBeSpawned[id] = false
g_GiveMoney[id] = false
g_SavedPoints[id] = {0,0,0}
}
public get_settings()
{
g_Mod = get_pcvar_num(c_Mod)
g_UsersCan = get_pcvar_num(c_UsersCan)
g_Money = get_pcvar_num(c_Money)
g_RespTime = get_pcvar_float(c_RespTime)
g_SPK = get_pcvar_float(c_SPK)
g_Saving = get_pcvar_num(c_Saving)
}
public on_death()
{
if (g_Mod!=1) return
new id = read_data(2)
g_CanBeSpawned[id] = true
if (g_CanRespawnGlobal)
{
client_print(id,print_chat,"* [RESPAWNER] You've dead. Type '/spawn' in chat, click left mouse button or wait to respawn...")
g_GiveMoney[id] = true
g_ReturnWeapon[id] = true
set_task(g_RespTime,"spec_spawn",SPAWNTASK+id)
}
}
public on_ResetHUD(id)
{
if (g_Mod!=1) return
if (g_GiveMoney[id])
{
g_GiveMoney[id] = false
new money = cs_get_user_money(id)+g_Money
if (money > 16000)
{
cs_set_user_money(id,16000,1)
}
else
{
cs_set_user_money(id,money,1)
}
}
}
public spk_on(id)
{
set_user_godmode(id,1)
set_task(g_SPK,"spk_off",id)
}
public spk_off(id)
{
set_user_godmode(id,0)
client_print(id,print_chat,"* [RESPAWNER] You can be killed now")
}
public weapon_return(id)
{
new wpn[32], num
new bool:l_HasKnife = false
new bool:l_HasGlock = false
new bool:l_HasUSP = false
get_user_weapons(id,wpn,num)
for (new i=0; i<num; i++)
{
if (wpn[i] == CSW_KNIFE) l_HasKnife = true
if (wpn[i] == CSW_GLOCK18) l_HasGlock = true
if (wpn[i] == CSW_USP) l_HasUSP = true
}
if (!l_HasKnife)
{
give_item(id,"weapon_knife")
}
if (!l_HasGlock && cs_get_user_team(id) == CS_TEAM_T)
{
give_item(id,"weapon_glock18")
give_item(id,"ammo_9mm")
//give_item(id,"ammo_9mm")
}
if (!l_HasUSP && cs_get_user_team(id) == CS_TEAM_CT)
{
give_item(id,"weapon_usp")
give_item(id,"ammo_45acp")
give_item(id,"ammo_45acp")
}
}
public on_round_start()
{
if (g_Mod!=1) return
g_CanRespawnGlobal = true
}
public on_round_end()
{
if (g_Mod!=1) return
g_CanRespawnGlobal = false
}
public player_prethink(id)
{
if (g_Mod!=1) return
if (!is_valid_id(id)) return
if (g_CanRespawnGlobal && g_CanBeSpawned[id] && !is_user_alive(id))
{
if (pev(id,pev_button) & IN_ATTACK)
{
client_print(id,print_chat,"* [RESPAWNER] You've called for momentally respawning. Working...")
if (task_exists(SPAWNTASK+id))
remove_task(SPAWNTASK+id)
g_GiveMoney[id] = true
g_ReturnWeapon[id] = true
spec_spawn(SPAWNTASK+id)
}
}
}
public is_valid_id(id)
{
if (1 <= id <= 32)
return true
return false
}
public cmd_respawn(id)
{
if (g_UsersCan!=1) return
new CsTeams:team = cs_get_user_team(id)
if (team == CS_TEAM_T || team == CS_TEAM_CT)
{
if (g_CanRespawnGlobal)
{
if (is_user_alive(id))
{
g_GiveMoney[id] = false
g_ReturnWeapon[id] = false
}
else
{
g_GiveMoney[id] = true
g_ReturnWeapon[id] = true
}
client_print(id,print_chat,"* [RESPAWNER] You've called for momentally respawning. Working...")
g_CanBeSpawned[id] = true
spec_spawn(SPAWNTASK+id)
}
}
}
public spec_spawn(tid)
{
new id = tid - SPAWNTASK
new parm[1]
parm[0]=id
new CsTeams:team = cs_get_user_team(id)
if (g_CanBeSpawned[id] && (team == CS_TEAM_T || team == CS_TEAM_CT))
{
set_task(0.5,"player_spawn",72,parm,1)
set_task(0.7,"player_spawn",72,parm,1)
set_task(0.7,"spk_on",id)
if (g_ReturnWeapon[id])
{
g_ReturnWeapon[id] = false
set_task(0.8,"weapon_return",id)
}
g_CanBeSpawned[id] = false
}
}
public player_spawn(parm[1])
{
new id = parm[0]
if (g_CanRespawnGlobal)
{
spawn(id)
}
else
{
g_GiveMoney[id] = false
}
}
public cmd_save(id)
{
if (g_Saving==1)
{
new origin[3]
get_user_origin(id,origin)
origin[2] +=30
g_SavedPoints[id] = origin
client_print(id,print_chat,"* [RESPAWNER] Position saved...")
}
else
{
client_print(id,print_chat,"* [RESPAWNER] Saving/Loading is disabled...")
}
}
public cmd_drop(id)
{
if (g_Saving==1)
{
g_SavedPoints[id] = {0,0,0}
client_print(id,print_chat,"* [RESPAWNER] Position deleted...")
}
else
{
client_print(id,print_chat,"* [RESPAWNER] Saving/Loading is disabled...")
}
}
public cmd_load(id)
{
if (g_Saving==1)
{
if (is_user_alive(id))
{
if (g_SavedPoints[id][0]!= 0 && g_SavedPoints[id][1]!= 0 && g_SavedPoints[id][2]!= 0)
{
set_user_origin(id,g_SavedPoints[id])
client_print(id,print_chat,"* [RESPAWNER] Position loaded...")
}
else
{
client_print(id,print_chat,"* [RESPAWNER] No position found...")
}
}
else
{
client_print(id,print_chat,"* [RESPAWNER] You can't load position while you dead")
}
}
else
{
client_print(id,print_chat,"* [RESPAWNER] Saving/Loading is disabled...")
}
}