This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Solved Help with this knife duel plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 04-29-2024 , 04:58   Help with this knife duel plugin
Reply With Quote #1

I'm using this plugin, when there are only 2 players left, you can challenge your opponent to a knife duel by hitting the wall with the knife 3 times.

There is one bug though. If someone challenges you and you don't accept or refuse and let the menu open until next round, you can accept the challenge then and everyone is forced into the duel and get stripped of their weapons.

How can I fix that? I've tried closing the menu automatically when a new round starts, but nothing seems to work.


PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "CS Revo: Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka | Wilian M."

#define CBASE_CURRWPN_ENT 373
#define OFFSET_ENT_TO_INDEX 43

#define PREFIX_CHAT "^4[ ^1CS Revo! ^4]"

new const g_szKnifeSound[] = "weapons/knife_hitwall1.wav";
new const 
g_szSpawnClassname[] = "info_player_deathmatch";

new 
Float:g_fHit[33];
new 
iHitCount[33];
new 
g_iChallengedg_iChallenger;

new 
Float:g_vKnifeOrigin[2][3];
new 
bool:g_bInChallenge;
new 
bool:g_bProtect;
new 
g_iTimer;

enum _:max_cvars {
    
    
CVAR_COUNT 0,
    
CVAR_TIMER,
    
CVAR_MAXDISTANCE,
    
CVAR_PROTECTION,
    
CVAR_ANNOUNCE,
    
CVAR_RESET
};

new 
g_Pcvar[max_cvars];

new 
g_iFwdSpawn;

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_forward(FM_EmitSound"fwd_EmitSound"1);
    
register_forward(FM_PlayerPreThink"fwd_PlayerPreThink_post"1);
    
RegisterHam(Ham_Killed"player""fwd_Killed"1);
    
unregister_forward(FM_Spawng_iFwdSpawn1);
    
    
register_logevent("logevent_RoundEnd"2"1=Round_End""1=Round_Draw");
    
    
g_Pcvar[CVAR_COUNT] = register_cvar("kd_knifecount""3");
    
g_Pcvar[CVAR_TIMER] = register_cvar("kd_preparetime""10");
    
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")

}

public 
plugin_precache()
    
g_iFwdSpawn register_forward(FM_Spawn"fwd_Spawn"1);

public 
client_disconnected(id)
{
    if((
id == g_iChallenged) || (id == g_iChallenger))
    {
        
g_bInChallenge false;
        
g_bProtect false;
    }
}

public 
fwd_Spawn(ent)
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED;
    
    static 
szClassname[32];
    
pev(entpev_classnameszClassnamesizeof szClassname 1);
    
    if(
equal(szClassnameg_szSpawnClassname))
    {
        if(
vec_null(g_vKnifeOrigin[0]))
        {
            
pev(entpev_origing_vKnifeOrigin[0]);
        }
        else if(!
vec_null(g_vKnifeOrigin[0]) && vec_null(g_vKnifeOrigin[1]))
        {
            static 
Float:vTmp[3];
            
pev(entpev_originvTmp);
            
            if((
300.0 <= vector_distance(g_vKnifeOrigin[0], vTmp) < 600.0))
                
g_vKnifeOrigin[1] = vTmp;
        }
    }
    return 
FMRES_IGNORED;
}

public 
fwd_EmitSound(idchannel, const sound[])
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED;
    
    if(!
equal(soundg_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])) && check_players() && !g_bInChallenge)
    {
        new 
iOpponent get_opponent(get_user_team(id));
        if(!
iOpponent)
            return 
FMRES_IGNORED;
        
        
fnChallenge(idiOpponent);
        
        
iHitCount[id] = 0;
    }
    return 
FMRES_IGNORED;
}

public 
fwd_PlayerPreThink_post(id)
{
    if(!
is_user_alive(id) || !g_bInChallenge)
        return 
FMRES_IGNORED;
    
    static 
iWpn;
    
iWpn get_pdata_cbase(idCBASE_CURRWPN_ENT);
    
    if(
pev_valid(iWpn))
    {
        if(
get_pdata_int(iWpnOFFSET_ENT_TO_INDEX) != CSW_KNIFE)
            
engclient_cmd(id"weapon_knife");
    }
    
    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(idiOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE])) && g_bProtect)
    {
        static 
Float:vVel[3];
        
fm_get_speed_vector2(idiOpponent100.0vVel);
        
        
set_pev(idpev_velocityvVel);
    }
    return 
FMRES_IGNORED;
}

public 
fwd_Killed(ididattackershouldgib)
{
    if(!
get_pcvar_num(g_Pcvar[CVAR_ANNOUNCE]))
        return 
HAM_IGNORED;
    
    if(
check_players())
    {
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
client_print_color(iprint_team_default"%s ^3You can challenge your enemy to a knife duel hitting the wall 3 times!"PREFIX_CHAT)
        }
    }
    return 
HAM_IGNORED;
}

