I took the amx code below and ran it through the .20 web compiler and it seems to work fine.I am however getting an error that is filling my logs up.
Can someone take a look and tell me what to fix so it will stop logging this and swelling my logs.
Also I didn't see this plugin listed anywhere, so if someone wants to make sure its updated and keep it current then by all means. I only posted to get help with it, not to maintain it.
Code:
/* AMX Mod script.
*
* [AFK_MANAGER] AFK Plugin for AMXMOD ([email protected])
*
* This file is provided as is (no warranties).
*
*/
/* put in server.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 <amxmod>
#define MAXCLIENTS 32
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("StatusIcon",
"icon_event",
"be",
"1=0",
"2=buyzone")
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("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_putinserver
(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
}
public icon_event
(id
) {
afk_pos
[id
][0] = 0
afk_pos
[id
][1] = 0
afk_pos
[id
][2] = 0
return PLUGIN_CONTINUE
}
public map_restart
() { // resets afk counts when map is restarted
if (get_cvar_num("amx_afkcheck") == 1) {
for(new a
= 1; a < MAXCLIENTS
+ 1;
++a
) {
afk_count
[a
] = 0
}
}
return PLUGIN_CONTINUE
}
public round_start
() { //gets clients coordinates to use with checking for afk later
new roundtime
= floatround(get_cvar_float("mp_roundtime") * 60.0)
if (get_cvar_num("amx_afkcheck") == 1 && get_cvar_num("amx_resetafk") == 1 && roundtime
== read_data(1)) {
new origin
[3]
for(new a
= 1; a < MAXCLIENTS
+ 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
}
public register_afk
(id
){ //checks for afks, registers them, and handles what to do with them
new afk_max
= get_cvar_num("amx_afkrounds")
new origin
[3]
new authid
[32]
new name
[32]
get_user_origin(id,origin,
0)
if (origin
[0] == afk_pos
[id
][0] && origin
[1] == afk_pos
[id
][1] && origin
[2] != 0) { //compare coords with spawn ones
afk_count
[id
]++
if (afk_count
[id
] >
= afk_max
) { // if user has been afk for X rounds straight we will kick them
client_cmd(id,
"echo [AFK MANAGER] Kicked due to idling.;disconnect")
get_user_authid(id,authid,
31)
get_user_name(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
)
return PLUGIN_HANDLED
} else {
get_user_name(id,name,
31)
if (is_user_alive(id
)){ //if the user is afk and alive he gets slayed
user_kill(id,
1)
client_print(0,print_chat,
"[AFK MANAGER] %s was slayed for being AFK.",name
)
} else {
client_print(0,print_chat,
"[AFK MANAGER] %s was AFK.",name
)
}
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public reset_player
(){ // resets a clients afk count if they were afk but are not anymore
if (get_cvar_num("amx_afkcheck") == 1) {
new killer, victim
killer
= read_data(1)
victim
= read_data(2)
if (killer
!= victim
&& killer
){ //make sure there is no worldspawn and that the user didnt kill himself
if (afk_count
[killer
] >
0){
afk_count
[killer
] = 0 //if player gets a kill hes not afk anymore and his count starts over
}
}
}
return PLUGIN_CONTINUE
}
public round_end
() { //checks for afks at rounds end
if (get_cvar_num("amx_afkcheck") == 1) {
for(new a
= 1; a < MAXCLIENTS
+ 1;
++a
) {
if (is_user_alive(a
)){ // only check the alive players
return register_afk
(a
)
}
}
}
return PLUGIN_CONTINUE
}
public client_death
() { // checks to see if player was afk at spawn when killed or if last alive on team
if (get_cvar_num("amx_afkcheck") == 1) {
new killer, victim
killer
= read_data(1)
victim
= read_data(2)
if (killer
!= victim
&& killer
){ //make sure that the victim did not kill himself and that it was not a worldspawn
return register_afk
(victim
)
}
new ctPlayers
= 0, tPlayers
= 0, team, tToCheck, ctToCheck
for(new a
= 1; a < MAXCLIENTS
+ 1;
++a
) {
if(is_user_alive(a
)){ //only check alive players for afk
team
= get_user_team(a
)
if (team
== 1) {
tPlayers
++
tToCheck
= a
}
if (team
== 2) {
ctPlayers
++
ctToCheck
= a
}
}
}
if ( tPlayers
== 1 )
return register_afk
(tToCheck
)
if ( ctPlayers
== 1 )
return register_afk
(ctToCheck
)
}
return PLUGIN_CONTINUE
}
public user_touchhost
(id
) { //checks for afks when a player grabs hostages
if (get_cvar_num("amx_afkonobj") == 1) {
new money
= read_data(1)
if (money
-user_money
[id
]==150 && t_respawn
[id
]<
get_gametime() ) { //when a player touches a hostage his money increases by incs of 150
for(new a
= 1; a < MAXCLIENTS
+ 1;
++a
) {
if(is_user_alive(a
)){ //only check alive players for afk
return register_afk
(a
)
}
}
}
user_money
[id
] = money
//update users money
}
return PLUGIN_CONTINUE
}
public user_plbomb
() { //checks for afks when a player plants the bomb
if (get_cvar_num("amx_afkonobj") == 1) {
for(new a
= 1; a < MAXCLIENTS
+ 1;
++a
) {
if(is_user_alive(a
)){ //only check alive players for afk
return register_afk
(a
)
}
}
}
return PLUGIN_CONTINUE
}
public plr_respawn
(id
) //helper function for user_hosttouch
t_respawn
[id
] = get_gametime() + 15.0