Du darfst mein Betatester sein. Ich habe heute den ganzen Tag dran geschrieben
Hier der Code für das multimapvote Plugin:
Code:
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
new STRING_VERSION[MAX_DATA_LENGTH] = "1.0";
#define MAX_NOMINATIONS 9
new MAPS[MAX_TEXT_LENGTH]="mapvote.ini";
new vote_canceled=0;
new NominatedMaps[MAX_NOMINATIONS][MAX_NAME_LENGTH];
new VoteEcho[MAX_NUMBER_LENGTH];
new VoteEchoRecover[MAX_TEXT_LENGTH];
new origTimelimit;
InitializeNominatedMaps() {
new MapCount;
for(MapCount=0;MapCount<MAX_NOMINATIONS;MapCount++) {
NominatedMaps[MapCount][0] = NULL_CHAR;
}
return PLUGIN_HANDLED;
}
public admin_vote_maps(HLCommand,HLData,HLUserName,UserIndex){
new Map[MAX_NAME_LENGTH];
new msg[MAX_TEXT_LENGTH] = "Mapwechsel zu:";
new nochange[MAX_TEXT_LENGTH] = "Vote Extend";
new i;
new iLine;
if (vote_allowed()!=1) {
selfmessage( "Ein Vote ist zur Zeit nicht zulaessig");
return PLUGIN_HANDLED;
}
iLine=filesize(MAPS,1);
if(iLine==0){
selfmessage("Die votemap.ini ist leer. Bitte admin_vote_add <map> ausfuehren.");
return PLUGIN_HANDLED;
}else{
if(iLine>8){
iLine=8;
}
}
for(i=1;i<=iLine;i++){
readfile(MAPS,Map,i,MAX_NAME_LENGTH);
NominatedMaps[i]=Map;
/*DEBUG
new Msg[MAX_TEXT_LENGTH];
snprintf(Msg,MAX_TEXT_LENGTH,"Linie:%i, i:%i, Map:%s %s",iLine,i,Map,NominatedMaps[i]);
say(Msg);
*/
}
switch(i-1){
case 1: vote(msg,nochange,NominatedMaps[1],"HVoteMap","");
case 2: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],"HVoteMap","");
case 3: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],NominatedMaps[3],"HVoteMap","");
case 4: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],NominatedMaps[3],NominatedMaps[4],"HVoteMap","");
case 5: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],NominatedMaps[3],NominatedMaps[4],NominatedMaps[5],"HVoteMap","");
case 6: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],NominatedMaps[3],NominatedMaps[4],NominatedMaps[5],NominatedMaps[6],"HVoteMap","");
case 7: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],NominatedMaps[3],NominatedMaps[4],NominatedMaps[5],NominatedMaps[6],NominatedMaps[7],"HVoteMap","");
case 8: vote(msg,nochange,NominatedMaps[1],NominatedMaps[2],NominatedMaps[3],NominatedMaps[4],NominatedMaps[5],NominatedMaps[6],NominatedMaps[7],NominatedMaps[8],"HVoteMap","");
}
getstrvar( "admin_vote_echo", VoteEcho, MAX_NUMBER_LENGTH );
snprintf(VoteEchoRecover,MAX_TEXT_LENGTH,"admin_vote_echo %s",VoteEcho);
exec("admin_vote_echo 1");
return PLUGIN_HANDLED;
}
public HVoteMap(WinningOption,HLMap,VoteCount,UserCount) {
new VoteSubject[MAX_DATA_LENGTH];
new VoteMap[MAX_NAME_LENGTH];
new Msg[MAX_TEXT_LENGTH] = "";
new strNumber[MAX_NUMBER_LENGTH];
new Timelimit = 0;
new Extend[MAX_DATA_LENGTH];
if (WinningOption==1 || WinningOption==0) {
Timelimit = getvar("mp_timelimit");
Timelimit += origTimelimit;
snprintf(Extend, MAX_DATA_LENGTH, "mp_timelimit %i", Timelimit);
exec(Extend);
snprintf(Msg,MAX_TEXT_LENGTH,"Der Vote ergab: Die Map wird um weitere %i min verlaengert",origTimelimit);
say(Msg);
exec(VoteEchoRecover);
return PLUGIN_HANDLED;
}else{
strcpy(VoteMap,NominatedMaps[WinningOption-1], MAX_NAME_LENGTH);
if(valid_map(VoteMap) != 1 && vote_canceled == 0) {
strcat(Msg,"Fehler im Mapvote fuer", MAX_TEXT_LENGTH);
strcat(Msg,VoteSubject, MAX_TEXT_LENGTH);
strcat(Msg,".", MAX_TEXT_LENGTH);
say(Msg);
say("Der Vote ist leider ungueltig!");
exec(VoteEchoRecover);
return PLUGIN_HANDLED;
} else {
strcat(VoteSubject,VoteMap, MAX_TEXT_LENGTH);
}
}
if( vote_canceled!=0 ) {
say("Vote ist fehlgeschlagen!");
vote_canceled=0;
} else {
strcat(Msg,"Der Vote hat ergeben,dass zu ",MAX_TEXT_LENGTH);
strcat(Msg,VoteSubject, MAX_TEXT_LENGTH);
strcat(Msg," gewechselt wird. ",MAX_TEXT_LENGTH);
say(Msg);
Msg = "";
strcat(Msg,"Diese Map hatte ", MAX_TEXT_LENGTH);
numtostr(VoteCount,strNumber);
strcat(Msg,strNumber, MAX_TEXT_LENGTH);
strcat(Msg," vote(s).", MAX_TEXT_LENGTH);
say(Msg);
exec(VoteEchoRecover);
if (WinningOption !=0 && WinningOption !=1 && vote_canceled==0 ) {
changelevel(VoteMap,6);
}
}
return PLUGIN_HANDLED;
}
public admin_vote_cancel(HLCommand,HLData,HLUserName,UserIndex) {
vote_canceled=1;
if (vote_allowed()==1) {
selfmessage( "Ein Vote ist zur Zeit NICHT im Gange!");
return PLUGIN_HANDLED;
}
selfmessage("Der aktuelle Multi-Map-Vote wurde aufgehoben!");
exec(VoteEchoRecover);
InitializeNominatedMaps();
return PLUGIN_HANDLED;
}
public admin_vote_reset(HLCommand,HLData,HLUserName,UserIndex) {
resetfile(MAPS);
selfmessage("Der Inhalt der mapvote.ini wurde geloescht!");
return PLUGIN_HANDLED;
}
public admin_vote_add(HLCommand,HLData,HLUserName,UserIndex) {
new iLine;
new Map[MAX_NAME_LENGTH];
new Msg[MAX_TEXT_LENGTH];
convert_string(HLData,Map,MAX_NAME_LENGTH);
iLine=filesize(MAPS,1);
if(iLine >= 8){
selfmessage("Es sind schon max.8 Maps angelegt");
selfmessage("Man muss admin_vote_reset ausfuehren, um neue Maps anzulegen.");
return PLUGIN_HANDLED;
}
if(valid_map(Map) != 1) {
snprintf(Msg,MAX_TEXT_LENGTH,"Die Map %s ist nicht gueltig.",Map);
selfmessage(Msg);
return PLUGIN_HANDLED;
}else{
writefile(MAPS,Map,-1);
selfmessage("Map in votemap.ini angelegt.");
}
return PLUGIN_HANDLED;
}
public admin_vote_list(HLCommand,HLData,HLUserName,UserIndex) {
new Maps[MAX_NAME_LENGTH];
new i;
new iLine;
iLine=filesize(MAPS,1);
for(i=1;i<=iLine;i++){
readfile(MAPS,Maps,i,MAX_NAME_LENGTH);
snprintf(Maps,MAX_NAME_LENGTH,"%i.%s",i,Maps);
selfmessage(Maps);
}
return PLUGIN_HANDLED;
}
public plugin_init() {
plugin_registerinfo("Multi-Map Vote 1.0","Allows multiple maps to be nominated",STRING_VERSION);
plugin_registercmd("admin_vote_maps","admin_vote_maps",ACCESS_VOTE_MAP,"admin_vote_maps: start a multi-map-vote");
plugin_registercmd("admin_vote_cancel","admin_vote_cancel",ACCESS_VOTE_MAP,"admin_vote_cancel: cancel a multi-map-vote");
plugin_registercmd("admin_vote_reset","admin_vote_reset",ACCESS_VOTE_MAP,"admin_vote_reset: reset the mapvote.ini");
plugin_registercmd("admin_vote_add","admin_vote_add",ACCESS_VOTE_MAP,"admin_vote_add <mapname>: add map in mapvote.ini");
plugin_registercmd("admin_vote_list","admin_vote_list",ACCESS_VOTE_MAP,"admin_vote_list: list maps in mapvote.ini");
origTimelimit=getvar("mp_timelimit");
return PLUGIN_CONTINUE;
}
Und nun die Erklärung:
Mit
admin_vote_add<map> erstellst Du eine mapvote.ini auf dem Server in dem die Maps gespeichert werden, die Du eben als Map angibst. Maximal 8 maps.
Mit
admin_vote_reset wird diese Liste wieder gelöscht.
Mit
admin_vote_list kannst Du Dir die Liste nochmal anzeigen lassen.
Mit
admin_vote_maps startest Du den Vote der Maps, die in der mapvote.ini gespeichert sind. Auf 1. ist Vote Extend festgelegt.
Mit
admin_vote_maps kannst Du den Vote, der 30 sek dauert canceln.
Benötigte Einstellung in der (listen)server.cfg:
file_access_read 1
file_access_write 1
allow_client_exec 1 //bin mir nicht 100% sicher, ob notwendig
Mögliche Bugs: Es könnte mit dem Vote Extend etwas überhand nehmen.
Codeidee aus dem Plugin:
plugin_cavey_votemap zu finden auf adminmod.org