public 
fnChallenge(idopponent)
{
    new 
szName[32], szOppName[32];
    
get_user_name(idszNamesizeof szName 1);
    
get_user_name(opponentszOppNamesizeof szOppName 1);
    
    new 
szTitle[64];
    
formatex(szTitlesizeof szTitle 1"\r%s \yis challenging you to a knife duel"szName);
    
    new 
iMenu menu_create(szTitle"menu_MainHandler"0);
    
menu_additem(iMenu"Accept""1"0, -1);
    
menu_additem(iMenu"No, thanks""2"0, -1);
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_NEVER);
    
menu_display(opponentiMenu0);

    
client_print_color(0print_team_default"%s ^4%s ^3challenged ^4%s ^3to a knife duel."PREFIX_CHATszNameszOppName)
    
    
g_iChallenger id;
    
g_iChallenged opponent;
    
g_bInChallenge true;
}

public 
menu_MainHandler(idmenuitem)
{
    if(!
is_user_connected(id))
        return 
1;
    
    new 
szData[6], iAccessiCallBack;
    
menu_item_getinfo(menuitemiAccessszDatasizeof szData 1__iCallBack);
    
    new 
iKey str_to_num(szData);
    
    new 
szName[32];
    
get_user_name(idszNamesizeof szName 1);
    
    switch(
iKey)
    {
        case 
1:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3accepted the knife duel."PREFIX_CHATszName)
            
fnStartDuel();
        }
        case 
2:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3refused the knife duel."PREFIX_CHATszName)
            
g_bInChallenge false;
        }
    }
    return 
1;
}

public 
fnStartDuel()
{
    if(!
is_user_connected(g_iChallenged) || !is_user_connected(g_iChallenger))
        return;
    
    
engfunc(EngFunc_SetOriging_iChallengedg_vKnifeOrigin[0]);
    
engfunc(EngFunc_SetOriging_iChallengerg_vKnifeOrigin[1]);
    
    
fm_entity_set_aim(g_iChallengedg_iChallenger0);
    
fm_entity_set_aim(g_iChallengerg_iChallenged0);
    
    
fm_set_user_godmode(g_iChallenged1);
    
fm_set_user_godmode(g_iChallenger1);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_RESET]))
    {
        
set_pev(g_iChallengedpev_health100.0);
        
set_pev(g_iChallengerpev_health100.0);
    }
    
set_task(1.0"taskDuelThink"'x'""0"b"0);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
        
g_bProtect true;
}

public 
taskDuelThink()
{
    if(
g_iTimer 0)
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.91);
        
show_hudmessage(0"Countdown: %d"g_iTimer--);
    }
    else
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.51);
        
show_hudmessage(0"The duel started!");
        
        
g_iTimer get_pcvar_num(g_Pcvar[CVAR_TIMER]);
        
remove_task('x');
        
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
fm_set_user_godmode(i0);
        }
    }
}

public 
logevent_RoundEnd()
{
    
g_bInChallenge false;
    
g_bProtect false;
}

