Всем доброго времени суток, нужен рабочий плагин Knife Duel с телепортом, восстановлением ХП, отсчетом до начала боя.
На примере есть один но с ним проблемы.
Заранее всем спасибо!
На примере есть один но с ним проблемы.
Заранее всем спасибо!
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka"
new const g_szKnifeSound[] = "weapons/knife_hitwall1.wav";
new const g_szSpawnClassname[] = "info_player_deathmatch";
new Float:g_fHit[33];
new Float:g_fDelay[33];
new iHitCount[33];
new g_iChallenged, g_iChallenger;
new Float:g_vKnifeOrigin[2][3];
new bool:g_bInChallenge;
new g_iTimer;
new g_iMenu;
enum _:max_cvars {
CVAR_COUNT = 0,
CVAR_DELAY,
CVAR_TIMER,
CVAR_MAXDISTANCE,
CVAR_PROTECTION,
CVAR_ANNOUNCE,
CVAR_RESET,
CVAR_HEALTH
};
new g_Pcvar[max_cvars];
new g_iFwdSpawn;
new g_iFwdPreThink;
new g_iMaxPlayers;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_EmitSound, "fwd_EmitSound", 1);
RegisterHam(Ham_Killed, "player", "fwd_Killed", 1);
unregister_forward(FM_Spawn, g_iFwdSpawn, 1);
register_event("CurWeapon", "Event_CurWeapon", "be", "1=1", "2!29")
register_logevent("logevent_RoundEnd", 2, "1=Round_End", "1=Round_Draw");
g_Pcvar[CVAR_COUNT] = register_cvar("kd_knifecount", "3");
g_Pcvar[CVAR_DELAY] = register_cvar("kd_delaytime", "30");
g_Pcvar[CVAR_TIMER] = register_cvar("kd_preparetime", "3");
g_iTimer = get_pcvar_num(g_Pcvar[CVAR_TIMER]);
g_Pcvar[CVAR_PROTECTION] = register_cvar("kd_protection", "1");
g_Pcvar[CVAR_MAXDISTANCE] = register_cvar("kd_maxdistance", "600");
g_Pcvar[CVAR_ANNOUNCE] = register_cvar("kd_announce", "1");
g_Pcvar[CVAR_RESET] = register_cvar("kd_resethp", "1");
g_Pcvar[CVAR_HEALTH] = register_cvar("kd_qtyhp", "35");
g_iMaxPlayers = get_maxplayers();
}
public plugin_precache()
g_iFwdSpawn = register_forward(FM_Spawn, "fwd_Spawn", 1);
public client_disconnect(id)
{
if((id == g_iChallenged) || (id == g_iChallenger))
{
g_fDelay[id] = 0.0;
g_bInChallenge = false;
}
}
public fwd_Spawn(ent)
{
if(!pev_valid(ent))
return FMRES_IGNORED;
static szClassname[32];
pev(ent, pev_classname, szClassname, sizeof szClassname - 1);
if(equal(szClassname, g_szSpawnClassname))
{
if(vec_null(g_vKnifeOrigin[0]))
{
pev(ent, pev_origin, g_vKnifeOrigin[0]);
}
else if(!vec_null(g_vKnifeOrigin[0]) && vec_null(g_vKnifeOrigin[1]))
{
static Float:vTmp[3];
pev(ent, pev_origin, vTmp);
if((300.0 <= vector_distance(g_vKnifeOrigin[0], vTmp) < 600.0))
g_vKnifeOrigin[1] = vTmp;
}
}
return FMRES_IGNORED;
}
public fwd_EmitSound(id, channel, const sound[])
{
if(!is_user_alive(id) || !equal(sound, g_szKnifeSound))
return FMRES_IGNORED;
static Float:fGmTime;
fGmTime = get_gametime();
if((fGmTime - g_fHit[id]) >= 1.0)
{
iHitCount[id] = 0;
g_fHit[id] = fGmTime;
}
++iHitCount[id];
g_fHit[id] = fGmTime;
if(iHitCount[id] >= get_pcvar_num(g_Pcvar[CVAR_COUNT]))
{
iHitCount[id] = 0;
if(g_bInChallenge || !check_players())
return FMRES_IGNORED;
if(fGmTime < g_fDelay[id])
{
ColorChat(id, "!y[!gДуэль!y] !yВы уже вызывали противника на дуэль. Подождите: !g%d!y секунд.", floatround(g_fDelay[id] - fGmTime));
return FMRES_IGNORED;
}
g_fDelay[id] = fGmTime + get_pcvar_float(g_Pcvar[CVAR_DELAY]);
static iOpponent
iOpponent = get_opponent(3 - get_user_team(id));
if(!iOpponent)
return FMRES_IGNORED;
fnChallenge(id, iOpponent);
}
return FMRES_IGNORED;
}
public fwd_PlayerPreThink_post(id)
{
if(!g_bInChallenge || !is_user_alive(id))
return FMRES_IGNORED;
static iOpponent;
if(id == g_iChallenged)
iOpponent = g_iChallenger;
else
iOpponent = g_iChallenged;
if(!is_user_connected(iOpponent))
return FMRES_IGNORED;
if(fm_get_entity_distance(id, iOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE]))
{
static Float:vVel[3];
fm_get_speed_vector2(id, iOpponent, 100.0, vVel);
set_pev(id, pev_velocity, vVel);
}
return FMRES_IGNORED;
}
public Event_CurWeapon(id)
{
if(!g_bInChallenge)
return
if(id == g_iChallenger || id == g_iChallenged)
engclient_cmd(id, "weapon_knife")
}
public fwd_Killed(id, idattacker, shouldgib)
{
if(!get_pcvar_num(g_Pcvar[CVAR_ANNOUNCE]))
return HAM_IGNORED;
if(check_players())
{
for(new i = 0; i <= g_iMaxPlayers; i++)
{
if(!is_user_alive(i))
continue;
ColorChat(i, "!y[!gИнформация!y] !yДля вызова противника на !gдуэль!y, ударь о стену !g%d!y раза ножом.", get_pcvar_num(g_Pcvar[CVAR_COUNT]));
}
}
return HAM_IGNORED;
}
public fnChallenge(id, opponent)
{
new szName[32], szOppName[32];
get_user_name(id, szName, sizeof szName - 1);
get_user_name(opponent, szOppName, sizeof szOppName - 1);
new szTitle[64];
formatex(szTitle, sizeof szTitle - 1, "\wИгрок\r %s \wвызвал Вас на дуэль!", szName);
g_iMenu = menu_create(szTitle, "menu_MainHandler", 0);
menu_additem(g_iMenu, "Да, я согласен!", "1", 0, -1);
menu_additem(g_iMenu, "Нет, я не согласен.", "2", 0, -1);
menu_setprop(g_iMenu, MPROP_EXIT, MEXIT_NEVER);
menu_display(opponent, g_iMenu, 0);
ColorChat(0, "!y[!gДуэль!y] !yИгрок !t%s !yвызвал !t%s !yна !gдуэль!y.", szName, szOppName);
g_iChallenger = id;
g_iChallenged = opponent;
}
public menu_MainHandler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new szData[6], iAccess, iCallBack;
menu_item_getinfo(menu, item, iAccess, szData, sizeof szData - 1, _, _, iCallBack);
new iKey = str_to_num(szData);
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
switch(iKey)
{
case 1:
{
ColorChat(0, "!y[!gДуэль!y] !yИгрок !t%s !yсогласен на !gдуэль!y!", szName);
fnStartDuel();
}
case 2: ColorChat(0, "!y[!gДуэль!y] !yИгрок !t%s !yотказался от !gдуэли!", szName);
}
return PLUGIN_HANDLED;
}
public fnStartDuel()
{
if(!is_user_connected(g_iChallenged) || !is_user_connected(g_iChallenger))
return;
engfunc(EngFunc_SetOrigin, g_iChallenged, g_vKnifeOrigin[0]);
engfunc(EngFunc_SetOrigin, g_iChallenger, g_vKnifeOrigin[1]);
fm_entity_set_aim(g_iChallenged, g_iChallenger, 0);
fm_entity_set_aim(g_iChallenger, g_iChallenged, 0);
fm_set_user_godmode(g_iChallenged, 1);
fm_set_user_godmode(g_iChallenger, 1);
if(get_pcvar_num(g_Pcvar[CVAR_RESET]))
{
set_pev(g_iChallenged, pev_health, get_pcvar_float(g_Pcvar[CVAR_HEALTH]));
set_pev(g_iChallenger, pev_health, get_pcvar_float(g_Pcvar[CVAR_HEALTH]));
}
engclient_cmd(g_iChallenged, "weapon_knife");
engclient_cmd(g_iChallenger, "weapon_knife");
if(get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
g_iFwdPreThink = register_forward(FM_PlayerPreThink, "fwd_PlayerPreThink_post", 1);
g_bInChallenge = true;
g_iTimer = get_pcvar_num(g_Pcvar[CVAR_TIMER]);
set_task(1.0, "taskDuelThink");
}
public taskDuelThink()
{
if(g_iTimer > 0)
{
set_hudmessage(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.9, 1);
show_hudmessage(0, "Дуэль начнется через: %d", g_iTimer--);
set_task(1.0, "taskDuelThink");
}
else
{
set_hudmessage(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.5, 1);
show_hudmessage(0, "Дуэль началась!");
fm_set_user_godmode(g_iChallenged, 0);
fm_set_user_godmode(g_iChallenger, 0);
}
}
public logevent_RoundEnd()
{
if(g_bInChallenge)
{
g_bInChallenge = false;
if(get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
unregister_forward(FM_Spawn, g_iFwdPreThink, 1);
}
if(g_iChallenged)
{
new iCrap, iMenuId;
player_menu_info(g_iChallenged, iCrap, iMenuId);
if(iMenuId != -1 && iMenuId == g_iMenu)
{
menu_cancel(g_iChallenged);
show_menu(g_iChallenged, 0, "^n", 1);
}
g_fDelay[g_iChallenged] = g_fDelay[g_iChallenger] = 0.0;
}
}
stock fm_entity_set_aim(id, ent, bone = 0)
{
if(!is_user_connected(id) || !pev_valid(ent))
return 0;
new Float:vOrigin[3];
pev(ent, pev_origin, vOrigin);
new Float:vEntOrigin[3], Float:vAngles[3];
if(bone)
engfunc(EngFunc_GetBonePosition, id, bone, vEntOrigin, vAngles);
else
pev(id, pev_origin, vEntOrigin);
vOrigin[0] -= vEntOrigin[0];
vOrigin[1] -= vEntOrigin[1];
vOrigin[2] -= vEntOrigin[2];
new Float:v_length;
v_length = vector_length(vOrigin);
new Float:vAimVector[3];
vAimVector[0] = vOrigin[0] / v_length;
vAimVector[1] = vOrigin[1] / v_length;
vAimVector[2] = vOrigin[2] / v_length;
new Float:vNewAngles[3];
vector_to_angle(vAimVector, vNewAngles);
vNewAngles[0] *= -1;
if(vNewAngles[1] > 180.0) vNewAngles[1] -= 360;
if(vNewAngles[1] < -180.0) vNewAngles[1] += 360;
if(vNewAngles[1] == 180.0 || vNewAngles[1] == -180.0) vNewAngles[1] = -179.9;
set_pev(id, pev_angles, vNewAngles);
set_pev(id, pev_fixangle, 1);
return 1;
}
stock vec_null(Float:vec[3])
{
if(!vec[0] && !vec[1] && !vec[2])
return 1;
return 0;
}
stock bool:check_players()
{
new iNum[2];
for(new i = 1; i <= g_iMaxPlayers; i++)
{
if(!is_user_alive(i))
continue;
if(get_user_team(i) == 1)
++iNum[0];
else if(get_user_team(i) == 2)
++iNum[1];
}
if((iNum[0] == 1) && (iNum[1] == 1))
return true;
return false;
}
stock get_opponent(team)
{
for(new i = 0; i <= g_iMaxPlayers; i++)
{
if(!is_user_alive(i))
continue;
if(get_user_team(i) == team)
return i;
}
return 0;
}
stock fm_set_user_godmode(index, godmode = 0)
{
set_pev(index, pev_takedamage, godmode == 1 ? DAMAGE_NO : DAMAGE_AIM);
return 1;
}
stock fm_get_speed_vector2(ent1, ent2, Float:speed, Float:new_velocity[3])
{
if(!pev_valid(ent1) || !pev_valid(ent2))
return 0;
static Float:vOrigin1[3];
pev(ent1, pev_origin, vOrigin1);
static Float:vOrigin2[3];
pev(ent2, pev_origin, vOrigin2);
new_velocity[0] = vOrigin2[0] - vOrigin1[0];
new_velocity[1] = vOrigin2[1] - vOrigin1[1];
new_velocity[2] = vOrigin2[2] - vOrigin1[2];
new Float:fNum = floatsqroot(speed * speed / (new_velocity[0] * new_velocity[0] + new_velocity[1] * new_velocity[1] + new_velocity[2] * new_velocity[2]));
new_velocity[0] *= fNum;
new_velocity[1] *= fNum;
new_velocity[2] *= fNum;
return 1;
}
stock Float:fm_get_entity_distance(ent1, ent2)
{
if(!pev_valid(ent1) || !pev_valid(ent2))
return 0.0;
static Float:vOrigin1[3];
pev(ent1, pev_origin, vOrigin1);
static Float:vOrigin2[3];
pev(ent2, pev_origin, vOrigin2);
return vector_distance(vOrigin1, vOrigin2);
}
stock ColorChat(const id, const input[], any:...)
{
new count = 1, players[32]
static msg[191]
vformat(msg, 190, input, 3)
format(msg, sizeof(msg), "%s", msg)
replace_all(msg, 190, "!g", "^4") // Green Color
replace_all(msg, 190, "!y", "^1") // Default Color
replace_all(msg, 190, "!t", "^3") // Team Color
if (id) players[0] = id; else get_players(players, count, "ch")
{
for (new i = 0; i < count; i++)
{
if (is_user_connected(players))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players)
write_byte(players);
write_string(msg);
message_end();
}
}
}
}
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka"
new const g_szKnifeSound[] = "weapons/knife_hitwall1.wav";
new const g_szSpawnClassname[] = "info_player_deathmatch";
new Float:g_fHit[33];
new Float:g_fDelay[33];
new iHitCount[33];
new g_iChallenged, g_iChallenger;
new Float:g_vKnifeOrigin[2][3];
new bool:g_bInChallenge;
new g_iTimer;
new g_iMenu;
enum _:max_cvars {
CVAR_COUNT = 0,
CVAR_DELAY,
CVAR_TIMER,
CVAR_MAXDISTANCE,
CVAR_PROTECTION,
CVAR_ANNOUNCE,
CVAR_RESET,
CVAR_HEALTH
};
new g_Pcvar[max_cvars];
new g_iFwdSpawn;
new g_iFwdPreThink;
new g_iMaxPlayers;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_EmitSound, "fwd_EmitSound", 1);
RegisterHam(Ham_Killed, "player", "fwd_Killed", 1);
unregister_forward(FM_Spawn, g_iFwdSpawn, 1);
register_event("CurWeapon", "Event_CurWeapon", "be", "1=1", "2!29")
register_logevent("logevent_RoundEnd", 2, "1=Round_End", "1=Round_Draw");
g_Pcvar[CVAR_COUNT] = register_cvar("kd_knifecount", "3");
g_Pcvar[CVAR_DELAY] = register_cvar("kd_delaytime", "30");
g_Pcvar[CVAR_TIMER] = register_cvar("kd_preparetime", "3");
g_iTimer = get_pcvar_num(g_Pcvar[CVAR_TIMER]);
g_Pcvar[CVAR_PROTECTION] = register_cvar("kd_protection", "1");
g_Pcvar[CVAR_MAXDISTANCE] = register_cvar("kd_maxdistance", "600");
g_Pcvar[CVAR_ANNOUNCE] = register_cvar("kd_announce", "1");
g_Pcvar[CVAR_RESET] = register_cvar("kd_resethp", "1");
g_Pcvar[CVAR_HEALTH] = register_cvar("kd_qtyhp", "35");
g_iMaxPlayers = get_maxplayers();
}
public plugin_precache()
g_iFwdSpawn = register_forward(FM_Spawn, "fwd_Spawn", 1);
public client_disconnect(id)
{
if((id == g_iChallenged) || (id == g_iChallenger))
{
g_fDelay[id] = 0.0;
g_bInChallenge = false;
}
}
public fwd_Spawn(ent)
{
if(!pev_valid(ent))
return FMRES_IGNORED;
static szClassname[32];
pev(ent, pev_classname, szClassname, sizeof szClassname - 1);
if(equal(szClassname, g_szSpawnClassname))
{
if(vec_null(g_vKnifeOrigin[0]))
{
pev(ent, pev_origin, g_vKnifeOrigin[0]);
}
else if(!vec_null(g_vKnifeOrigin[0]) && vec_null(g_vKnifeOrigin[1]))
{
static Float:vTmp[3];
pev(ent, pev_origin, vTmp);
if((300.0 <= vector_distance(g_vKnifeOrigin[0], vTmp) < 600.0))
g_vKnifeOrigin[1] = vTmp;
}
}
return FMRES_IGNORED;
}
public fwd_EmitSound(id, channel, const sound[])
{
if(!is_user_alive(id) || !equal(sound, g_szKnifeSound))
return FMRES_IGNORED;
static Float:fGmTime;
fGmTime = get_gametime();
if((fGmTime - g_fHit[id]) >= 1.0)
{
iHitCount[id] = 0;
g_fHit[id] = fGmTime;
}
++iHitCount[id];
g_fHit[id] = fGmTime;
if(iHitCount[id] >= get_pcvar_num(g_Pcvar[CVAR_COUNT]))
{
iHitCount[id] = 0;
if(g_bInChallenge || !check_players())
return FMRES_IGNORED;
if(fGmTime < g_fDelay[id])
{
ColorChat(id, "!y[!gДуэль!y] !yВы уже вызывали противника на дуэль. Подождите: !g%d!y секунд.", floatround(g_fDelay[id] - fGmTime));
return FMRES_IGNORED;
}
g_fDelay[id] = fGmTime + get_pcvar_float(g_Pcvar[CVAR_DELAY]);
static iOpponent
iOpponent = get_opponent(3 - get_user_team(id));
if(!iOpponent)
return FMRES_IGNORED;
fnChallenge(id, iOpponent);
}
return FMRES_IGNORED;
}
public fwd_PlayerPreThink_post(id)
{
if(!g_bInChallenge || !is_user_alive(id))
return FMRES_IGNORED;
static iOpponent;
if(id == g_iChallenged)
iOpponent = g_iChallenger;
else
iOpponent = g_iChallenged;
if(!is_user_connected(iOpponent))
return FMRES_IGNORED;
if(fm_get_entity_distance(id, iOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE]))
{
static Float:vVel[3];
fm_get_speed_vector2(id, iOpponent, 100.0, vVel);
set_pev(id, pev_velocity, vVel);
}
return FMRES_IGNORED;
}
public Event_CurWeapon(id)
{
if(!g_bInChallenge)
return
if(id == g_iChallenger || id == g_iChallenged)
engclient_cmd(id, "weapon_knife")
}
public fwd_Killed(id, idattacker, shouldgib)
{
if(!get_pcvar_num(g_Pcvar[CVAR_ANNOUNCE]))
return HAM_IGNORED;
if(check_players())
{
for(new i = 0; i <= g_iMaxPlayers; i++)
{
if(!is_user_alive(i))
continue;
ColorChat(i, "!y[!gИнформация!y] !yДля вызова противника на !gдуэль!y, ударь о стену !g%d!y раза ножом.", get_pcvar_num(g_Pcvar[CVAR_COUNT]));
}
}
return HAM_IGNORED;
}
public fnChallenge(id, opponent)
{
new szName[32], szOppName[32];
get_user_name(id, szName, sizeof szName - 1);
get_user_name(opponent, szOppName, sizeof szOppName - 1);
new szTitle[64];
formatex(szTitle, sizeof szTitle - 1, "\wИгрок\r %s \wвызвал Вас на дуэль!", szName);
g_iMenu = menu_create(szTitle, "menu_MainHandler", 0);
menu_additem(g_iMenu, "Да, я согласен!", "1", 0, -1);
menu_additem(g_iMenu, "Нет, я не согласен.", "2", 0, -1);
menu_setprop(g_iMenu, MPROP_EXIT, MEXIT_NEVER);
menu_display(opponent, g_iMenu, 0);
ColorChat(0, "!y[!gДуэль!y] !yИгрок !t%s !yвызвал !t%s !yна !gдуэль!y.", szName, szOppName);
g_iChallenger = id;
g_iChallenged = opponent;
}
public menu_MainHandler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new szData[6], iAccess, iCallBack;
menu_item_getinfo(menu, item, iAccess, szData, sizeof szData - 1, _, _, iCallBack);
new iKey = str_to_num(szData);
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
switch(iKey)
{
case 1:
{
ColorChat(0, "!y[!gДуэль!y] !yИгрок !t%s !yсогласен на !gдуэль!y!", szName);
fnStartDuel();
}
case 2: ColorChat(0, "!y[!gДуэль!y] !yИгрок !t%s !yотказался от !gдуэли!", szName);
}
return PLUGIN_HANDLED;
}
public fnStartDuel()
{
if(!is_user_connected(g_iChallenged) || !is_user_connected(g_iChallenger))
return;
engfunc(EngFunc_SetOrigin, g_iChallenged, g_vKnifeOrigin[0]);
engfunc(EngFunc_SetOrigin, g_iChallenger, g_vKnifeOrigin[1]);
fm_entity_set_aim(g_iChallenged, g_iChallenger, 0);
fm_entity_set_aim(g_iChallenger, g_iChallenged, 0);
fm_set_user_godmode(g_iChallenged, 1);
fm_set_user_godmode(g_iChallenger, 1);
if(get_pcvar_num(g_Pcvar[CVAR_RESET]))
{
set_pev(g_iChallenged, pev_health, get_pcvar_float(g_Pcvar[CVAR_HEALTH]));
set_pev(g_iChallenger, pev_health, get_pcvar_float(g_Pcvar[CVAR_HEALTH]));
}
engclient_cmd(g_iChallenged, "weapon_knife");
engclient_cmd(g_iChallenger, "weapon_knife");
if(get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
g_iFwdPreThink = register_forward(FM_PlayerPreThink, "fwd_PlayerPreThink_post", 1);
g_bInChallenge = true;
g_iTimer = get_pcvar_num(g_Pcvar[CVAR_TIMER]);
set_task(1.0, "taskDuelThink");
}
public taskDuelThink()
{
if(g_iTimer > 0)
{
set_hudmessage(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.9, 1);
show_hudmessage(0, "Дуэль начнется через: %d", g_iTimer--);
set_task(1.0, "taskDuelThink");
}
else
{
set_hudmessage(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.5, 1);
show_hudmessage(0, "Дуэль началась!");
fm_set_user_godmode(g_iChallenged, 0);
fm_set_user_godmode(g_iChallenger, 0);
}
}
public logevent_RoundEnd()
{
if(g_bInChallenge)
{
g_bInChallenge = false;
if(get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
unregister_forward(FM_Spawn, g_iFwdPreThink, 1);
}
if(g_iChallenged)
{
new iCrap, iMenuId;
player_menu_info(g_iChallenged, iCrap, iMenuId);
if(iMenuId != -1 && iMenuId == g_iMenu)
{
menu_cancel(g_iChallenged);
show_menu(g_iChallenged, 0, "^n", 1);
}
g_fDelay[g_iChallenged] = g_fDelay[g_iChallenger] = 0.0;
}
}
stock fm_entity_set_aim(id, ent, bone = 0)
{
if(!is_user_connected(id) || !pev_valid(ent))
return 0;
new Float:vOrigin[3];
pev(ent, pev_origin, vOrigin);
new Float:vEntOrigin[3], Float:vAngles[3];
if(bone)
engfunc(EngFunc_GetBonePosition, id, bone, vEntOrigin, vAngles);
else
pev(id, pev_origin, vEntOrigin);
vOrigin[0] -= vEntOrigin[0];
vOrigin[1] -= vEntOrigin[1];
vOrigin[2] -= vEntOrigin[2];
new Float:v_length;
v_length = vector_length(vOrigin);
new Float:vAimVector[3];
vAimVector[0] = vOrigin[0] / v_length;
vAimVector[1] = vOrigin[1] / v_length;
vAimVector[2] = vOrigin[2] / v_length;
new Float:vNewAngles[3];
vector_to_angle(vAimVector, vNewAngles);
vNewAngles[0] *= -1;
if(vNewAngles[1] > 180.0) vNewAngles[1] -= 360;
if(vNewAngles[1] < -180.0) vNewAngles[1] += 360;
if(vNewAngles[1] == 180.0 || vNewAngles[1] == -180.0) vNewAngles[1] = -179.9;
set_pev(id, pev_angles, vNewAngles);
set_pev(id, pev_fixangle, 1);
return 1;
}
stock vec_null(Float:vec[3])
{
if(!vec[0] && !vec[1] && !vec[2])
return 1;
return 0;
}
stock bool:check_players()
{
new iNum[2];
for(new i = 1; i <= g_iMaxPlayers; i++)
{
if(!is_user_alive(i))
continue;
if(get_user_team(i) == 1)
++iNum[0];
else if(get_user_team(i) == 2)
++iNum[1];
}
if((iNum[0] == 1) && (iNum[1] == 1))
return true;
return false;
}
stock get_opponent(team)
{
for(new i = 0; i <= g_iMaxPlayers; i++)
{
if(!is_user_alive(i))
continue;
if(get_user_team(i) == team)
return i;
}
return 0;
}
stock fm_set_user_godmode(index, godmode = 0)
{
set_pev(index, pev_takedamage, godmode == 1 ? DAMAGE_NO : DAMAGE_AIM);
return 1;
}
stock fm_get_speed_vector2(ent1, ent2, Float:speed, Float:new_velocity[3])
{
if(!pev_valid(ent1) || !pev_valid(ent2))
return 0;
static Float:vOrigin1[3];
pev(ent1, pev_origin, vOrigin1);
static Float:vOrigin2[3];
pev(ent2, pev_origin, vOrigin2);
new_velocity[0] = vOrigin2[0] - vOrigin1[0];
new_velocity[1] = vOrigin2[1] - vOrigin1[1];
new_velocity[2] = vOrigin2[2] - vOrigin1[2];
new Float:fNum = floatsqroot(speed * speed / (new_velocity[0] * new_velocity[0] + new_velocity[1] * new_velocity[1] + new_velocity[2] * new_velocity[2]));
new_velocity[0] *= fNum;
new_velocity[1] *= fNum;
new_velocity[2] *= fNum;
return 1;
}
stock Float:fm_get_entity_distance(ent1, ent2)
{
if(!pev_valid(ent1) || !pev_valid(ent2))
return 0.0;
static Float:vOrigin1[3];
pev(ent1, pev_origin, vOrigin1);
static Float:vOrigin2[3];
pev(ent2, pev_origin, vOrigin2);
return vector_distance(vOrigin1, vOrigin2);
}
stock ColorChat(const id, const input[], any:...)
{
new count = 1, players[32]
static msg[191]
vformat(msg, 190, input, 3)
format(msg, sizeof(msg), "%s", msg)
replace_all(msg, 190, "!g", "^4") // Green Color
replace_all(msg, 190, "!y", "^1") // Default Color
replace_all(msg, 190, "!t", "^3") // Team Color
if (id) players[0] = id; else get_players(players, count, "ch")
{
for (new i = 0; i < count; i++)
{
if (is_user_connected(players))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players)
write_byte(players);
write_string(msg);
message_end();
}
}
}
}