Skocz do zawartości

Nowy szablon forum

mygo.pl

Stworzyliśmy dla Was nowy wygląd forum. Z pewnością znajdziesz rzeczy, które wg Ciebie mogą zostać zmienione - wspomnij o tym w specjalnym wątku.

Czytaj więcej

Jak założyć własną sieć

serwerów CS

Zastanawiasz się nad prowadzeniem własnej sieci serwerów? Przeczytaj podstawowe informacje, na które należy zwrócić uwagę, przy takim projekcie.

Czytaj więcej

Tworzymy spis sieci

dodaj swoją

Dodaj sieć do której należysz, pozwoli to na promocję i budowę ogólnopolskiej bazy sieci CS.

Czytaj więcej

RSSHelp with this knife duel plugin


MYGO.pl
 Udostępnij

Rekomendowane odpowiedzi

  • RSSy
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);


Przeczytaj cały wpis

Odnośnik do komentarza
Udostępnij na innych stronach

Gość
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
 Udostępnij

  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...