stock fm_entity_set_aim(identbone 0)
{
    if(!
is_user_connected(id) || !pev_valid(ent))
        return 
0;
    
    new 
Float:vOrigin[3];
    
pev(entpev_originvOrigin);
    
    new 
Float:vEntOrigin[3], Float:vAngles[3];
    
    if(
bone)
        
engfunc(EngFunc_GetBonePositionidbonevEntOriginvAngles);
    else
        
pev(idpev_originvEntOrigin);
    
    
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(vAimVectorvNewAngles);
    
    
vNewAngles[0] *= -1;
    
    if(
vNewAngles[1] > 180.0vNewAngles[1] -= 360;
    if(
vNewAngles[1] < -180.0vNewAngles[1] += 360;
    if(
vNewAngles[1] == 180.0 || vNewAngles[1] == -180.0vNewAngles[1] = -179.9;
    
    
set_pev(idpev_anglesvNewAngles);
    
set_pev(idpev_fixangle1);
    
    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 
<= MaxClients 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 
<= MaxClients i++)
    {
        if(!
is_user_alive(i))
            continue;
        
        if(
get_user_team(i) == team)
            return 
i;
    }
    return 
0;
}

stock fm_set_user_godmode(indexgodmode 0)
{
    
set_pev(indexpev_takedamagegodmode == DAMAGE_NO DAMAGE_AIM);
    return 
1;
}

stock fm_get_speed_vector2(ent1ent2Float:speedFloat:new_velocity[3])
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    
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(ent1ent2)
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0.0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    return 
vector_distance(vOrigin1vOrigin2);


Last edited by JuanitoAlimana; 05-08-2024 at 00:24.
JuanitoAlimana is offline
Ace67
Senior Member
Join Date: Sep 2020
Location: France
Old 04-29-2024 , 14:51   Re: Help with this knife duel plugin
Reply With Quote #2

Quote:
Originally Posted by JuanitoAlimana View Post
I'm using this plugin, when there are only 2 players left, you can challenge your opponent to a knife duel by hitting the wall with the knife 3 times.

There is one bug though. If someone challenges you and you don't accept or refuse and let the menu open until next round, you can accept the challenge then and everyone is forced into the duel and get stripped of their weapons.

How can I fix that? I've tried closing the menu automatically when a new round starts, but nothing seems to work.


PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "CS Revo: Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka | Wilian M."

#define CBASE_CURRWPN_ENT 373
#define OFFSET_ENT_TO_INDEX 43

#define PREFIX_CHAT "^4[ ^1CS Revo! ^4]"

new const g_szKnifeSound[] = "weapons/knife_hitwall1.wav";
new const 
g_szSpawnClassname[] = "info_player_deathmatch";

new 
Float:g_fHit[33];
new 
iHitCount[33];
new 
g_iChallengedg_iChallenger;

new 
Float:g_vKnifeOrigin[2][3];
new 
bool:g_bInChallenge;
new 
bool:g_bProtect;
new 
g_iTimer;

enum _:max_cvars {
    
    
CVAR_COUNT 0,
    
CVAR_TIMER,
    
CVAR_MAXDISTANCE,
    
CVAR_PROTECTION,
    
CVAR_ANNOUNCE,
    
CVAR_RESET
};

new 
g_Pcvar[max_cvars];

new 
g_iFwdSpawn;

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_forward(FM_EmitSound"fwd_EmitSound"1);
    
register_forward(FM_PlayerPreThink"fwd_PlayerPreThink_post"1);
    
RegisterHam(Ham_Killed"player""fwd_Killed"1);
    
unregister_forward(FM_Spawng_iFwdSpawn1);
    
    
register_logevent("logevent_RoundEnd"2"1=Round_End""1=Round_Draw");
    
    
g_Pcvar[CVAR_COUNT] = register_cvar("kd_knifecount""3");
    
g_Pcvar[CVAR_TIMER] = register_cvar("kd_preparetime""10");
    
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")

}

public 
plugin_precache()
    
g_iFwdSpawn register_forward(FM_Spawn"fwd_Spawn"1);

public 
client_disconnected(id)
{
    if((
id == g_iChallenged) || (id == g_iChallenger))
    {
        
g_bInChallenge false;
        
g_bProtect false;
    }
}

public 
fwd_Spawn(ent)
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED;
    
    static 
szClassname[32];
    
pev(entpev_classnameszClassnamesizeof szClassname 1);
    
    if(
equal(szClassnameg_szSpawnClassname))
    {
        if(
vec_null(g_vKnifeOrigin[0]))
        {
            
pev(entpev_origing_vKnifeOrigin[0]);
        }
        else if(!
vec_null(g_vKnifeOrigin[0]) && vec_null(g_vKnifeOrigin[1]))
        {
            static 
Float:vTmp[3];
            
pev(entpev_originvTmp);
            
            if((
300.0 <= vector_distance(g_vKnifeOrigin[0], vTmp) < 600.0))
                
g_vKnifeOrigin[1] = vTmp;
        }
    }
    return 
FMRES_IGNORED;
}

public 
fwd_EmitSound(idchannel, const sound[])
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED;
    
    if(!
equal(soundg_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])) && check_players() && !g_bInChallenge)
    {
        new 
iOpponent get_opponent(get_user_team(id));
        if(!
iOpponent)
            return 
FMRES_IGNORED;
        
        
fnChallenge(idiOpponent);
        
        
iHitCount[id] = 0;
    }
    return 
FMRES_IGNORED;
}

public 
fwd_PlayerPreThink_post(id)
{
    if(!
is_user_alive(id) || !g_bInChallenge)
        return 
FMRES_IGNORED;
    
    static 
iWpn;
    
iWpn get_pdata_cbase(idCBASE_CURRWPN_ENT);
    
    if(
pev_valid(iWpn))
    {
        if(
get_pdata_int(iWpnOFFSET_ENT_TO_INDEX) != CSW_KNIFE)
            
engclient_cmd(id"weapon_knife");
    }
    
    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(idiOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE])) && g_bProtect)
    {
        static 
Float:vVel[3];
        
fm_get_speed_vector2(idiOpponent100.0vVel);
        
        
set_pev(idpev_velocityvVel);
    }
    return 
FMRES_IGNORED;
}

public 
fwd_Killed(ididattackershouldgib)
{
    if(!
get_pcvar_num(g_Pcvar[CVAR_ANNOUNCE]))
        return 
HAM_IGNORED;
    
    if(
check_players())
    {
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
client_print_color(iprint_team_default"%s ^3You can challenge your enemy to a knife duel hitting the wall 3 times!"PREFIX_CHAT)
        }
    }
    return 
HAM_IGNORED;
}

public 
fnChallenge(idopponent)
{
    new 
szName[32], szOppName[32];
    
get_user_name(idszNamesizeof szName 1);
    
get_user_name(opponentszOppNamesizeof szOppName 1);
    
    new 
szTitle[64];
    
formatex(szTitlesizeof szTitle 1"\r%s \yis challenging you to a knife duel"szName);
    
    new 
iMenu menu_create(szTitle"menu_MainHandler"0);
    
menu_additem(iMenu"Accept""1"0, -1);
    
menu_additem(iMenu"No, thanks""2"0, -1);
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_NEVER);
    
