PDA

View Full Version : Automatic Knife Duel - Preveden



psy-gan
05-01-2011, 03:21
U pitanju je "automatic knife duel" plugin, ja sam ga preveo na srpski da bi mogli da imaju srpsku verziju i oni koji se ne "razumeju" i menjanje kodova, ime autora je staro posto nista drugo nije modifikovano u kodu osim print poruka. Ako sam slucajno napravio neku gresku mozete mi skrenuti paznju da to prepravim.

Zivelii :)



#define PLUGINNAME "Automatic knife duel - Srpski"
#define VERSION "0.4"
#define AUTHOR "JGHG"
/*
Copyleft 2005
Plugin topic: http://www.amxmodx.org/forums/viewtopic.php?p=91239


AUTOMATIC KNIFE DUEL
====================
Where I come from, if you cut the wall repeteadly with your knife it means you're challenging your last opponent to a knife duel. ;-)

I decided to automate this process.

If only you and another person on the opposite team remain in the round, you can hit a wall (or another object) with your knife, THREE TIMES in fast succession.
By this action you challenge your opponent to a knife duel. The person you challenge gets a menu where he can accept/decline your
challenge. The challenged person has 10 seconds to decide his mind, else the challenge is automatically declined, and the menu should be closed automatically.

Should a knife duel start, it works out pretty much like a round of Knife Arena: you can only use the knife (and the C4!).
As soon as the round ends the Knife Arena mode is turned off.

/JGHG


VERSIONS
========
050421 0.3 You must now slash with your knife three times in fast succession to challenge someone.
050208 0.2 Fixed seconds display.
Bots should now respond correctly and a little human like. They will mostly accept challenges. ;-)
Small fixes here and there. :-)
050208 0.1 First version - largely untested
*/

#include <amxmodx>
#include <fakemeta>
#include <fun>

#define DEBUG

#if defined DEBUG
#include <amxmisc>
#endif // defined DEBUG

#define MENUSELECT1 0
#define MENUSELECT2 1
#define TASKID_CHALLENGING 2348923
#define TASKID_BOTTHINK 3242321
#define DECIDESECONDS 10
#define ALLOWED_WEAPONS 2
#define KNIFESLASHES 3 // the nr of slashes within a short amount of time until a challenge starts...
// Globals below
new g_allowedWeapons[ALLOWED_WEAPONS] = {CSW_KNIFE, CSW_C4}
new g_MAXPLAYERS
new bool:g_challenging = false
new bool:g_knifeArena = false
new bool:g_noChallengingForAWhile = false
new g_challengemenu
new g_challenger
new g_challenged
new g_challenges[33]
// Globals above

public plugin_modules()
{
require_module("fakemeta")
require_module("fun")
}

public forward_emitsound(const PIRATE, const Onceuponatimetherewasaverysmall, noise[], const Float:turtlewhoateabiggerturtleand, const Float:afterthatthesmallturtlegot, const veryveryverybig, const theend) {
if (g_noChallengingForAWhile || g_knifeArena || g_challenging || PIRATE < 1 || PIRATE > g_MAXPLAYERS || !is_user_alive(PIRATE) || !equal(noise, "weapons/knife_hitwall1.wav"))
return FMRES_IGNORED

new team = get_user_team(PIRATE), otherteam = 0, matchingOpponent = 0
// Make sure exactly one person on each team is alive.
for (new i = 1; i <= g_MAXPLAYERS; i++) {
if (!is_user_connected(i) || !is_user_alive(i) || PIRATE == i)
continue
if (get_user_team(i) == team) {
// No fun.
return FMRES_IGNORED
}
else {
if (++otherteam > 1) {
// No fun.
return FMRES_IGNORED
}
matchingOpponent = i
}
}

if (matchingOpponent == 0)
return FMRES_IGNORED

if (++g_challenges[PIRATE] >= KNIFESLASHES) {
Challenge(PIRATE, matchingOpponent)
if (is_user_bot(matchingOpponent)) {
new Float:val = float(DECIDESECONDS)
if (val < 2.0)
val = 2.0
remove_task(TASKID_BOTTHINK)
set_task(random_float(1.0, float(DECIDESECONDS) - 1.0), "BotDecides", TASKID_BOTTHINK)
}
g_challenges[PIRATE] = 0
}
else
set_task(1.0, "decreaseChallenges", PIRATE)

//client_print(PIRATE, print_chat, "Your challenges: %d", g_challenges[PIRATE])

return FMRES_IGNORED
}

public decreaseChallenges(id) {
if (--g_challenges[id] < 0)
g_challenges[id] = 0
}

