Why my ShopMenu won't work ? here is my code, what is incorrect and where is issue ?
PHP Code:
#include <amxmodx>
#include <csx>
#include <amxmisc>
#include <fakemeta_util>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <sqlx>
#include <fun>
#include <nvault>
#include <unixtime>
#define PLUGIN "User System"
#define VERSION "1.2"
#define AUTHOR "Min2liz"
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_PASS "notsaying"
#define SQL_DB "user"
#define SQL_TABLE "cs_users"
#define MAX_PLAYERS 32
// VoteKick ir VoteBan
#define MAX_VOTEIDS MAX_PLAYERS
#define WEIGHT_PLAYER 1
#define WEIGHT_ADMIN 2
new gmsgTextMsg
new round = 1
new g_iLastTouchedBox[33]
new Handle:g_SqlTuple
new g_Error[512]
new PlayerXP[32], PlayerCon[32], PlayerTime[32], PlayerDamage[32], PlayerUnixTimeDamage[32]
new PlayerSlot[32], PlayerSlotTime[32], PlayerAwp[32], PlayerAwpTime[32], PlayerPap[32], PlayerPapTime[32], PlayerKar[32], PlayerKarTime[32], PlayerAdmin[32], PlayerAdminTime[32]
new XP_Kill,XP_Knife,XP_Hs
new g_SayText
new g_hudmsg1
new ShopDamage, ShopAwp, ShopPap, ShopKar, ShopSlot
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /ps", "userPoints")
register_clcmd("say /shop", "ShopMenu")
register_event("DeathMsg", "eDeath", "a")
register_event("Damage", "on_damage", "b", "2!0", "3=0", "4!0");
remove_user_flags(0, read_flags("z"))
// Damage stuff
g_hudmsg1 = CreateHudSyncObj()
g_SqlTuple = SQL_MakeDbTuple(SQL_HOST,SQL_USER,SQL_PASS,SQL_DB)
// Plugin cvras
register_cvar("slot_reserv","1") // 1 = Short time | 2 - Too high Ping
// Kill cvars
XP_Kill = register_cvar("points_kill", "2")
XP_Hs = register_cvar("points_hs","5")
XP_Knife = register_cvar("points_knife","3")
// Shop Cvars
g_SayText = get_user_msgid("SayText");
RegisterHam(Ham_Spawn, "player", "Player_Spawn_Post", 1)
register_touch("weaponbox", "player", "WeaponBox_Touch")
register_menucmd(register_menuid("T_BuyRifle", 1), (1<<4), "BuyRifle")
register_menucmd(register_menuid("CT_BuyRifle", 1), (1<<5), "BuyRifle")
register_event("HLTV", "NewRound", "a", "1=0", "2=0");
gmsgTextMsg = get_user_msgid("TextMsg")
ShopDamage = register_cvar("shop_damage", "6000")
ShopAwp = register_cvar("shop_awp", "8000")
ShopPap = register_cvar("shop_pap", "5000")
ShopKar = register_cvar("shop_kar", "6000")
ShopSlot = register_cvar("shop_slot", "2000")
}
public ShopMenu(id) {
if (PlayerCon[id]) {
new title[64], m1[64], m2[64], m3[64], m4[64], m5[64]
formatex(title, 63, "Jusu taskai: \y(\r25000\y)", PlayerXP[id])
if(!PlayerDamage[id]){
formatex(m1, 63, "Zalos rodymas \y(\wKaina: \r%i\y)",get_pcvar_num(ShopDamage))
} else {
formatex(m1, 63, "\dZalos rodymas \r*")
} if(!PlayerAwp[id]){
formatex(m2, 63, "Awp naudojimas \y(\wKaina: \r%i\y)" ,get_pcvar_num(ShopAwp))
} else {
formatex(m2, 63, "\dAwp naudojimas \r*")
} if(!PlayerPap[id]){
formatex(m3, 63, "Papildomi bonusai \y(\wKaina: \r%i\y)", get_pcvar_num(ShopPap))
} else {
formatex(m3, 63, "\dPapildomi bonusai \r*")
} if(!PlayerKar[id]){
formatex(m4, 63, "Kario komplektas \y(\wKaina: \r%i\y)", get_pcvar_num(ShopKar))
} else {
formatex(m4, 63, "\dKario komplektas \r*")
} if(!PlayerSlot[id]){
formatex(m5, 63, "Slotas serveryje \y(\wKaina: \r%i\y)", get_pcvar_num(ShopSlot))
} else {
formatex(m5, 63, "\dSlotas serveryje \r*")
}
new menu = menu_create(title, "ShopMenuHandler")
menu_additem(menu, m1, "2", 0)
menu_additem(menu, m2, "3",0)
menu_additem(menu, m3, "4",0)
menu_additem(menu, m4, "5",0)
menu_additem(menu, m5, "6",0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
}else{
client_print(id, print_chat,"Tik registruoti vartotojai gali rinkti taskus")
client_print(id, print_chat,"Slapyvardzio registracija: www.inch.lt")
}
return PLUGIN_HANDLED
}
public ShopMenuHandler(id, menu, item) {
if( item == MENU_EXIT ) {
menu_destroy(menu)
return PLUGIN_HANDLED
}
new data[6], iName[64]
new access, callback
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
new key = str_to_num(data)
switch(key) {
case 1: {
ShopMenu(id);
}
case 2: {
if (!PlayerDamage[id]){
BuyDamage(id)
}else{
ShopMenu(id)
}
}
case 3: {
if (!PlayerAwp[id]){
BuyAwp(id)
}else{
ShopMenu(id)
}
}
case 4: {
if (!PlayerPap[id]){
BuyPap(id)
}else{
ShopMenu(id)
}
}
case 5: {
if (!PlayerKar[id]){
BuyKar(id)
}else{
ShopMenu(id)
}
}
case 6: {
if (!PlayerSlot[id]){
BuySlot(id)
}else{
ShopMenu(id)
}
}
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
public BuyDamage(id) {
new name[32], damageTime,DamageCost
get_user_name(id, name, 31)
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
DamageCost = get_pcvar_num(ShopDamage)
damageTime = get_systime() + 604800
if (PlayerXP[id] > DamageCost) {
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle) {
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `damage`='1', `damage_time`='%i' WHERE `user`='%s'",SQL_TABLE,damageTime,name)
if(!SQL_Execute(Query)) {
// if there were any problems
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
PlayerXP[id] = PlayerXP[id] - DamageCost
PlayerDamage[id] = 1
new iMonth, iDay, iYear, iHour, iMinute, iSecond
new iUnixTime = damageTime
UnixToTime( iUnixTime , iYear , iMonth , iDay , iHour , iMinute , iSecond )
client_cmd(id, "spk mp3/vipmenu.wav")
client_print(id,print_chat,"Jus sekmingai nusipirkot zalos rodyma savaitei.")
client_print(id,print_chat,"Galioja iki %02d-%02d-%02d",iYear , iMonth , iDay)
client_print(id,print_chat,"Jums liko %i taskai(-as)",PlayerXP[id])
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
else {
client_print(id,print_chat,"Jums neuztenka tasku. Zalos rodymas savaitei kainuoja %i, jus turite %i",DamageCost,PlayerXP[id])
}
}
public BuyAwp(id) {
new name[32], AwpTime,AwpCost
get_user_name(id, name, 31)
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
AwpCost = get_pcvar_num(ShopAwp)
AwpTime = get_systime() + 604800
if (PlayerXP[id] > AwpCost) {
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle) {
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `awp`='1', `awp_time`='%i' WHERE `user`='%s'",SQL_TABLE,AwpTime,name)
if(!SQL_Execute(Query)) {
// if there were any problems
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
PlayerXP[id] = PlayerXP[id] - AwpCost
PlayerAwp[id] = 1
new iMonth, iDay, iYear, iHour, iMinute, iSecond
new iUnixTime = AwpTime
UnixToTime( iUnixTime , iYear , iMonth , iDay , iHour , iMinute , iSecond )
client_cmd(id, "spk mp3/vipmenu.wav")
client_print(id,print_chat,"Jus sekmingai nusipirkot awp naudojima savaitei.")
client_print(id,print_chat,"Galioja iki %02d-%02d-%02d",iYear , iMonth , iDay)
client_print(id,print_chat,"Jums liko %i taskai(-as)",PlayerXP[id])
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
else {
client_print(id,print_chat,"Jums neuztenka tasku. Awp naudojojimas savaitei kainuoja %i, jus turite %i",AwpCost,PlayerXP[id])
}
}
public BuyPap(id) {
new name[32], PapTime,PapCost
get_user_name(id, name, 31)
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
PapCost = get_pcvar_num(ShopPap)
PapTime = get_systime() + 604800
if (PlayerXP[id] > PapCost) {
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle) {
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `pap`='1', `pap_time`='%i' WHERE `user`='%s'",SQL_TABLE,PapTime,name)
if(!SQL_Execute(Query)) {
// if there were any problems
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
PlayerXP[id] = PlayerXP[id] - PapCost
PlayerPap[id] = 1
new iMonth, iDay, iYear, iHour, iMinute, iSecond
new iUnixTime = PapTime
UnixToTime( iUnixTime , iYear , iMonth , iDay , iHour , iMinute , iSecond )
client_cmd(id, "spk mp3/vipmenu.wav")
client_print(id,print_chat,"Jus sekmingai nusipirkot papildomus bonusus savaitei.")
client_print(id,print_chat,"Galioja iki %02d-%02d-%02d",iYear , iMonth , iDay)
client_print(id,print_chat,"Jums liko %i taskai(-as)",PlayerXP[id])
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}else {
client_print(id,print_chat,"Jums neuztenka tasku. Papildomi bonusai savaitei kainuoja %i, jus turite %i",PapCost,PlayerXP[id])
}
}
public BuyKar(id) {
new name[32], KarTime,KarCost
get_user_name(id, name, 31)
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
KarCost = get_pcvar_num(ShopKar)
KarTime = get_systime() + 604800
if (PlayerXP[id] > KarCost) {
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle) {
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `kar`='1', `kar_time`='%i' WHERE `user`='%s'",SQL_TABLE,KarTime,name)
if(!SQL_Execute(Query)) {
// if there were any problems
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
PlayerXP[id] = PlayerXP[id] - KarCost
PlayerKar[id] = 1
new iMonth, iDay, iYear, iHour, iMinute, iSecond
new iUnixTime = KarTime
UnixToTime( iUnixTime , iYear , iMonth , iDay , iHour , iMinute , iSecond )
client_cmd(id, "spk mp3/vipmenu.wav")
client_print(id,print_chat,"Jus sekmingai nusipirkot kario komplekta savaitei.")
client_print(id,print_chat,"Galioja iki %02d-%02d-%02d",iYear , iMonth , iDay)
client_print(id,print_chat,"Jums liko %i taskai(-as)",PlayerXP[id])
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
else {
client_print(id,print_chat,"Jums neuztenka tasku. Kario komplektas savaitei kainuoja %i, jus turite %i",KarCost,PlayerXP[id])
}
}
public BuySlot(id) {
new name[32], SlotTime,SlotCost
get_user_name(id, name, 31)
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
SlotCost = get_pcvar_num(ShopSlot)
SlotTime = get_systime() + 604800
if (PlayerXP[id] > SlotCost) {
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle) {
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `slot`='1', `slot_time`='%i' WHERE `user`='%s'",SQL_TABLE,SlotTime,name)
if(!SQL_Execute(Query)) {
// if there were any problems
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
PlayerXP[id] = PlayerXP[id] - SlotCost
PlayerSlot[id] = 1
new iMonth, iDay, iYear, iHour, iMinute, iSecond
new iUnixTime = SlotTime
UnixToTime( iUnixTime , iYear , iMonth , iDay , iHour , iMinute , iSecond )
client_cmd(id, "spk mp3/vipmenu.wav")
client_print(id,print_chat,"Jus sekmingai nusipirkot slota savaitei.")
client_print(id,print_chat,"Galioja iki %02d-%02d-%02d",iYear , iMonth , iDay)
client_print(id,print_chat,"Jums liko %i taskai(-as)",PlayerXP[id])
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
else {
client_print(id,print_chat,"Jums neuztenka tasku. Slotas savaitei kainuoja %i, jus turite %i",SlotCost,PlayerXP[id])
}
}
public userPoints(id) {
if(PlayerCon[id]) {
client_print(id,print_chat,"Jus turite %i taskus(-a)",PlayerXP[id])
}
else {
client_print(id,print_chat,"Tik registruoti zaidejai gauna taskus")
}
return PLUGIN_HANDLED
}
public eDeath() {
new killer = read_data(1)
if(PlayerCon[killer]){
new clip, ammo, weapon = get_user_weapon(killer,clip,ammo);
new hs = read_data(3)
PlayerXP[killer] += get_pcvar_num(XP_Kill)
if(hs) {
PlayerXP[killer] += get_pcvar_num(XP_Hs)
}
if(weapon == CSW_KNIFE) {
PlayerXP[killer] += get_pcvar_num(XP_Knife)
}
if(PlayerPap[killer]){
new hpmax = 100
new hpadd = 5
new killerhp = get_user_health(killer)
killerhp += hpadd
if (killerhp > hpmax) killerhp = hpmax
set_user_health(killer, killerhp)
new killermoney = cs_get_user_money(killer)
new moneyadd = 200
new maxmoney = 16000
killermoney += moneyadd
if(killermoney > maxmoney) killermoney = maxmoney
cs_set_user_money(killer, killermoney)
}
}
}
public on_damage(id) {
if (PlayerCon[id]) {
static attacker; attacker = get_user_attacker(id)
static damage; damage = read_data(2)
if ( !(1 <= attacker <= MAX_PLAYERS) ) {
}
else {
if (PlayerDamage[attacker]) {
if (is_user_connected(attacker)) {
set_hudmessage(0, 100, 200, -1.0, 0.55, 2, 0.1, 4.0, 0.02, 0.02, -1)
ShowSyncHudMsg(attacker, g_hudmsg1, "%i^n", damage)
}
}
}
}
}
public UserSQL(name[],id) {
new pass[32]
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle){
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"SELECT * FROM `%s` WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
PlayerCon[id] = false
}
else {
new qcolAuth = SQL_FieldNameToNum(Query, "user")
new qcolPass = SQL_FieldNameToNum(Query, "password")
new qcolAccess = SQL_FieldNameToNum(Query, "access")
new qcolPoints = SQL_FieldNameToNum(Query, "points")
new qcolTime = SQL_FieldNameToNum(Query, "time")
new qcolActive = SQL_FieldNameToNum(Query, "active")
new qcolBan = SQL_FieldNameToNum(Query, "ban")
new qcolDamage = SQL_FieldNameToNum(Query, "damage")
new qcolDMTime = SQL_FieldNameToNum(Query, "damage_time")
new qcolSlot = SQL_FieldNameToNum(Query, "slot")
new qcolSlotTime = SQL_FieldNameToNum(Query, "slot_time")
new qcolAwp = SQL_FieldNameToNum(Query, "awp")
new qcolAwpTime = SQL_FieldNameToNum(Query, "awp_time")
new qcolPap = SQL_FieldNameToNum(Query, "pap")
new qcolPapTime = SQL_FieldNameToNum(Query, "pap_time")
new qcolKar = SQL_FieldNameToNum(Query, "kar")
new qcolKarTime = SQL_FieldNameToNum(Query, "kar_time")
new qcolAdmin = SQL_FieldNameToNum(Query, "admin")
new qcolAdminTime = SQL_FieldNameToNum(Query, "admin_time")
new AuthData[44]
new Password[44]
new Access[32]
new pPoints, pTime, pDamage, pTimeDamage, pBan, pActive
new pSlot, pSlotTime, pAwp, pAwpTime, pPap, pPapTime, pKar, pKarTime, pAdmin, pAdminTime
SQL_ReadResult(Query, qcolAuth, AuthData, sizeof(AuthData)-1)
SQL_ReadResult(Query, qcolPass, Password, sizeof(Password)-1)
SQL_ReadResult(Query, qcolAccess, Access, sizeof(Access)-1)
pPoints = SQL_ReadResult(Query,qcolPoints)
pTime = SQL_ReadResult(Query,qcolTime)
pBan = SQL_ReadResult(Query,qcolBan)
pActive = SQL_ReadResult(Query,qcolActive)
pTime = SQL_ReadResult(Query,qcolTime)
pDamage = SQL_ReadResult(Query,qcolDamage)
pTimeDamage = SQL_ReadResult(Query,qcolDMTime)
pSlot = SQL_ReadResult(Query,qcolSlot)
pSlotTime = SQL_ReadResult(Query,qcolSlotTime)
pAwp = SQL_ReadResult(Query,qcolAwp)
pAwpTime = SQL_ReadResult(Query,qcolAwpTime)
pPap = SQL_ReadResult(Query,qcolPap)
pPapTime = SQL_ReadResult(Query,qcolPapTime)
pKar = SQL_ReadResult(Query,qcolKar)
pKarTime = SQL_ReadResult(Query,qcolKarTime)
pAdmin = SQL_ReadResult(Query,qcolAdmin)
pAdminTime = SQL_ReadResult(Query,qcolAdminTime)
get_user_info(id, "_pw", pass, 31)
replace_all(pass,31,"`","\`")
replace_all(pass,31,"'","\'")
if (!equal(Password,pass)) {
server_cmd("kick #%d Wrong pass", get_user_userid(id))
}
else {
if (pBan) {
server_cmd("kick #%d You^'r user account is banned", get_user_userid(id))
}
if (!pActive) {
server_cmd("kick #%d You^'r user account is not activated", get_user_userid(id))
}
PlayerCon[id] = true
PlayerXP[id] = pPoints
PlayerTime[id] = pTime
PlayerDamage[id] = pDamage
PlayerUnixTimeDamage[id] = pTimeDamage
PlayerSlot[id] = pSlot
PlayerSlotTime[id] = pSlotTime
PlayerAwp[id] = pAwp
PlayerAwpTime[id] = pAwpTime
PlayerPap[id] = pPap
PlayerPapTime[id] = pPapTime
PlayerKar[id] = pKar
PlayerKarTime[id] = pKarTime
PlayerAdmin[id] = pAdmin
PlayerAdminTime[id] = pAdminTime
remove_user_flags(id, read_flags("z"))
set_user_flags(id,read_flags(Access))
if (pTimeDamage < get_systime()) {
PlayerDamage[id] = 0
PlayerDamage[id] = 0
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `damage`='0', `damage_time`='0' WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
// Nieko enrasta
}
}
if (pSlotTime < get_systime()) {
PlayerSlotTime[id] = 0
PlayerSlot[id] = 0
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `slot`='0', `slot_time`='0' WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
// Nieko enrasta
}
}
if (pAwpTime < get_systime()) {
PlayerAwpTime[id] = 0
PlayerAwp[id] = 0
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `awp`='0', `awp_time`='0' WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
// Nieko enrasta
}
}
if (pPapTime < get_systime()) {
PlayerPapTime[id] = 0
PlayerPap[id] = 0
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `pap`='0', `pap_time`='0' WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
// Nieko enrasta
}
}
if (pKarTime < get_systime()) {
PlayerKarTime[id] = 0
PlayerKar[id] = 0
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `kar`='0', `kar_time`='0' WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
// Nieko enrasta
}
}
if (pAdminTime < get_systime()) {
PlayerAdminTime[id] = 0
PlayerAdmin[id] = 0
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `access`='z', `admin`='0', `admin_time`='0' WHERE `user`='%s'",SQL_TABLE,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
else if (!SQL_NumResults(Query)) {
// Nieko enrasta
}
}
}
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
public client_authorized(id) {
new name[32]
get_user_name(id, name, 31)
UserSQL(name,id)
new maxplayers = get_maxplayers()
new players = get_playersnum(1)
new limit = maxplayers - 1
new resType = get_cvar_num("slot_reserv")
new who
if ( players > limit ) {
if (PlayerSlot[id]) {
switch(resType) {
case 1:
who = kickFresh()
case 2:
who = kickLag()
}
if(who) {
new name[32]
get_user_name( who, name , 31 )
client_cmd(id,"echo ^"* %s was kicked to free this slot^"" ,name )
}
return PLUGIN_CONTINUE
}
if ( is_user_bot(id) )
server_cmd("kick #%d", get_user_userid(id) )
else
client_cmd(id,"echo ^"Server is Full.^";disconnect")
return PLUGIN_HANDLED // block connect in other plugins (especially in consgreet)
}
return PLUGIN_CONTINUE
}
public client_infochanged(id) {
new name[32], oldname[32]
get_user_name(id, oldname, 31)
get_user_info(id, "name", name, 31)
if (!equali(name, oldname)) {
UserSQL(name,id)
}
}
public client_disconnect(id) {
if (PlayerCon[id]) {
new name[32], mOsef[8], Rank
get_user_name(id, name, 31)
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
Rank = get_user_stats(id, mOsef, mOsef)
PlayerTime[id] = PlayerTime[id] + get_user_time(id)
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle){
log_amx(g_Error)
}
new Handle:Query = SQL_PrepareQuery(SqlConnection,"UPDATE `%s` SET `points`='%i', `time`='%i',`rank`='%i' WHERE `user`='%s'",SQL_TABLE,PlayerXP[id],PlayerTime[id],Rank,name)
if(!SQL_Execute(Query)) {
SQL_QueryError(Query,g_Error,511)
log_amx(g_Error)
}
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnection)
}
}
stock ham_give_weapon(id,weapon[]) {
if(!equal(weapon,"weapon_",7)) return 0;
new wEnt = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,weapon));
if(!pev_valid(wEnt)) return 0;
set_pev(wEnt,pev_spawnflags,SF_NORESPAWN);
dllfunc(DLLFunc_Spawn,wEnt);
if(!ExecuteHamB(Ham_AddPlayerItem,id,wEnt))
{
if(pev_valid(wEnt)) set_pev(wEnt,pev_flags,pev(wEnt,pev_flags) | FL_KILLME);
return 0;
}
ExecuteHamB(Ham_Item_AttachToPlayer,wEnt,id)
return 1;
}
stock client_printc(const id, const string[], {Float, Sql, Resul,_}:...) {
new msg[191], players[32], count = 1;
vformat(msg, sizeof msg - 1, string, 3);
replace_all(msg,190,"!g","^4");
replace_all(msg,190,"!y","^1");
replace_all(msg,190,"!t","^3");
if(id)
players[0] = id;
else
get_players(players,count,"ch");
for (new i = 0 ; i < count ; i++) {
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, g_SayText,_, players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
kickLag() {
new who = 0, ping, loss, worst = -1
new maxplayers = get_maxplayers()
for(new i = 1; i <= maxplayers; ++i) {
if ( !is_user_connected(i) && !is_user_connecting(i) )
continue // not used slot
if (PlayerSlot[i])
continue // has reservation, skip him
get_user_ping(i,ping,loss) // get ping
if ( ping > worst ) {
worst = ping
who = i
}
}
if(who)
if ( is_user_bot(who) )
server_cmd("kick #%d", get_user_userid(who) )
else
client_cmd(who,"echo ^"Dropped due to high ping to free slot for an admin^";disconnect")
return who
}
kickFresh() {
new who = 0, itime, shortest = 0x7fffffff
new maxplayers = get_maxplayers()
for(new i = 1; i <= maxplayers; ++i){
if ( !is_user_connected(i) && !is_user_connecting(i) )
continue // not used slot
if (PlayerSlot[i])
continue // has reservation, skip him
itime = get_user_time(i) // get user playing time with connection duration
if ( shortest > itime ) {
shortest = itime
who = i
}
}
if(who)
if ( is_user_bot(who) )
server_cmd("kick #%d", get_user_userid(who) )
else
client_cmd(who,"echo ^"Dropped due to shortest playing time to free slot for an admin^";disconnect")
return who
}
public Player_Spawn_Post( id ){
if(PlayerCon[id] && PlayerKar[id]){
fm_give_item(id, "item_kevlar")
fm_give_item(id, "item_assaultsuit")
fm_give_item(id, "weapon_flashbang")
fm_give_item(id, "weapon_flashbang")
fm_give_item(id, "weapon_hegrenade")
fm_give_item(id, "weapon_smokegrenade")
fm_give_item(id, "item_thighpack")
}
g_iLastTouchedBox[id] = 0
if(round == 4){
if(PlayerCon[id]) {
client_print(id,print_chat,"Jus turite %i taskus(-a)",PlayerXP[id])
}
else {
client_print(id,print_chat,"Tik registruoti zaidejai gauna taskus")
client_print(id,print_chat,"Uzsiregistruokite www.inch.lt puslapyje")
}
}
return PLUGIN_HANDLED
}
public WeaponBox_Touch(iWpnBx, id)
{
if( is_user_alive(id) && entity_get_int(iWpnBx, EV_INT_flags) & FL_ONGROUND )
{
const XTRA_OFS_WEAPONBOX = 4
const m_rgpPlayerItems_wpnbx_slot1 = 35
static iWeapon
iWeapon = get_pdata_cbase(iWpnBx, m_rgpPlayerItems_wpnbx_slot1, XTRA_OFS_WEAPONBOX)
if( !PlayerCon[id]){
if( !PlayerAwp[id]) {
if( iWeapon > 0 && cs_get_weapon_id(iWeapon) == CSW_AWP )
{
if( g_iLastTouchedBox[id] != iWpnBx )
{
if( !user_has_weapon(id, CSW_AWP) )
{
Message_No_Awp(id)
}
g_iLastTouchedBox[id] = iWpnBx
}
return PLUGIN_HANDLED
}
}
}
}
return PLUGIN_CONTINUE
}
public BuyRifle(id)
{
if( !PlayerCon[id] ){
if( !PlayerAwp[id]){
Message_No_Awp(id)
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public client_command(id)
{
static szCommand[8]
if( read_argv(0, szCommand, charsmax(szCommand)) < 7 && bCheckArgAwp(id, szCommand) )
{
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public CS_InternalCommand(id, const szCommand[])
{
if( strlen(szCommand) < 7 && bCheckArgAwp(id, szCommand) )
{
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
bool:bCheckArgAwp(id, const szCommand[])
{
static const awp[] = "awp"
static const magnum[] = "magnum"
if(!PlayerCon[id]){
if(!PlayerAwp[id] && ( equali(szCommand, awp) || equali(szCommand, magnum) )){
Message_No_Awp(id)
return true
}
}
return false
}
Message_No_Awp(id)
{
const HUD_PRINTCENTER = 4
static const szOnlyVIP[] = "Tu negali naudoti awp ginklu"
message_begin(MSG_ONE_UNRELIABLE, gmsgTextMsg, .player=id)
write_byte( HUD_PRINTCENTER )
write_string( szOnlyVIP )
message_end()
}
public plugin_end() {
SQL_FreeHandle(g_SqlTuple)
}