Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#define VOTETIME 75.0 //time after map starts when the vote begins
new normalsky[64];
new choice[2]
new is = 1
new was = 1
new reconnect = 0
public client_putinserver() { // This is to fix the engine bug in amxx 1.60 you can delete this if your running 1.65
if(get_cvar_num("sv_daynight") == 1)
{
if(is == 1)
{
set_lights("#OFF")
}
else
{
set_lights("b")
}
}
}
public plugin_init() {
register_logevent("reconnectplayers",2,"0=World triggered","1=Round_Start")
get_cvar_string("sv_skyname" , normalsky , 63);
is = 1
was = is
register_plugin("daynight","1.00","NL)Ramon(NL")
register_cvar("sv_daynight", "1")
register_concmd("amx_voteday","votedaynow", ADMIN_BAN," : <0 or 1> 1 = day 2 = night")
register_menucmd(register_menuid("menu_1"),(1<<0)|(1<<1),"count_votes")
set_task(VOTETIME,"voteday")
}
public plugin_precache() {
precache_generic("gfx/env/spacert.tga")
precache_generic("gfx/env/spacelf.tga")
precache_generic("gfx/env/spaceft.tga")
precache_generic("gfx/env/spacedn.tga")
precache_generic("gfx/env/spacebk.tga")
precache_generic("gfx/env/spaceup.tga")
}
public votedaynow(id,level,cid) {
if (get_cvar_num("sv_daynight") == 1)
{
if (!cmd_access(id,level,cid,1)) {
return PLUGIN_HANDLED
}
voteday()
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public voteday() {
if (get_cvar_num("sv_daynight") == 1)
{
show_menu(0,(1<<0)|(1<<1), "Do you want day or night modus^n^n1: Day^n2: Night", 15, "menu_1") // Display menu
set_task(15.0,"check_the_votes")
choice[0] = 0
choice[1] = 0
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public count_votes(id,key){
new name[32]
get_user_name(id,name,31)
new what[6] = "day"
if (key == 1) what = "night"
client_print(0,print_chat,"* %s voted %s", name, what)
++choice[key]
return PLUGIN_HANDLED
}
public check_the_votes(id){
if (choice[0] >= choice[1]){
set_cvar_string("sv_skyname" , normalsky);
client_print(0,print_chat,"* Day mode on. (Day ^"%d^") (Night ^"%d^"). *",choice[0],choice[1])
set_lights("#OFF")
is = 1
checkclient()
} else {
server_cmd("sv_skyname space")
client_print(0,print_chat,"* Night mode on. (Day ^"%d^") (Night ^"%d^"). *",choice[0],choice[1])
set_lights("b")
is = 0
checkclient()
}
return PLUGIN_CONTINUE
}
public checkclient(){
if (is == was)
{
return PLUGIN_HANDLED
}
else
{
client_print(0,print_chat,"Reconnecting all players on next round seconds to change sky")
was = is
reconnect = 1
}
return PLUGIN_CONTINUE
}
public reconnectplayers() {
if (reconnect == 1)
{
reconnect = 0
client_cmd(0,"reconnect")
}
}