public BotDecides() {
if (!g_challenging)
return

if (random_num(0,9) > 0)
Accept()
else {
DeclineMsg()
}
g_challenging = false
remove_task(TASKID_CHALLENGING)
}

Challenge(challenger, challenged) {
g_challenger = challenger
g_challenged = challenged
g_challenging = true
new challenger_name[32], challenged_name[32]
get_user_name(challenger, challenger_name, 31)
get_user_name(challenged, challenged_name, 31)

client_print(challenger, print_chat, "Izazivas %s Na noz duel Pre nego sto odgovori procice %d sekundi...", challenged_name, DECIDESECONDS)

new menu[1024], keys = MENU_KEY_1 | MENU_KEY_2
format(menu, 1023, "Izazvan si od strane %s Na noz duel^n^nSta ce to biti? Imas %d sekunda da odgovoris!^n^n\y1\w. Sta cekamo?!^n\y2\w. Ne ja sam sisa, ne smem!", challenger_name, DECIDESECONDS)
show_menu(challenged, keys, menu, DECIDESECONDS, "JGHG's automatic knife duel")
set_task(float(DECIDESECONDS), "timed_toolate", TASKID_CHALLENGING)
}

public timed_toolate() {
if (g_challenging) {
new challenger_name[32], challenged_name[32]
get_user_name(g_challenger, challenger_name, 31)
get_user_name(g_challenged, challenged_name, 31)
client_print(0, print_chat, "%s nije odgovorio %s's noz duel mora biti brzi...", challenged_name, challenger_name)
CancelAll()
}
}

public client_putinserver(id) {
set_task(25.0, "Announcement", id)

return PLUGIN_CONTINUE
}

public Announcement(id) {
client_print(id, print_chat, "Kada ste samo ti i jedan neprijatelj ostali zivi mozes ga izazvati na noz duel, udaranjem 3 puta nozem o zid.")
}

public challenged_menu(id, key) {
switch (key) {
case MENUSELECT1: {
// Prihvatam
Accept()
}
case MENUSELECT2: {
// Odbijam
DeclineMsg()
}
}
g_challenging = false
remove_task(TASKID_CHALLENGING)

return PLUGIN_HANDLED
}

DeclineMsg() {
new challenger_name[32], challenged_name[32]
get_user_name(g_challenger, challenger_name, 31)
get_user_name(g_challenged, challenged_name, 31)
client_print(0, print_chat, "%s je odbio %s's noz duel...", challenged_name, challenger_name)
}

Accept() {
new challenger_name[32], challenged_name[32]
get_user_name(g_challenger, challenger_name, 31)
get_user_name(g_challenged, challenged_name, 31)

client_print(0, print_chat, "%s prihvata %s's noz duel!", challenged_name, challenger_name)
g_knifeArena = true
give_item(g_challenger, "weapon_knife")
give_item(g_challenged, "weapon_knife")
engclient_cmd(g_challenger, "weapon_knife")
engclient_cmd(g_challenged, "weapon_knife")
}

public event_holdwpn(id) {
if (!g_knifeArena || !is_user_alive(id))
return PLUGIN_CONTINUE

new weaponType = read_data(2)

for (new i = 0; i < ALLOWED_WEAPONS; i++) {
if (weaponType == g_allowedWeapons[i])
return PLUGIN_CONTINUE
}

engclient_cmd(id, "weapon_knife")

return PLUGIN_CONTINUE
}

public event_roundend() {
if (g_challenging || g_knifeArena)
CancelAll()
g_noChallengingForAWhile = true
set_task(4.0, "NoChallengingForAWhileToFalse")

return PLUGIN_CONTINUE
}

public NoChallengingForAWhileToFalse() {
g_noChallengingForAWhile = false
}

CancelAll() {
if (g_challenging) {
g_challenging = false
// Close menu of challenged
if (is_user_connected(g_challenged)) {
new usermenu, userkeys
get_user_menu(g_challenged, usermenu, userkeys) // get user menu

// Hmm this ain't working :-/
if (usermenu == g_challengemenu) // Close it!
show_menu(g_challenged, 0, "blabla") // show empty menu
}
}
if (g_knifeArena) {
g_knifeArena = false
}
remove_task(TASKID_BOTTHINK)
remove_task(TASKID_CHALLENGING)
}

public event_death() {
if (g_challenging || g_knifeArena)
CancelAll()

return PLUGIN_CONTINUE
}

