here's code that worked with AMXX1.50 - could anyone help to solve this problem? (Bailopan, Kr@tal, ...)? ThanX
Code:
/* AMX Mod script.
*
* [AFK_MANAGER] AFK Plugin for AMXMOD ([email protected])
*
* This file is provided as is (no warranties).
*
*/
/* put in amx.cfg:
*
* enable / disable afk checking when bomb is planted or when hostages are grabbed 0=off 1=on (default 1)
* amx_afkonobj < value >
*
* enable / disable afk checking on round end or when player is killed 0=off 1=on (default 1)
* amx_afkcheck < value >
*
* rounds before idler is kicked (default 2)
* amx_afkrounds < value >
*
* enable / disable afk resetting if a player was afk but came back 0=off 1=on (default 1)
* amx_resetafk < value >
*
*/
#include <amxmodx>
new afk_pos
[33][3]
new afk_count
[33]
new Float:t_respawn
[33]
new user_money
[33]
public plugin_init
() {
register_plugin("AFK MANAGER",
"1.0",
"outkast134 ([email protected])")
register_cvar("amx_afkonobj",
"1")
register_cvar("amx_afkcheck",
"1")
register_cvar("amx_afkrounds",
"2")
register_cvar("amx_resetafk",
"1")
register_event("RoundTime",
"round_start",
"bc")
register_event("SendAudio",
"user_plbomb",
"ac",
"2&%!MRAD_BOMBPL")
register_event("SendAudio",
"round_end",
"ac",
"2=%!MRAD_terwin",
"2=%!MRAD_ctwin",
"2=%!MRAD_rounddraw")
register_event("TextMsg",
"map_restart",
"ac",
"2&#Game_C",
"2&#Game_w")
register_event("DeathMsg",
"client_death",
"a")
register_event("DeathMsg",
"reset_player",
"a")
register_event("DeathMsg",
"check_lastman",
"a")
register_event("Money",
"user_touchhost",
"b",
"2=1")
register_event("ResetHUD",
"plr_respawn",
"b")
new mapname
[4]
get_mapname(mapname,
3)
if (!equali(mapname,
"de_",
3)) {
pause ("b",
"user_plbomb")
} else if (!equali(mapname,
"cs_",
3)) {
pause ("b",
"user_touchhost")
} else if (!equali(mapname,
"de_",
3) ||
!equali(mapname,
"cs_",
3)) {
pause ("b",
"user_plbomb")
pause ("b",
"user_touchhost")
}
}
public client_connect
(id
){
afk_pos
[id
][0] = 0
afk_pos
[id
][1] = 0
afk_pos
[id
][2] = 0
afk_count
[id
] = 0
return PLUGIN_CONTINUE
}
public client_disconnect
(id
){
afk_pos
[id
][0] = 0
afk_pos
[id
][1] = 0
afk_pos
[id
][2] = 0
afk_count
[id
] = 0
return PLUGIN_CONTINUE
}
// resets afk counts when map is restarted
public map_restart
() {
if (get_cvar_num("amx_afkcheck") == 1) {
for(new a
= 1; a <
get_maxplayers() + 1;
++a
) {
afk_count
[a
] = 0
}
}
return PLUGIN_CONTINUE
}
//gets clients coordinates to use with checking for afk later
public round_start
() {
new roundtime
= floatround(get_cvar_float("mp_roundtime") * 60.0)
if (get_cvar_num("amx_afkcheck") == 1 && roundtime
== read_data(1)) {
new origin
[3]
for(new a
= 1; a <
get_maxplayers() + 1;
++a
) {
get_user_origin(a,origin,
0)
afk_pos
[a
][0] = origin
[0]
afk_pos
[a
][1] = origin
[1]
afk_pos
[a
][2] = origin
[2]
}
}
return PLUGIN_CONTINUE
}
// resets a clients afk count if they were afk but are not anymore
public reset_player
() {
if (get_cvar_num("amx_afkcheck") == 1 && get_cvar_num("amx_resetafk") == 1) {
new killer, victim
killer
= read_data(1)
victim
= read_data(2)
//make sure there is no worldspawn and that the user didnt kill himself
if (killer
!= victim
&& killer
) {
if (afk_count
[killer
] >
0) {
//if player gets a kill hes not afk anymore and his count starts over
afk_count
[killer
] = 0
}
}
}
return PLUGIN_CONTINUE
}
//checks for afks at rounds end
public round_end
() {
if (get_cvar_num("amx_afkcheck") == 1) {
for(new a
= 1; a <
get_maxplayers() + 1;
++a
) {
// only check the alive players
if (is_user_alive(a
)) {
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3], authid
[32], name
[32]
get_user_origin(a,origin,
0)
//compare coords with spawn ones
if (origin
[0] == afk_pos
[a
][0] && origin
[1] == afk_pos
[a
][1] && origin
[2] != 0) {
afk_count
[a
]++
// if user has been afk for X rounds straight we will kick them
if (afk_count
[a
] >
= afk_max
) {
client_cmd(a,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(a,authid,
31)
get_user_name(a,name,
31)
//log_message("[AFK MANAGER] %s<%s> kicked due to idling",name,authid)
client_print(0,print_chat,
"[AFK MANAGER] %s was kicked being afk too much.",name
)
} else {
get_user_name(a,name,
31)
//slay the afk player and count it
user_kill(a,
1)
client_print(0,print_chat,
"[AFK MANAGER] %s was slayed for being AFK.",name
)
}
}
}
}
}
return PLUGIN_CONTINUE
}
// checks to see if player was afk at spawn when killed
public client_death
() {
if (get_cvar_num("amx_afkcheck") == 1) {
new killer, victim, killerteam, victimteam
killer
= read_data(1)
victim
= read_data(2)
killerteam
= get_user_team(killer
)
victimteam
= get_user_team(victim
)
if (killerteam
== victimteam
)
return PLUGIN_HANDLED
//make sure that the victim did not kill himself and that it was not a worldspawn
if (killer
!= victim
&& killer
){
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3], authid
[32], name
[32]
get_user_origin(victim,origin,
0)
//compare coords with spawn ones
if ( (origin
[0] > afk_pos
[victim
][0] - 10 && origin
[0] < afk_pos
[victim
][0] + 10) &&
(origin
[1] > afk_pos
[victim
][1] - 10 && origin
[1] < afk_pos
[victim
][1] + 10) &&
(origin
[2] != 0) ) {
afk_count
[victim
]++
// if user has been afk for X rounds straight we will kick them
if (afk_count
[victim
] >
= afk_max
) {
client_cmd(victim,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(victim,authid,
31)
get_user_name(victim,name,
31)
//log_message("[AFK MANAGER] %s<%s> kicked due to idling",name,authid)
client_print(0,print_chat,
"[AFK MANAGER] %s was kicked being afk too much.",name
)
} else {
get_user_name(victim,name,
31)
client_print(0,print_chat,
"[AFK MANAGER] %s was AFK.",name
)
}
}
}
}
return PLUGIN_CONTINUE
}
//checks to make sure that the last man standing on a team isn't afk
public check_lastman
() {
new team
new tnum
= 0
new ctnum
= 0
new ct_id
new t_id
for(new a
= 1; a <
get_maxplayers() + 1;
++a
) {
if (is_user_alive(a
)) {
team
= get_user_team(a
)
if (team
== 1) {
t_id
= a
tnum
++
}
if (team
== 2) {
ct_id
= a
ctnum
++
}
}
}
if (tnum >
1 && ctnum >
1) {
return PLUGIN_HANDLED
}
if (tnum
== 1 && ctnum >
1 && t_id
!= 0) {
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3], authid
[32], name
[32]
get_user_origin(t_id,origin,
0)
//compare coords with spawn ones
if (origin
[0] == afk_pos
[t_id
][0] && origin
[1] == afk_pos
[t_id
][1] && origin
[2] != 0) {
afk_count
[t_id
]++
// if user has been afk for X rounds straight we will kick them
if (afk_count
[t_id
] >
= afk_max
) {
client_cmd(t_id,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(t_id,authid,
31)
get_user_name(t_id,name,
31)
//log_message("[AFK MANAGER] %s<%s> kicked due to idling",name,authid)
client_print(0,print_chat,
"[AFK MANAGER] %s was kicked being afk too much.",name
)
} else {
get_user_name(t_id,name,
31)
user_kill(t_id,
1)
client_print(0,print_chat,
"[AFK MANAGER] %s was slayed for being AFK.",name
)
}
}
}
if (ctnum
== 1 && tnum >
1 && ct_id
!= 0) {
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3], authid
[32], name
[32]
get_user_origin(ct_id,origin,
0)
//compare coords with spawn ones
if (origin
[0] == afk_pos
[ct_id
][0] && origin
[1] == afk_pos
[ct_id
][1] && origin
[2] != 0) {
afk_count
[ct_id
]++
// if user has been afk for X rounds straight we will kick them
if (afk_count
[ct_id
] >
= afk_max
) {
client_cmd(ct_id,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(ct_id,authid,
31)
get_user_name(ct_id,name,
31)
//log_message("[AFK MANAGER] %s<%s> kicked due to idling",name,authid)
client_print(0,print_chat,
"[AFK MANAGER] %s was kicked being afk too much.",name
)
} else {
get_user_name(ct_id,name,
31)
user_kill(ct_id,
1)
client_print(0,print_chat,
"[AFK MANAGER] %s was slayed for being AFK.",name
)
}
}
}
return PLUGIN_CONTINUE
}
//checks for afks when a player grabs hostages
public user_touchhost
(id
) {
if (get_cvar_num("amx_afkonobj") == 1) {
new money
= read_data(1)
//when a player touches a hostage his money increases by incs of 150
if ((money
- user_money
[id
] == 150) && (t_respawn
[id
] <
get_gametime()) ) {
for(new a
= 1; a <
get_maxplayers() + 1;
++a
) {
//only check alive players for afk
if(is_user_alive(a
)) {
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3], authid
[32], name
[32]
get_user_origin(a,origin,
0)
//compare coords with spawn ones
if (origin
[0] == afk_pos
[a
][0] && origin
[1] == afk_pos
[a
][1] && origin
[2] != 0) {
afk_count
[a
]++
// if user has been afk for X rounds straight we will kick them
if (afk_count
[a
] >
= afk_max
) {
client_cmd(a,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(a,authid,
31)
get_user_name(a,name,
31)
//log_message("[AFK MANAGER] %s<%s> kicked due to idling",name,authid)
client_print(0,print_chat,
"[AFK MANAGER] %s was kicked being afk too much.",name
)
} else {
get_user_name(a,name,
31)
user_kill(a,
1)
client_print(0,print_chat,
"[AFK MANAGER] %s was slayed for being AFK.",name
)
}
}
}
}
}
//update users money
user_money
[id
] = money
}
return PLUGIN_CONTINUE
}
//checks for afks when a player plants the bomb
public user_plbomb
() {
if (get_cvar_num("amx_afkonobj") == 1) {
for(new a
= 1; a <
get_maxplayers() + 1;
++a
) {
//only check alive players for afk
if(is_user_alive(a
)){
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3], authid
[32], name
[32]
get_user_origin(a,origin,
0)
//compare coords with spawn ones
if (origin
[0] == afk_pos
[a
][0] && origin
[1] == afk_pos
[a
][1] && origin
[2] != 0) {
afk_count
[a
]++
// if user has been afk for X rounds straight we will kick them
if (afk_count
[a
] >
= afk_max
) {
client_cmd(a,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(a,authid,
31)
get_user_name(a,name,
31)
//log_message("[AFK MANAGER] %s<%s> kicked due to idling",name,authid)
client_print(0,print_chat,
"[AFK MANAGER] %s was kicked being afk too much.",name
)
} else {
get_user_name(a,name,
31)
user_kill(a,
1)
client_print(0,print_chat,
"[AFK MANAGER] %s was slayed for being AFK.",name
)
}
}
}
}
}
return PLUGIN_CONTINUE
}
//helper function for user_hosttouch
public plr_respawn
(id
) {
t_respawn
[id
] = get_gametime() + 15.0
}