menu_display(opponentiMenu0);

    
client_print_color(0print_team_default"%s ^4%s ^3challenged ^4%s ^3to a knife duel."PREFIX_CHATszNameszOppName)
    
    
g_iChallenger id;
    
g_iChallenged opponent;
    
g_bInChallenge true;
}

public 
menu_MainHandler(idmenuitem)
{
    if(!
is_user_connected(id))
        return 
1;
    
    new 
szData[6], iAccessiCallBack;
    
menu_item_getinfo(menuitemiAccessszDatasizeof szData 1__iCallBack);
    
    new 
iKey str_to_num(szData);
    
    new 
szName[32];
    
get_user_name(idszNamesizeof szName 1);
    
    switch(
iKey)
    {
        case 
1:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3accepted the knife duel."PREFIX_CHATszName)
            
fnStartDuel();
        }
        case 
2:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3refused the knife duel."PREFIX_CHATszName)
            
g_bInChallenge false;
        }
    }
    return 
1;
}

public 
fnStartDuel()
{
    if(!
is_user_connected(g_iChallenged) || !is_user_connected(g_iChallenger))
        return;
    
    
engfunc(EngFunc_SetOriging_iChallengedg_vKnifeOrigin[0]);
    
engfunc(EngFunc_SetOriging_iChallengerg_vKnifeOrigin[1]);
    
    
fm_entity_set_aim(g_iChallengedg_iChallenger0);
    
fm_entity_set_aim(g_iChallengerg_iChallenged0);
    
    
fm_set_user_godmode(g_iChallenged1);
    
fm_set_user_godmode(g_iChallenger1);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_RESET]))
    {
        
set_pev(g_iChallengedpev_health100.0);
        
set_pev(g_iChallengerpev_health100.0);
    }
    
set_task(1.0"taskDuelThink"'x'""0"b"0);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
        
g_bProtect true;
}

public 
taskDuelThink()
{
    if(
g_iTimer 0)
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.91);
        
show_hudmessage(0"Countdown: %d"g_iTimer--);
    }
    else
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.51);
        
show_hudmessage(0"The duel started!");
        
        
g_iTimer get_pcvar_num(g_Pcvar[CVAR_TIMER]);
        
remove_task('x');
        
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
fm_set_user_godmode(i0);
        }
    }
}

public 
logevent_RoundEnd()
{
    
g_bInChallenge false;
    
g_bProtect false;
}