#if defined DEBUG
public challengefn(id, level, cid) {
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED

new challenger[64], challenged[64]
read_argv(1, challenger, 63)
read_argv(2, challenged, 63)

console_print(id, "challenger: %s, challenged: %s", challenger, challenged)

new r = str_to_num(challenger)
new d = str_to_num(challenged)
Challenge(r, d)
if (is_user_bot(d))
Accept()

return PLUGIN_HANDLED
}
#endif // defined DEBUG

public plugin_init() {
register_plugin(PLUGINNAME, VERSION, AUTHOR)
register_event("CurWeapon", "event_holdwpn", "be", "1=1")
register_forward(FM_EmitSound, "forward_emitsound")
g_MAXPLAYERS = get_maxplayers()

g_challengemenu = register_menuid("JGHG's automatic knife duel"/*"You are challenged"*/)
register_menucmd(g_challengemenu, MENU_KEY_1 | MENU_KEY_2, "challenged_menu")

register_event("DeathMsg", "event_death", "a")
register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_terwin")
register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_ctwin")
register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_rounddraw")

#if defined DEBUG
register_clcmd("0challenge", "challengefn", ADMIN_CFG, "<challenger> <challenged> - start knife duel challenge")
#endif // defined DEBUG

new Float:maptime = get_cvar_float("mp_timelimit")
if (maptime == 0.0)
maptime = 15.0

new Float:anntime = 60.0 * 5.0 // 5 minutes
if (maptime < 5.0)
anntime = maptime / 3.0

set_task(anntime, "Announcement", 0, "", 0, "b")
}

'RaZoR'
05-01-2011, 03:34
hehe svaka cast :)

Pazi Petarda
05-01-2011, 11:38
jel to sad na srpskom ili na engleskom ili treba ja to da prevedem na srpski?

Pazi Petarda
05-01-2011, 11:41
meni radi neki knife duel na engleskom ali nemam ga u cstrike/addons/amxmodx/config
i gde onda ovo da kucam ? sto si mi ti dao :)

Skin
05-01-2011, 11:54
Source file: http://balkanhost.info/cs/plugins/automatic_knife_duel.sma
AMXX file: http://balkanhost.info/cs/plugins/automatic_knife_duel.amxx

Skinete AMXX file i zamjenite ga s već postojećim u vašem plugins direktoriju na vašem serveru.

JoX !
05-01-2011, 12:48
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka"

#define CBASE_CURRWPN_ENT 373
#define OFFSET_ENT_TO_INDEX 43

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_iChallenged, g_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;
new g_iMaxPlayers;

public plugin_init() {

register_plugin(PLUGIN, VERSION, AUTHOR);

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_Spawn, g_iFwdSpawn, 1);

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", "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", "0");

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_bInChallenge = false;
g_bProtect = 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))
return FMRES_IGNORED;

if(!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])) && check_players() && !g_bInChallenge)
{
new iOpponent = get_opponent(3 - get_user_team(id));
if(!iOpponent)
return FMRES_IGNORED;

fnChallenge(id, iOpponent);

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(id, CBASE_CURRWPN_ENT);

if(pev_valid(iWpn))
{
if(get_pdata_int(iWpn, OFFSET_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(id, iOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE])) && g_bProtect)
{
static Float:vVel[3];
fm_get_speed_vector2(id, iOpponent, 100.0, vVel);

set_pev(id, pev_velocity, vVel);
}
return FMRES_IGNORED;
}

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;

client_print(i, print_chat, " Mozes izazvati svog neprijatelja na Duel nozem tako sto ces ogrebati zid %d puta.", 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, "\r%s \yte izaziva na Duel", szName);

new iMenu = menu_create(szTitle, "menu_MainHandler", 0);
menu_additem(iMenu, "Prihvati", "1", 0, -1);
menu_additem(iMenu, "Odbij", "2", 0, -1);

menu_setprop(iMenu, MPROP_EXIT, MEXIT_NEVER);
menu_display(opponent, iMenu, 0);

client_print(0, print_chat, "* %s je izazvao %s na Duel nozem.", szName, szOppName);

g_iChallenger = id;
g_iChallenged = opponent;
g_bInChallenge = true;
}

public menu_MainHandler(id, menu, item)
{
if(!is_user_connected(id))
return 1;

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:
{
client_print(0, print_chat, "* %s je prihvatio Duel nozem!", szName);
fnStartDuel();
}
case 2:
{
client_print(0, print_chat, "* %s je odbijo Duel nozem!", szName);
g_bInChallenge = false;
}
}
return 1;
}

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, 100.0);
set_pev(g_iChallenger, pev_health, 100.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(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.9, 1);
show_hudmessage(0, "Duel pocinje za: %d", g_iTimer--);
}
else
{
set_hudmessage(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.5, 1);
show_hudmessage(0, "Duel je poceo");

g_iTimer = get_pcvar_num(g_Pcvar[CVAR_TIMER]);
remove_task('x');

for(new i = 0 ; i <= g_iMaxPlayers ; i++)
{
if(!is_user_alive(i))
continue;

fm_set_user_godmode(i, 0);
}
}
}

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

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);
}


