Kod:
#include <amxmodx>
#include <reapi>
#pragma semicolon 1
#define EKLENTI_ADI "OzelMesaj"
#define EKLENTI_SURUM "1.1"
#define EKLENTI_YAPIMCI "osmanbnm"
#define ETIKET "^4[WebAilesi]^1"
#define SES_DOSYASI "buttons/blip1.wav"
#define MESAJ_MAX 101
#define MENU_YOK -1
new g_HedefIndeks[MAX_PLAYERS + 1];
new g_HedefUserid[MAX_PLAYERS + 1];
new g_SonGonderen[MAX_PLAYERS + 1];
new g_Menu[MAX_PLAYERS + 1];
new Float:g_flSecimBitis[MAX_PLAYERS + 1];
new Float:g_flSonMesaj[MAX_PLAYERS + 1];
new Float:g_flBekleme;
new Float:g_flSure;
new g_iSes;
new g_iKayit;
new bool:g_bRegame;
new g_iMaxOyuncu;
new const g_TakimEtiketi[][] = { "?", "T", "CT", "SPEC" };
public plugin_precache()
{
precache_sound(SES_DOSYASI);
}
public plugin_init()
{
register_plugin(EKLENTI_ADI, EKLENTI_SURUM, EKLENTI_YAPIMCI);
if (!is_rehlds())
{
set_fail_state("OzelMesaj icin ReHLDS ve ReAPI gerekli.");
return;
}
g_bRegame = bool:is_regamedll();
g_iMaxOyuncu = get_maxplayers();
for (new i = 0; i <= MAX_PLAYERS; i++)
g_Menu[i] = MENU_YOK;
register_cvar("ozelmesaj_surum", EKLENTI_SURUM, FCVAR_SERVER | FCVAR_SPONLY);
bind_pcvar_float(create_cvar("om_bekleme", "1.0", FCVAR_NONE, "Iki ozel mesaj arasi bekleme suresi (saniye)", true, 0.0), g_flBekleme);
bind_pcvar_float(create_cvar("om_sure", "45.0", FCVAR_NONE, "Menuden secilen hedefin gecerlilik suresi (saniye)", true, 5.0), g_flSure);
bind_pcvar_num(create_cvar("om_ses", "1", FCVAR_NONE, "Mesaj alan oyuncuya bildirim sesi cal (0/1)", true, 0.0, true, 1.0), g_iSes);
bind_pcvar_num(create_cvar("om_kayit", "0", FCVAR_NONE, "Ozel mesajlari sunucu loguna yaz (0/1)", true, 0.0, true, 1.0), g_iKayit);
register_clcmd("say", "@Sohbet");
register_clcmd("say_team", "@TakimSohbet");
register_clcmd("ozelmesaj", "@MenuKomut");
RegisterHookChain(RH_SV_DropClient, "@OyuncuAyrildi", true);
}
public client_connect(id)
{
g_Menu[id] = MENU_YOK;
}
public client_putinserver(id)
{
Sifirla(id);
}
@OyuncuAyrildi(const id, const bool:cokme, const sebep[])
{
Sifirla(id);
}
@MenuKomut(const id)
{
MenuAc(id);
return PLUGIN_HANDLED;
}
@Sohbet(const id)
{
return SohbetIsle(id, true);
}
@TakimSohbet(const id)
{
return SohbetIsle(id, false);
}
SohbetIsle(const id, const bool:yonlendir)
{
static metin[192];
read_args(metin, charsmax(metin));
remove_quotes(metin);
trim(metin);
if (!metin[0])
return PLUGIN_CONTINUE;
if (metin[0] == '/' || metin[0] == '!')
{
static komut[16], kalan[160];
argbreak(metin, komut, charsmax(komut), kalan, charsmax(kalan));
if (equali(komut[1], "om") || equali(komut[1], "ozelmesaj") || equali(komut[1], "pm") || equali(komut[1], "mesaj"))
{
if (kalan[0])
DogrudanGonder(id, kalan);
else
MenuAc(id);
return PLUGIN_HANDLED;
}
if (equali(komut[1], "cevap") || equali(komut[1], "r"))
{
Cevapla(id, kalan);
return PLUGIN_HANDLED;
}
if (equali(komut[1], "iptal"))
{
if (g_HedefUserid[id])
{
HedefTemizle(id);
client_print_color(id, print_team_default, "%s Ozel mesaj hedefi iptal edildi.", ETIKET);
}
else
client_print_color(id, print_team_default, "%s Iptal edilecek bir hedef secimi yok.", ETIKET);
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
if (!yonlendir || !g_HedefUserid[id])
return PLUGIN_CONTINUE;
if (get_gametime() > g_flSecimBitis[id])
{
HedefTemizle(id);
client_print_color(id, print_team_default, "%s Hedef secimi zaman asimina ugradi, mesajiniz gonderilmedi. Tekrar ^4/om^1 yazin.", ETIKET);
return PLUGIN_HANDLED;
}
if (MesajGonder(id, g_HedefIndeks[id], g_HedefUserid[id], metin))
HedefTemizle(id);
return PLUGIN_HANDLED;
}
MenuAc(const id)
{
MenuKapat(id);
new menu = menu_create("\y[WebAilesi] \wOzel Mesaj^n\dKime mesaj gondermek istiyorsunuz?", "@MenuIslem");
new sayi, takim, isim[32], satir[48], bilgi[8];
for (new i = 1; i <= g_iMaxOyuncu; i++)
{
if (i == id || !is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
continue;
takim = g_bRegame ? get_member(i, m_iTeam) : get_user_team(i);
if (takim < 0 || takim > 3)
takim = 0;
get_user_name(i, isim, charsmax(isim));
formatex(satir, charsmax(satir), "\r[%s] \w%s", g_TakimEtiketi[takim], isim);
num_to_str(get_user_userid(i), bilgi, charsmax(bilgi));
menu_additem(menu, satir, bilgi);
sayi++;
}
if (!sayi)
{
menu_destroy(menu);
client_print_color(id, print_team_default, "%s Sunucuda mesaj gonderebileceginiz baska oyuncu yok.", ETIKET);
return;
}
menu_setprop(menu, MPROP_EXITNAME, "Cikis");
menu_setprop(menu, MPROP_BACKNAME, "Geri");
menu_setprop(menu, MPROP_NEXTNAME, "Ileri");
g_Menu[id] = menu;
menu_display(id, menu, 0);
}
@MenuIslem(const id, const menu, const item)
{
if (g_Menu[id] == menu)
g_Menu[id] = MENU_YOK;
if (item < 0)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new bilgi[8], erisim, geri;
menu_item_getinfo(menu, item, erisim, bilgi, charsmax(bilgi), _, _, geri);
menu_destroy(menu);
new hedef = find_player("k", str_to_num(bilgi));
if (!hedef || hedef == id)
{
client_print_color(id, print_team_default, "%s Secilen oyuncu artik sunucuda degil.", ETIKET);
return PLUGIN_HANDLED;
}
HedefSec(id, hedef);
return PLUGIN_HANDLED;
}
DogrudanGonder(const id, const metin[])
{
static isim[32], mesaj[160];
argbreak(metin, isim, charsmax(isim), mesaj, charsmax(mesaj));
new hedef = find_player("blh", isim);
if (!hedef || is_user_bot(hedef))
{
client_print_color(id, print_team_default, "%s ^3%s^1 adli oyuncu bulunamadi. Menu icin sadece ^4/om^1 yazin.", ETIKET, isim);
return;
}
if (hedef == id)
{
client_print_color(id, print_team_default, "%s Kendinize ozel mesaj gonderemezsiniz.", ETIKET);
return;
}
if (mesaj[0])
MesajGonder(id, hedef, get_user_userid(hedef), mesaj);
else
HedefSec(id, hedef);
}
Cevapla(const id, const mesaj[])
{
new userid = g_SonGonderen[id];
if (!userid)
{
client_print_color(id, print_team_default, "%s Cevaplayabileceginiz bir mesaj yok.", ETIKET);
return;
}
new hedef = find_player("k", userid);
if (!hedef)
{
g_SonGonderen[id] = 0;
client_print_color(id, print_team_default, "%s Size son mesaj gonderen oyuncu artik sunucuda degil.", ETIKET);
return;
}
if (mesaj[0])
MesajGonder(id, hedef, userid, mesaj);
else
HedefSec(id, hedef);
}
HedefSec(const id, const hedef)
{
g_HedefIndeks[id] = hedef;
g_HedefUserid[id] = get_user_userid(hedef);
g_flSecimBitis[id] = get_gametime() + g_flSure;
new isim[32];
get_user_name(hedef, isim, charsmax(isim));
client_print_color(id, hedef, "%s Hedef: ^3%s^1. Simdi sohbete yazacaginiz mesaj sadece ona gidecek. Iptal icin ^4/iptal^1 yazin.", ETIKET, isim);
client_print(id, print_center, "Ozel mesaj hedefi: %s", isim);
}
bool:MesajGonder(const gonderen, const alici, const userid, const mesaj[])
{
if (!is_user_connected(alici) || get_user_userid(alici) != userid)
{
client_print_color(gonderen, print_team_default, "%s Hedef oyuncu artik sunucuda degil.", ETIKET);
return true;
}
new Float:simdi = get_gametime();
if (simdi - g_flSonMesaj[gonderen] < g_flBekleme)
{
client_print_color(gonderen, print_team_default, "%s Cok hizli mesaj gonderiyorsunuz, biraz bekleyin.", ETIKET);
return false;
}
g_flSonMesaj[gonderen] = simdi;
static kisa[MESAJ_MAX];
copy(kisa, charsmax(kisa), mesaj);
new gonderenIsim[32], aliciIsim[32];
get_user_name(gonderen, gonderenIsim, charsmax(gonderenIsim));
get_user_name(alici, aliciIsim, charsmax(aliciIsim));
client_print_color(alici, gonderen, "%s ^3%s^1 -> ^3Siz^1: %s", ETIKET, gonderenIsim, kisa);
client_print_color(gonderen, alici, "%s ^3Siz^1 -> ^3%s^1: %s", ETIKET, aliciIsim, kisa);
g_SonGonderen[alici] = get_user_userid(gonderen);
client_print(alici, print_center, "%s size ozel mesaj gonderdi. Cevap: /r mesaj", gonderenIsim);
if (g_iSes)
rh_emit_sound2(alici, alici, CHAN_AUTO, SES_DOSYASI, 0.6, ATTN_NORM, 0, PITCH_NORM);
if (g_iKayit)
log_amx("[WebAilesi] %s -> %s: %s", gonderenIsim, aliciIsim, kisa);
return true;
}
MenuKapat(const id)
{
if (g_Menu[id] != MENU_YOK)
{
menu_destroy(g_Menu[id]);
g_Menu[id] = MENU_YOK;
}
}
HedefTemizle(const id)
{
g_HedefIndeks[id] = 0;
g_HedefUserid[id] = 0;
g_flSecimBitis[id] = 0.0;
}
Sifirla(const id)
{
MenuKapat(id);
HedefTemizle(id);
g_SonGonderen[id] = 0;
g_flSonMesaj[id] = 0.0;
}