stock fm_entity_set_aim(identbone 0)
{
    if(!
is_user_connected(id) || !pev_valid(ent))
        return 
0;
    
    new 
Float:vOrigin[3];
    
pev(entpev_originvOrigin);
    
    new 
Float:vEntOrigin[3], Float:vAngles[3];
    
    if(
bone)
        
engfunc(EngFunc_GetBonePositionidbonevEntOriginvAngles);
    else
        
pev(idpev_originvEntOrigin);
    
    
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(vAimVectorvNewAngles);
    
    
vNewAngles[0] *= -1;
    
    if(
vNewAngles[1] > 180.0vNewAngles[1] -= 360;
    if(
vNewAngles[1] < -180.0vNewAngles[1] += 360;
    if(
vNewAngles[1] == 180.0 || vNewAngles[1] == -180.0vNewAngles[1] = -179.9;
    
    
set_pev(idpev_anglesvNewAngles);
    
set_pev(idpev_fixangle1);
    
    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 
<= MaxClients 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 
<= MaxClients i++)
    {
        if(!
is_user_alive(i))
            continue;
        
        if(
get_user_team(i) == team)
            return 
i;
    }
    return 
0;
}

stock fm_set_user_godmode(indexgodmode 0)
{
    
set_pev(indexpev_takedamagegodmode == DAMAGE_NO DAMAGE_AIM);
    return 
1;
}

stock fm_get_speed_vector2(ent1ent2Float:speedFloat:new_velocity[3])
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    
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(ent1ent2)
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0.0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    return 
vector_distance(vOrigin1vOrigin2);

PHP Code:
register_logevent("logevent_RoundStart"2"1=Round_Start""1=Round_Draw"); 
PHP Code:
public logevent_RoundEnd()
{
    
g_bInChallenge false;
    
g_bProtect false;
}

public 
logevent_RoundStart()
{
    
close_challenge_menus();
}

public 
close_challenge_menus()
{
    for (new 
1<= MaxClientsi++)
    {
        if (
is_menu_active(i))
        {
            
close_menu(i);
        }
    }

__________________
CS:CZ > CS 1.6
Ace67 is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-03-2024 , 18:34   Re: Help with this knife duel plugin
Reply With Quote #3

Quote:
Originally Posted by Ace67 View Post
PHP Code:
register_logevent("logevent_RoundStart"2"1=Round_Start""1=Round_Draw"); 
PHP Code:
public logevent_RoundEnd()
{
    
g_bInChallenge false;
    
g_bProtect false;
}

public 
logevent_RoundStart()
{
    
close_challenge_menus();
}

public 
close_challenge_menus()
{
    for (new 
1<= MaxClientsi++)
    {
        if (
is_menu_active(i))
        {
            
close_menu(i);
        }
    }

error 017: undefined symbol "is_menu_active"
error 017: undefined symbol "close_menu"
JuanitoAlimana is offline
v120kaaimcfg
Member
Join Date: Apr 2024
Old 05-03-2024 , 20:32   Re: Help with this knife duel plugin
Reply With Quote #4

Quote:
Originally Posted by JuanitoAlimana View Post
I'm using this plugin, when there are only 2 players left, you can challenge your opponent to a knife duel by hitting the wall with the knife 3 times.

There is one bug though. If someone challenges you and you don't accept or refuse and let the menu open until next round, you can accept the challenge then and everyone is forced into the duel and get stripped of their weapons.

How can I fix that? I've tried closing the menu automatically when a new round starts, but nothing seems to work.
Here
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "CS Revo: Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka | Wilian M."

#define CBASE_CURRWPN_ENT 373
#define OFFSET_ENT_TO_INDEX 43

#define PREFIX_CHAT "^4[ ^1CS Revo! ^4]"

new const g_szKnifeSound[] = "weapons/knife_hitwall1.wav";
new const 
g_szSpawnClassname[] = "info_player_deathmatch";

new 
Float:g_fHit[33];
new 
iHitCount[33];
new 
g_iChallengedg_iChallenger;

new 
Float:g_vKnifeOrigin[2][3];
new 
bool:g_bInChallenge;
new 
bool:g_bProtect;
new 
g_iTimer;

enum _:max_cvars {
    
    
CVAR_COUNT 0,
    
CVAR_TIMER,
    
CVAR_MAXDISTANCE,
    
CVAR_PROTECTION,
    
CVAR_ANNOUNCE,
    
CVAR_RESET
};

new 
g_Pcvar[max_cvars];

new 
g_iFwdSpawn;

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_forward(FM_EmitSound"fwd_EmitSound"1);
    
register_forward(FM_PlayerPreThink"fwd_PlayerPreThink_post"1);
    
RegisterHam(Ham_Killed"player""fwd_Killed"1);
    
unregister_forward(FM_Spawng_iFwdSpawn1);
    
    
register_logevent("logevent_RoundEnd"2"1=Round_End""1=Round_Draw");
    
    
g_Pcvar[CVAR_COUNT] = register_cvar("kd_knifecount""3");
    
g_Pcvar[CVAR_TIMER] = register_cvar("kd_preparetime""10");
    
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")

}

public 
plugin_precache()
    
g_iFwdSpawn register_forward(FM_Spawn"fwd_Spawn"1);

public 
client_disconnected(id)
{
    if((
id == g_iChallenged) || (id == g_iChallenger))
    {
        
g_bInChallenge false;
        
g_bProtect false;
    }
}

public 
fwd_Spawn(ent)
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED;
    
    static 
szClassname[32];
    
pev(entpev_classnameszClassnamesizeof szClassname 1);
    
    if(
equal(szClassnameg_szSpawnClassname))
    {
        if(
vec_null(g_vKnifeOrigin[0]))
        {
            
pev(entpev_origing_vKnifeOrigin[0]);
        }
        else if(!
vec_null(g_vKnifeOrigin[0]) && vec_null(g_vKnifeOrigin[1]))
        {
            static 
Float:vTmp[3];
            
pev(entpev_originvTmp);
            
            if((
300.0 <= vector_distance(g_vKnifeOrigin[0], vTmp) < 600.0))
                
g_vKnifeOrigin[1] = vTmp;
        }
    }
    return 
FMRES_IGNORED;
}

public 
fwd_EmitSound(idchannel, const sound[])
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED;
    
    if(!
equal(soundg_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])) && check_players() && !g_bInChallenge)
    {
        new 
iOpponent get_opponent(get_user_team(id));
        if(!
iOpponent)
            return 
FMRES_IGNORED;
        
        
fnChallenge(idiOpponent);
        
        
iHitCount[id] = 0;
    }
    return 
FMRES_IGNORED;
}

public 
fwd_PlayerPreThink_post(id)
{
    if(!
is_user_alive(id) || !g_bInChallenge)
        return 
FMRES_IGNORED;
    
    static 
iWpn;
    
iWpn get_pdata_cbase(idCBASE_CURRWPN_ENT);
    
    if(
pev_valid(iWpn))
    {
        if(
get_pdata_int(iWpnOFFSET_ENT_TO_INDEX) != CSW_KNIFE)
            
engclient_cmd(id"weapon_knife");
    }
    
    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(idiOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE])) && g_bProtect)
    {
        static 
Float:vVel[3];
        
fm_get_speed_vector2(idiOpponent100.0vVel);
        
        
set_pev(idpev_velocityvVel);
    }
    return 
FMRES_IGNORED;
}