Evo, ja imam ovaj moj preveden koji koristim...

Emporio
05-01-2011, 13:12
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Knife Duel"
#define VERSION "1.0"
#define AUTHOR "Alka"

#define CBASE_CURRWPN_ENT 373
#define OFFSET_ENT_TO_INDEX 43

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_iChallenged, g_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;
new g_iMaxPlayers;

public plugin_init() {

register_plugin(PLUGIN, VERSION, AUTHOR);

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_Spawn, g_iFwdSpawn, 1);

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", "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", "0");

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_bInChallenge = false;
g_bProtect = 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))
return FMRES_IGNORED;

if(!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])) && check_players() && !g_bInChallenge)
{
new iOpponent = get_opponent(3 - get_user_team(id));
if(!iOpponent)
return FMRES_IGNORED;

fnChallenge(id, iOpponent);

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(id, CBASE_CURRWPN_ENT);

if(pev_valid(iWpn))
{
if(get_pdata_int(iWpn, OFFSET_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(id, iOpponent) >= get_pcvar_float(g_Pcvar[CVAR_MAXDISTANCE])) && g_bProtect)
{
static Float:vVel[3];
fm_get_speed_vector2(id, iOpponent, 100.0, vVel);

set_pev(id, pev_velocity, vVel);
}
return FMRES_IGNORED;
}

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;

client_print(i, print_chat, " Mozes izazvati svog neprijatelja na Duel nozem tako sto ces ogrebati zid %d puta.", 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, "\r%s \yte izaziva na Duel", szName);

new iMenu = menu_create(szTitle, "menu_MainHandler", 0);
menu_additem(iMenu, "Prihvati", "1", 0, -1);
menu_additem(iMenu, "Odbij", "2", 0, -1);

menu_setprop(iMenu, MPROP_EXIT, MEXIT_NEVER);
menu_display(opponent, iMenu, 0);

client_print(0, print_chat, "* %s je izazvao %s na Duel nozem.", szName, szOppName);

g_iChallenger = id;
g_iChallenged = opponent;
g_bInChallenge = true;
}

public menu_MainHandler(id, menu, item)
{
if(!is_user_connected(id))
return 1;

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:
{
client_print(0, print_chat, "* %s je prihvatio Duel nozem!", szName);
fnStartDuel();
}
case 2:
{
client_print(0, print_chat, "* %s je odbijo Duel nozem!", szName);
g_bInChallenge = false;
}
}
return 1;
}

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, 100.0);
set_pev(g_iChallenger, pev_health, 100.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(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.9, 1);
show_hudmessage(0, "Duel pocinje za: %d", g_iTimer--);
}
else
{
set_hudmessage(255, 100, 0, -1.0, 0.3, 0, 6.0, 1.0, 0.1, 0.5, 1);
show_hudmessage(0, "Duel je poceo");

g_iTimer = get_pcvar_num(g_Pcvar[CVAR_TIMER]);
remove_task('x');

for(new i = 0 ; i <= g_iMaxPlayers ; i++)
{
if(!is_user_alive(i))
continue;

fm_set_user_godmode(i, 0);
}
}
}

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

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);
}


Evo, ja imam ovaj moj preveden koji koristim...

Ima jedna greska, mala, gramaticka. Nije odbiJo nego odbio. Nista licno, samo kazem zapazanje! :)

Lucky
05-01-2011, 13:17
http://www.kgb-hosting.com/forum/showthread.php?1006-Pitanje-oko-plugin&p=10348&viewfull=1#post10348 :D

Brane94
05-01-2011, 15:18
Ja sam svoj preveo pre 4-5 meseca :D Posto Lucky-jev nije radio :P

punisher1389
05-01-2011, 15:25
jbt sad cu i ja da prevedem svoj, pa ce biti 1000 verzija istog plugina :S

JoX !
05-01-2011, 16:00
Ima jedna greska, mala, gramaticka. Nije odbiJo nego odbio. Nista licno, samo kazem zapazanje! :)

Hvala, ispravicu, slucajno sam dodao pri brzom kucanju




jbt sad cu i ja da prevedem svoj, pa ce biti 1000 verzija istog plugina :S

Svako ce imati svoju verziju,a skoro svima isti prevod xD

TimeX
05-01-2011, 16:23
TY :) Sigurno cu isprobati ;)