Code:
/* NextMap voting plugin by stetze - visit www.adminmod.de */
/* $Id $ */
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
#define ACCESS_NEXTMAP_VOTE 1
#define ACCESS_CONTROL_VOTE 2
#define MAP_INVALID -1
#define MAX_MAPS 64
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
new ExtendCount = 0;
new ExtendMapTime = 0;
public StartNextMapVote() {
new Text[MAX_TEXT_LENGTH];
new sNextMap[MAX_TEXT_LENGTH];
if (vote_allowed()!=1) {
selfmessage( "NextMap vote not allowed at this time.");
return PLUGIN_HANDLED;
}
new iMaxExtend = getvar("admin_vote_maxextend");
if(ExtendCount < iMaxExtend || iMaxExtend == 0) {
nextmap(sNextMap,30)
if (valid_map(sNextMap) == 1) {
snprintf(Text, MAX_TEXT_LENGTH, "Change to %s or extend current map?", sNextMap);
log(Text);
vote(Text,"Change","Extend","HandleNextMapVote",sNextMap);
} else {
say("Oops, Nextmap-Voting failed!");
}
}
return PLUGIN_HANDLED;
}
public ChangeNextMap(Timer,Repeat,HLUser,HLParam) {
new NewMap[MAX_NAME_LENGTH];
convert_string(HLParam,NewMap,MAX_NAME_LENGTH);
if(strlen(NewMap) != 0) {
changelevel(NewMap);
}
}
public ExtendNextMap(Timer,Repeat,HLUser,HLParam) {
new iFreq = getvar("admin_vote_freq");
new ExecCommand[MAX_DATA_LENGTH];
new Timelimit = 0;
new VaultData[MAX_DATA_LENGTH];
new intTime = timeleft(0);
ExtendCount++;
Timelimit = getvar("mp_timelimit");
Timelimit += GetExtendTime();
snprintf(ExecCommand, MAX_DATA_LENGTH, "mp_timelimit %i", Timelimit);
exec(ExecCommand);
if (iFreq > 0) {
set_timer("AllowMapVote",iFreq,1);
}
get_vaultdata("NEXTMAP_AUTOSTART",VaultData, MAX_DATA_LENGTH);
if(VaultData[0] == '1') {
/* Call for a vote two minutes before map ends */
set_timer("StartNextMapVote", intTime + ((ExtendMapTime - 2) * 60),1);
}
}
/* Handle a map vote's results. */
public HandleNextMapVote(WinningOption,HLMap,VoteCount,UserCount) {
new strNumber[MAX_NUMBER_LENGTH];
new Text[MAX_TEXT_LENGTH];
new VoteMap[MAX_DATA_LENGTH];
convert_string(HLMap,VoteMap,MAX_DATA_LENGTH);
if (WinningOption == 1) {
new Ratio = getvar("map_ratio");
if (VoteCount >= Ratio*UserCount/100) {
snprintf(Text, MAX_TEXT_LENGTH, "Changing map to %s due to vote.", VoteMap);
say(Text);
exec("mp_timelimit 1");
set_timer("ChangeNextMap",2,1,VoteMap);
} else {
numtostr(Ratio*UserCount/100,strNumber);
snprintf(Text, MAX_TEXT_LENGTH, "NextMap vote succeeded, but not enough votes for change (needed %s)", strNumber);
say(Text);
}
} else {
if(WinningOption == 2) {
new iExtend = GetExtendTime();
snprintf(Text, MAX_TEXT_LENGTH, "Nextmap vote over. Current map will be extended for %i minutes. ", iExtend);
say(Text);
set_timer("ExtendNextMap",2,1);
} else {
say("Map vote failed.");
}
}
}
/* Return the amount of time (in minutes) to extend a map for if an extend vote wins. */
GetExtendTime() {
/* If this is the first time we're extending the map, we want to extend it
by the length of mp_timelimit. Second and subsequent times through, we want
to keep extending it by the original timelimit...not the new one (eg, if we
start at 30 mins...on the second time through, mp_timelimit will say 60. We
want to jump to 90, not 120. */
if (ExtendMapTime == 0) {
ExtendMapTime = getvar("mp_timelimit");
}
return ExtendMapTime;
}
public admin_map_maxextend(HLCommand,HLData,HLUserName,UserIndex) {
new Command[MAX_COMMAND_LENGTH];
new Data[MAX_DATA_LENGTH];
new User[MAX_NAME_LENGTH];
convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
convert_string(HLData,Data,MAX_DATA_LENGTH);
convert_string(HLUserName,User,MAX_NAME_LENGTH);
execute_command(User,Command,"admin_vote_maxextend",Data);
return PLUGIN_HANDLED;
}
public admin_vote_nextmap(HLCommand,HLData,HLUserName,UserIndex) {
new Command[MAX_COMMAND_LENGTH];
new Data[MAX_DATA_LENGTH];
new Text[MAX_TEXT_LENGTH];
new User[MAX_NAME_LENGTH];
new sNextMap[MAX_TEXT_LENGTH];
if (vote_allowed()!=1) {
selfmessage( "Vote not allowed at this time.");
return PLUGIN_HANDLED;
}
convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
convert_string(HLData,Data,MAX_DATA_LENGTH);
convert_string(HLUserName,User,MAX_NAME_LENGTH);
nextmap(sNextMap,30);
if (valid_map(sNextMap) == 1) {
snprintf(Text, MAX_TEXT_LENGTH, "Change to %s or extend current map?", sNextMap);
log(Text);
vote(Text,"Change","Extend","HandleNextMapVote",sNextMap);
} else {
say("Oops, Nextmap-Voting failed!");
}
return PLUGIN_HANDLED;
}
public plugin_init() {
plugin_registerinfo("NextMap voting plugin by stetze","Enables Voting for Nextmap or extend - visit www.adminmod.de 4 more!",STRING_VERSION);
plugin_registercmd("admin_vote_nextmap","admin_vote_nextmap",ACCESS_NEXTMAP_VOTE,"admin_vote_nextmap: Starts Voting for NextMap or extend the current map.");
plugin_registercmd("admin_map_maxextend","admin_map_maxextend",ACCESS_CONTROL_VOTE,"admin_map_maxextend <nr>: Sets how often a map can be extended.");
new intTime = timeleft(0);
new VaultData[MAX_DATA_LENGTH];
/*
new sVaultData[MAX_DATA_LENGTH];
get_vaultdata("NEXTMAP_AUTOSTART", sVaultData, MAX_DATA_LENGTH);
VaultData = strtonum(sVaultData);
if(VaultData == '1' || VaultData == 1) { */
get_vaultdata("NEXTMAP_AUTOSTART",VaultData, MAX_DATA_LENGTH);
if(VaultData[0] == '1') {
/* Call for a vote two minutes before map ends */
set_timer("StartNextMapVote", intTime - 120, 1);
}
return PLUGIN_CONTINUE;
}
[/code]