public 
fwd_Killed(ididattackershouldgib)
{
    if(!
get_pcvar_num(g_Pcvar[CVAR_ANNOUNCE]))
        return 
HAM_IGNORED;
    
    if(
check_players())
    {
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
client_print_color(iprint_team_default"%s ^3You can challenge your enemy to a knife duel hitting the wall 3 times!"PREFIX_CHAT)
        }
    }
    return 
HAM_IGNORED;
}

public 
fnChallenge(idopponent)
{
    new 
szName[32], szOppName[32];
    
get_user_name(idszNamesizeof szName 1);
    
get_user_name(opponentszOppNamesizeof szOppName 1);
    
    new 
szTitle[64];
    
formatex(szTitlesizeof szTitle 1"\r%s \yis challenging you to a knife duel"szName);
    
    new 
iMenu menu_create(szTitle"menu_MainHandler");
    
menu_additem(iMenu"Accept""1"0, -1);
    
menu_additem(iMenu"No, thanks""2"0, -1);
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_NEVER);
    
menu_display(opponentiMenu0);

    
client_print_color(0print_team_default"%s ^4%s ^3challenged ^4%s ^3to a knife duel."PREFIX_CHATszNameszOppName)
    
    
g_iChallenger id;
    
g_iChallenged opponent;
    
g_bInChallenge true;
}

public 
menu_MainHandler(idmenuitem)
{
    if(!
is_user_connected(id))
        return 
1;
    
    new 
szData[6], iAccessiCallBack;
    
menu_item_getinfo(menuitemiAccessszDatasizeof szData 1__iCallBack);
    
    new 
iKey str_to_num(szData);
    
    new 
szName[32];
    
get_user_name(idszNamesizeof szName 1);
    
    switch(
iKey)
    {
        case 
1:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3accepted the knife duel."PREFIX_CHATszName)
            
fnStartDuel();
        }
        case 
2:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3refused the knife duel."PREFIX_CHATszName)
            
g_bInChallenge false;
        }
    }
    return 
1;
}

public 
fnStartDuel()
{
    if(!
is_user_connected(g_iChallenged) || !is_user_connected(g_iChallenger))
        return;
    
    
engfunc(EngFunc_SetOriging_iChallengedg_vKnifeOrigin[0]);
    
engfunc(EngFunc_SetOriging_iChallengerg_vKnifeOrigin[1]);
    
    
fm_entity_set_aim(g_iChallengedg_iChallenger0);
    
fm_entity_set_aim(g_iChallengerg_iChallenged0);
    
    
fm_set_user_godmode(g_iChallenged1);
    
fm_set_user_godmode(g_iChallenger1);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_RESET]))
    {
        
set_pev(g_iChallengedpev_health100.0);
        
set_pev(g_iChallengerpev_health100.0);
    }
    
set_task(1.0"taskDuelThink"'x'""0"b"0);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
        
g_bProtect true;
}

public 
taskDuelThink()
{
    if(
g_iTimer 0)
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.91);
        
show_hudmessage(0"Countdown: %d"g_iTimer--);
    }
    else
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.51);
        
show_hudmessage(0"The duel started!");
        
        
g_iTimer get_pcvar_num(g_Pcvar[CVAR_TIMER]);
        
remove_task('x');
        
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
fm_set_user_godmode(i0);
        }
    }
}

public 
logevent_RoundEnd()
{
    
g_bInChallenge false;
    
g_bProtect false;

    for(new 
i=1i<MaxClientsi++)
    {
        if(
is_user_connected(i))
        {
            
menu_cancel(i)
        }
    }
}

stock fm_entity_set_aim(identbone 0)
{
    if(!
is_user_connected(id) || !pev_valid(ent))
        return 
0;
    
    new 
Float:vOrigin[3];
    
pev(entpev_originvOrigin);
    
    new 
Float:vEntOrigin[3], Float:vAngles[3];
    
    if(
bone)
        
engfunc(EngFunc_GetBonePositionidbonevEntOriginvAngles);
    else
        
pev(idpev_originvEntOrigin);
    
    
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(vAimVectorvNewAngles);
    
    
vNewAngles[0] *= -1;
    
    if(
vNewAngles[1] > 180.0vNewAngles[1] -= 360;
    if(
vNewAngles[1] < -180.0vNewAngles[1] += 360;
    if(
vNewAngles[1] == 180.0 || vNewAngles[1] == -180.0vNewAngles[1] = -179.9;
    
    
set_pev(idpev_anglesvNewAngles);
    
set_pev(idpev_fixangle1);
    
    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 
<= MaxClients 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 
<= MaxClients i++)
    {
        if(!
is_user_alive(i))
            continue;
        
        if(
get_user_team(i) == team)
            return 
i;
    }
    return 
0;
}

stock fm_set_user_godmode(indexgodmode 0)
{
    
set_pev(indexpev_takedamagegodmode == DAMAGE_NO DAMAGE_AIM);
    return 
1;
}

stock fm_get_speed_vector2(ent1ent2Float:speedFloat:new_velocity[3])
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    
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(ent1ent2)
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0.0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    return 
vector_distance(vOrigin1vOrigin2);

v120kaaimcfg is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-08-2024 , 00:25   Re: Help with this knife duel plugin
Reply With Quote #5

Quote:
Originally Posted by v120kaaimcfg View Post
Here
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "CS Revo: Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka | Wilian M."

#define CBASE_CURRWPN_ENT 373
#define OFFSET_ENT_TO_INDEX 43

#define PREFIX_CHAT "^4[ ^1CS Revo! ^4]"

new const g_szKnifeSound[] = "weapons/knife_hitwall1.wav";
new const 
g_szSpawnClassname[] = "info_player_deathmatch";

new 
Float:g_fHit[33];
new 
iHitCount[33];
new 
g_iChallengedg_iChallenger;

new 
Float:g_vKnifeOrigin[2][3];
new 
bool:g_bInChallenge;
new 
bool:g_bProtect;
new 
g_iTimer;

enum _:max_cvars {
    
    
CVAR_COUNT 0,
    
CVAR_TIMER,
    
CVAR_MAXDISTANCE,
    
CVAR_PROTECTION,
    
CVAR_ANNOUNCE,
    
CVAR_RESET
};

new 
g_Pcvar[max_cvars];

new 
g_iFwdSpawn;

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_forward(FM_EmitSound"fwd_EmitSound"1);
    
register_forward(FM_PlayerPreThink"fwd_PlayerPreThink_post"1);
    
RegisterHam(Ham_Killed"player""fwd_Killed"1);
    
unregister_forward(FM_Spawng_iFwdSpawn1);
    
    
register_logevent("logevent_RoundEnd"2"1=Round_End""1=Round_Draw");
    
    
g_Pcvar[CVAR_COUNT] = register_cvar("kd_knifecount""3");
    
g_Pcvar[CVAR_TIMER] = register_cvar("kd_preparetime""10");
    
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")

}

public 
plugin_precache()
    
g_iFwdSpawn register_forward(FM_Spawn"fwd_Spawn"1);

public 
client_disconnected(id)
{
    if((
id == g_iChallenged) || (id == g_iChallenger))
    {
        
g_bInChallenge false;
        
g_bProtect false;
    }
}

public 
fwd_Spawn(ent)
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED;
    
    static 
szClassname[32];
    
pev(entpev_classnameszClassnamesizeof szClassname 1);
    
    if(
equal(szClassnameg_szSpawnClassname))
    {
        if(
vec_null(g_vKnifeOrigin[0]))
        {
            
pev(entpev_origing_vKnifeOrigin[0]);
        }
        else if(!
vec_null(g_vKnifeOrigin[0]) && vec_null(g_vKnifeOrigin[1]))
        {
            static 
Float:vTmp[3];
            
pev(entpev_originvTmp);
            
            if((
300.0 <= vector_distance(g_vKnifeOrigin[0], vTmp) < 600.0))
                
g_vKnifeOrigin[1] = vTmp;
        }
    }
    return 
FMRES_IGNORED;
}

public 
fwd_EmitSound(idchannel, const sound[])
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED;
    
    if(!
equal(soundg_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])) && check_players() && !g_bInChallenge)
    {
        new 
iOpponent get_opponent(get_user_team(id));
        if(!
iOpponent)
            return 
FMRES_IGNORED;
        
        
fnChallenge(idiOpponent);
        
        
iHitCount[id] = 0;
    }
    return 
FMRES_IGNORED;
}

public 
fwd_PlayerPreThink_post(id)
{
    if(!
is_user_alive(id) || !g_bInChallenge)
        return 
FMRES_IGNORED;
    
    static 
iWpn;
    
iWpn get_pdata_cbase(idCBASE_CURRWPN_ENT);
    
    if(
pev_valid(iWpn))
    {
        if(
get_pdata_int(iWpnOFFSET_ENT_TO_INDEX) != CSW_KNIFE)
            
engclient_cmd(id"weapon_knife");
    }
    
    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(idiOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE])) && g_bProtect)
    {
        static 
Float:vVel[3];
        
fm_get_speed_vector2(idiOpponent100.0vVel);
        
        
set_pev(idpev_velocityvVel);
    }
    return 
FMRES_IGNORED;
}

public 
fwd_Killed(ididattackershouldgib)
{
    if(!
get_pcvar_num(g_Pcvar[CVAR_ANNOUNCE]))
        return 
HAM_IGNORED;
    
    if(
check_players())
    {
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
client_print_color(iprint_team_default"%s ^3You can challenge your enemy to a knife duel hitting the wall 3 times!"PREFIX_CHAT)
        }
    }
    return 
HAM_IGNORED;
}

public 
fnChallenge(idopponent)
{
    new 
szName[32], szOppName[32];
    
get_user_name(idszNamesizeof szName 1);
    
get_user_name(opponentszOppNamesizeof szOppName 1);
    
    new 
szTitle[64];
    
formatex(szTitlesizeof szTitle 1"\r%s \yis challenging you to a knife duel"szName);
    
    new 
iMenu menu_create(szTitle"menu_MainHandler");
    
menu_additem(iMenu"Accept""1"0, -1);
    
menu_additem(iMenu"No, thanks""2"0, -1);
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_NEVER);
    
menu_display(opponentiMenu0);

    
client_print_color(0print_team_default"%s ^4%s ^3challenged ^4%s ^3to a knife duel."PREFIX_CHATszNameszOppName)
    
    
g_iChallenger id;
    
g_iChallenged opponent;
    
g_bInChallenge true;
}

public 
menu_MainHandler(idmenuitem)
{
    if(!
is_user_connected(id))
        return 
1;
    
    new 
szData[6], iAccessiCallBack;
    
menu_item_getinfo(menuitemiAccessszDatasizeof szData 1__iCallBack);
    
    new 
iKey str_to_num(szData);
    
    new 
szName[32];
    
get_user_name(idszNamesizeof szName 1);
    
    switch(
iKey)
    {
        case 
1:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3accepted the knife duel."PREFIX_CHATszName)
            
fnStartDuel();
        }
        case 
2:
        {
            
client_print_color(0print_team_default"%s ^4%s ^3refused the knife duel."PREFIX_CHATszName)
            
g_bInChallenge false;
        }
    }
    return 
1;
}

public 
fnStartDuel()
{
    if(!
is_user_connected(g_iChallenged) || !is_user_connected(g_iChallenger))
        return;
    
    
engfunc(EngFunc_SetOriging_iChallengedg_vKnifeOrigin[0]);
    
engfunc(EngFunc_SetOriging_iChallengerg_vKnifeOrigin[1]);
    
    
fm_entity_set_aim(g_iChallengedg_iChallenger0);
    
fm_entity_set_aim(g_iChallengerg_iChallenged0);
    
    
fm_set_user_godmode(g_iChallenged1);
    
fm_set_user_godmode(g_iChallenger1);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_RESET]))
    {
        
set_pev(g_iChallengedpev_health100.0);
        
set_pev(g_iChallengerpev_health100.0);
    }
    
set_task(1.0"taskDuelThink"'x'""0"b"0);
    
    if(
get_pcvar_num(g_Pcvar[CVAR_PROTECTION]))
        
g_bProtect true;
}

public 
taskDuelThink()
{
    if(
g_iTimer 0)
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.91);
        
show_hudmessage(0"Countdown: %d"g_iTimer--);
    }
    else
    {
        
set_hudmessage(2551000, -1.00.306.01.00.10.51);
        
show_hudmessage(0"The duel started!");
        
        
g_iTimer get_pcvar_num(g_Pcvar[CVAR_TIMER]);
        
remove_task('x');
        
        for(new 
<= MaxClients i++)
        {
            if(!
is_user_alive(i))
                continue;
            
            
fm_set_user_godmode(i0);
        }
    }
}

public 
logevent_RoundEnd()
{
    
g_bInChallenge false;
    
g_bProtect false;

    for(new 
i=1i<MaxClientsi++)
    {
        if(
is_user_connected(i))
        {
            
menu_cancel(i)
        }
    }
}

stock fm_entity_set_aim(identbone 0)
{
    if(!
is_user_connected(id) || !pev_valid(ent))
        return 
0;
    
    new 
Float:vOrigin[3];
    
pev(entpev_originvOrigin);
    
    new 
Float:vEntOrigin[3], Float:vAngles[3];
    
    if(
bone)
        
engfunc(EngFunc_GetBonePositionidbonevEntOriginvAngles);
    else
        
pev(idpev_originvEntOrigin);
    
    
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(vAimVectorvNewAngles);
    
    
vNewAngles[0] *= -1;
    
    if(
vNewAngles[1] > 180.0vNewAngles[1] -= 360;
    if(
vNewAngles[1] < -180.0vNewAngles[1] += 360;
    if(
vNewAngles[1] == 180.0 || vNewAngles[1] == -180.0vNewAngles[1] = -179.9;
    
    
set_pev(idpev_anglesvNewAngles);
    
set_pev(idpev_fixangle1);
    
    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 
<= MaxClients 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 
<= MaxClients i++)
    {
        if(!
is_user_alive(i))
            continue;
        
        if(
get_user_team(i) == team)
            return 
i;
    }
    return 
0;
}

stock fm_set_user_godmode(indexgodmode 0)
{
    
set_pev(indexpev_takedamagegodmode == DAMAGE_NO DAMAGE_AIM);
    return 
1;
}

stock fm_get_speed_vector2(ent1ent2Float:speedFloat:new_velocity[3])
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    
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(ent1ent2)
{
    if(!
pev_valid(ent1) || !pev_valid(ent2))
        return 
0.0;
    
    static 
Float:vOrigin1[3];
    
pev(ent1pev_originvOrigin1);
    static 
Float:vOrigin2[3];
    
pev(ent2pev_originvOrigin2);
    
    return 
vector_distance(vOrigin1vOrigin2);

Thank you so much!
JuanitoAlimana is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode