Raised This Month: $ Target: $400
 0% 

adminvote


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
daffy4jr
Junior Member
Join Date: Apr 2007
Old 05-13-2007 , 17:27   adminvote
Reply With Quote #1

I am having some trouble with my adminvote.amxx
I have been trying to get my old adminvote.amx code into amxx file.
everything appears to be the same until the line 563.
I have been trying to do some coding for a friend of mine on MSC mod and helping him to switch over to AMXX. I do not like the amx at all but I love the amxx better because it doesn't crash the server as much anymore. The only problem I have with amxx is the vote system and that is the only thing that crash the server. I did delete a few line from amxx file to allow the server to function without crashing. I don't remember the whole line but I remember it had "Disconnect" on player join. So the server doesn't crash anymore. the players are able to change map by going to the trans point but not able to votemap in chat or party chat. also votepvp is required to function too.

My amxx code is below.

Code:
/* AMX Mod X
*   Admin Votes Plugin
*
* by the AMX Mod X Development Team
*  originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/

#include <amxmodx>
#include <amxmisc>

new g_Answer[128]
new g_optionName[4][32]
new g_voteCount[4]
new g_validMaps
new g_yesNoVote
new g_coloredMenus
new g_voteCaller
new g_Execute[256]
new g_execLen

new bool:g_execResult
new Float:g_voteRatio

public plugin_init()
{
    register_plugin("Admin Votes", AMXX_VERSION_STR, "AMXX Dev Team")
    register_dictionary("adminvote.txt")
    register_dictionary("common.txt")
    register_dictionary("mapsmenu.txt")
    register_menucmd(register_menuid("Change map to "), (1<<0)|(1<<1), "voteCount")
    register_menucmd(register_menuid("Choose map: "), (1<<0)|(1<<1)|(1<<2)|(1<<3), "voteCount")
    register_menucmd(register_menuid("Kick "), (1<<0)|(1<<1), "voteCount")
    register_menucmd(register_menuid("Ban "), (1<<0)|(1<<1), "voteCount")
    register_menucmd(register_menuid("Vote: "), (1<<0)|(1<<1), "voteCount")
    register_menucmd(register_menuid("The result: "), (1<<0)|(1<<1), "actionResult")
    register_concmd("votemap", "cmdVoteMap", 0, "<map> must be adjacent or root town")
    register_concmd("votekick", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
    register_concmd("voteban", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
    register_concmd("vote", "cmdVote", ADMIN_VOTE, "<question> <answer#1> <answer#2>")
    register_concmd("cancelvote", "cmdCancelVote", ADMIN_VOTE, "- cancels last vote")
    
    register_cvar("amx_votekick_ratio","0.40")
    register_cvar("amx_voteban_ratio","0.40")  
    register_cvar("amx_votemap_ratio","0.40")
    register_cvar("amx_vote_ratio","0.02")   
    register_cvar("amx_vote_time","10")
    register_cvar("amx_vote_answers","1")
    register_cvar("amx_vote_delay","60")   
    register_cvar("amx_last_voting","0")
    set_cvar_float("amx_last_voting",0.0)
    register_cvar("amx_show_activity","2")
    register_cvar("amx_allow_pvp_vote","1")
    register_cvar("ms_votemap_type","0")
    
    g_coloredMenus = colored_menus()
}

public cmdCancelVote(id, level, cid)
{
    if (!cmd_access(id, level, cid, 0))
        return PLUGIN_HANDLED

    if (task_exists(99889988, 1))
    {
        new authid[32], name[32]
        
        get_user_authid(id, authid, 31)
        get_user_name(id, name, 31)
        log_amx("Vote: ^"%s<%d><%s><>^" cancel vote session", name, get_user_userid(id), authid)
        
        new players[32], pnum, lTag[16], activity = get_cvar_num("amx_show_activity")
        get_players(players, pnum, "c")
        
        for (new i = 0; i < pnum;i ++)
        {
            format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")
            switch (activity)
            {
                case 2: client_print(players[i], print_chat, "%L", LANG_PLAYER, "ADMIN_CANC_VOTE_2", lTag, name)
                case 1: client_print(players[i], print_chat, "%L", LANG_PLAYER, "ADMIN_CANC_VOTE_1", lTag)
            }
        }
        
        console_print(id, "%L", id, "VOTING_CANC")
        client_print(0,print_chat,"%L",LANG_PLAYER,"VOTING_CANC")
        remove_task(99889988, 1)
        set_cvar_float("amx_last_voting", get_gametime())
    }
    else
        console_print(id, "%L", id, "NO_VOTE_CANC")

    return PLUGIN_HANDLED
}

public delayedExec(cmd[])
    server_cmd("%s", cmd)

public autoRefuse()
{
    log_amx("Vote: %L", "en", "RES_REF")
    client_print(0, print_chat, "%L", LANG_PLAYER, "RES_REF")
}

public actionResult(id, key)
{
    remove_task(4545454)
    
    switch (key)
    {
        case 0:
        {
            set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
            log_amx("Vote: %L", "en", "RES_ACCEPTED")
            client_print(0, print_chat, "%L", LANG_PLAYER, "RES_ACCEPTED")
        }
        case 1: autoRefuse()
    }
    
    return PLUGIN_HANDLED
}

public checkVotes()
{
    new best = 0
    
    if (!g_yesNoVote)
    {
        for (new a = 0; a < 4; ++a)
            if (g_voteCount[a] > g_voteCount[best])
        
        best = a
    }

    new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3]
    new iRatio = votesNum ? floatround(g_voteRatio * float(votesNum), floatround_ceil) : 1
    new iResult = g_voteCount[best]
    new players[32], pnum, i
    
    get_players(players, pnum, "c")
    
    if (iResult < iRatio)
    {
        new lVotingFailed[64]
        
        for (i = 0; i < pnum; i++)
        {
            format(lVotingFailed, 63, "%L", players[i], "VOTING_FAILED")
            if (g_yesNoVote)
                client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_1", lVotingFailed, g_voteCount[0], g_voteCount[1], iRatio)
            else
                client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_2", lVotingFailed, iResult, iRatio)
        }
        
        format(lVotingFailed, 63, "%L", "en", "VOTING_FAILED")
        log_amx("Vote: %s (got ^"%d^") (needed ^"%d^")", lVotingFailed, iResult, iRatio)
        
        return PLUGIN_CONTINUE
    }

    g_execLen = format(g_Execute, 255, g_Answer, g_optionName[best]) + 1
    
    if (g_execResult)
    {
        g_execResult = false
        
        if (is_user_connected(g_voteCaller))
        {
            new menuBody[512], lTheResult[32], lYes[16], lNo[16]
            
            format(lTheResult, 31, "%L", g_voteCaller, "THE_RESULT")
            format(lYes, 15, "%L", g_voteCaller, "YES")
            format(lNo, 15, "%L", g_voteCaller, "NO")
            
            new len = format(menuBody, 511, g_coloredMenus ? "\y%s: \w%s^n^n" : "%s: %s^n^n", lTheResult, g_Execute)
            
            len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", g_voteCaller, "WANT_CONTINUE")
            format(menuBody[len], 511 - len, "^n1. %s^n2. %s", lYes, lNo)
            show_menu(g_voteCaller, 0x03, menuBody, 10, "The result: ")
            set_task(10.0, "autoRefuse", 4545454)
        }
        else
            set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
    }
    
    new lVotingSuccess[32]
    
    for (i = 0; i < pnum; i++)
    {
        format(lVotingSuccess, 31, "%L", players[i], "VOTING_SUCCESS")
        client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_3", lVotingSuccess, iResult, iRatio, g_Execute)
    }
    
    format(lVotingSuccess, 31, "%L", "en", "VOTING_SUCCESS")
    log_amx("Vote: %s (got ^"%d^") (needed ^"%d^") (result ^"%s^")", lVotingSuccess, iResult, iRatio, g_Execute)
    
    return PLUGIN_CONTINUE
}

public voteCount(id, key)
{
    if (get_cvar_num("amx_vote_answers"))
    {
        new name[32]
        get_user_name(id, name, 31)
        
        if (g_yesNoVote)
            client_print(0, print_chat, "%L", LANG_PLAYER, key ? "VOTED_AGAINST" : "VOTED_FOR", name)
        else
            client_print(0, print_chat, "%L", LANG_PLAYER, "VOTED_FOR_OPT", name, key + 1)
    }
    ++g_voteCount[key]
    
    return PLUGIN_HANDLED
}

public cmdVoteMap(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED
    
    new Float:voting = get_cvar_float("amx_last_voting")
    if (voting > get_gametime())
    {
        console_print(id, "%L", id, "ALREADY_VOTING")
        return PLUGIN_HANDLED
    }
    
    if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
    {
        console_print(id, "%L", id, "VOTING_NOT_ALLOW")
        return PLUGIN_HANDLED
    }

    new argc = read_argc()
    if (argc > 5) argc = 5
    
    g_validMaps = 0
    g_optionName[0][0] = 0
    g_optionName[1][0] = 0
    g_optionName[2][0] = 0
    g_optionName[3][0] = 0
    
    for (new i = 1; i < argc; ++i)
    {
        read_argv(i, g_optionName[g_validMaps], 31)
        
        if (is_map_valid(g_optionName[g_validMaps]))
            g_validMaps++
    }
    
    if (g_validMaps == 0)
    {
        new lMaps[16]
        
        format(lMaps, 15, "%L", id, (argc == 2) ? "MAP_IS" : "MAPS_ARE")
        console_print(id, "%L", id, "GIVEN_NOT_VALID", lMaps)
        return PLUGIN_HANDLED
    }

    new menu_msg[256], len = 0
    new keys = 0
    
    if (g_validMaps > 1)
    {
        keys = MENU_KEY_0
        len = format(menu_msg, 255, g_coloredMenus ? "\y%L: \w^n^n" : "%L: ^n^n", LANG_SERVER, "CHOOSE_MAP")
        new temp[128]
        
        for (new a = 0; a < g_validMaps; ++a)
        {
            format(temp, 127, "%d.  %s^n", a+1, g_optionName[a])
            len += copy(menu_msg[len], 255-len, temp)
            keys |= (1<<a)
        }
        
        format(menu_msg[len], 255-len, "^n0.  %L", LANG_SERVER, "NONE")
        g_yesNoVote = 0
    } else {
        new lChangeMap[32], lYes[16], lNo[16]
        
        format(lChangeMap, 31, "%L", LANG_SERVER, "CHANGE_MAP_TO")
        format(lYes, 15, "%L", LANG_SERVER, "YES")
        format(lNo, 15, "%L", LANG_SERVER, "NO")
        format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1.  %s^n2.  %s" : "%s %s?^n^n1.  %s^n2.  %s", lChangeMap, g_optionName[0], lYes, lNo)
        keys = MENU_KEY_1|MENU_KEY_2
        g_yesNoVote = 1
    }
    
    new authid[32], name[32]
    
    get_user_authid(id, authid, 31)
    get_user_name(id, name, 31)
    
    if (argc == 2)
        log_amx("Vote: ^"%s<%d><%s><>^" vote map (map ^"%s^")", name, get_user_userid(id), authid, g_optionName[0])
    else
        log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")", name, get_user_userid(id), authid, g_optionName[0], g_optionName[1], g_optionName[2], g_optionName[3])

    new lTag[16], activity = get_cvar_num("amx_show_activity")
    
    if (activity > 0)
    {
        new players[32], pnum
        
        get_players(players, pnum, "c")
        for (new i = 0; i < pnum; i++)
        {
            format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")
            
            switch (activity)
            {
                case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_MAP_2", lTag, name)
                case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_MAP_1", lTag)
            }
        }
    }

    g_execResult = true
    new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
    
    set_cvar_float("amx_last_voting", get_gametime() + vote_time)
    g_voteRatio = get_cvar_float("amx_votemap_ratio")
    g_Answer = "changelevel %s"
    show_menu(0, keys, menu_msg, floatround(vote_time), (g_validMaps > 1) ? "Choose map: " : "Change map to ")
    set_task(vote_time, "checkVotes", 99889988)
    g_voteCaller = id
    console_print(id, "%L", id, "VOTING_STARTED")
    g_voteCount = {0, 0, 0, 0}
    
    return PLUGIN_HANDLED
}

public cmdVote(id, level, cid)
{
    if (!cmd_access(id, level, cid, 4))
        return PLUGIN_HANDLED
    
    new Float:voting = get_cvar_float("amx_last_voting")
    if (voting > get_gametime())
    {
        console_print(id, "%L", id, "ALREADY_VOTING")
        return PLUGIN_HANDLED
    }
    
    if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
    {
        console_print(id, "%L", id, "VOTING_NOT_ALLOW")
        return PLUGIN_HANDLED
    }

    new quest[48]
    read_argv(1, quest, 47)
    
    if ((contain(quest, "sv_password") != -1) || (contain(quest, "rcon_password") != -1) || (contain(quest, "kick") != -1) || 
        (contain(quest, "addip") != -1) || (contain(quest, "ban") != -1))
    {
        console_print(id, "%L", id, "VOTING_FORBIDDEN")
        return PLUGIN_HANDLED
    }
    
    read_argv(2, g_optionName[0], 31)
    read_argv(3, g_optionName[1], 31)

    new authid[32], name[32]
    
    get_user_authid(id, authid, 31)
    get_user_name(id, name, 31)
    log_amx("Vote: ^"%s<%d><%s><>^" vote custom (question ^"%s^") (option#1 ^"%s^") (option#2 ^"%s^")", name, get_user_userid(id), authid, quest, g_optionName[0], g_optionName[1])

    new activity = get_cvar_num("amx_show_activity")
    
    if (activity > 0)
    {
        new players[32], pnum, lTag[16]
        
        get_players(players, pnum, "c")
        for (new i = 0; i < pnum; i++)
        {
            format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")
            
            switch (activity)
            {
                case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_CUS_2", lTag, name)
                case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_CUS_1", lTag)
            }
        }
    }

    new menu_msg[256], lVote[16]
    
    format(lVote, 15, "%L", LANG_SERVER, "VOTE")
    new keys = MENU_KEY_1|MENU_KEY_2
    
    format(menu_msg, 255, g_coloredMenus ? "\y%s: %s\w^n^n1.  %s^n2.  %s" : "%s: %s^n^n1.  %s^n2.  %s", lVote, quest, g_optionName[0], g_optionName[1])
    g_execResult = false
    
    new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
    
    set_cvar_float("amx_last_voting", get_gametime() + vote_time)
    g_voteRatio = get_cvar_float("amx_vote_ratio")
    format(g_Answer, 127, "%s - %%s", quest)
    show_menu(0, keys, menu_msg, floatround(vote_time), "Vote: ")
    set_task(vote_time, "checkVotes", 99889988)
    g_voteCaller = id
    console_print(id, "%L", id, "VOTING_STARTED")
    g_voteCount = {0, 0, 0, 0}
    g_yesNoVote = 0
    
    return PLUGIN_HANDLED
}

public cmdVoteKickBan(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED
    
    new Float:voting = get_cvar_float("amx_last_voting")
    if (voting > get_gametime())
    {
        console_print(id, "%L", id, "ALREADY_VOTING")
        return PLUGIN_HANDLED
    }

    if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
    {
        console_print(id, "%L", id, "VOTING_NOT_ALLOW")
        return PLUGIN_HANDLED
    }

    new cmd[32]
    
    read_argv(0, cmd, 31)
    
    new voteban = equal(cmd, "amx_voteban")
    new arg[32]
    read_argv(1, arg, 31)
    
    new player = cmd_target(id, arg, 1)
    
    if (!player)
        return PLUGIN_HANDLED
    
    if (voteban && is_user_bot(player))
    {
        new imname[32]
        
        get_user_name(player, imname, 31)
        console_print(id, "%L", id, "ACTION_PERFORMED", imname)
        return PLUGIN_HANDLED
    }

    new keys = MENU_KEY_1|MENU_KEY_2
    new menu_msg[256], lYes[16], lNo[16], lKickBan[16]
    
    format(lYes, 15, "%L", LANG_SERVER, "YES")
    format(lNo, 15, "%L", LANG_SERVER, "NO")
    format(lKickBan, 15, "%L", LANG_SERVER, voteban ? "BAN" : "KICK")
    ucfirst(lKickBan)
    get_user_name(player, arg, 31)
    format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1.  %s^n2.  %s" : "%s %s?^n^n1.  %s^n2.  %s", lKickBan, arg, lYes, lNo)
    g_yesNoVote = 1
    
    if (voteban)
        get_user_authid(player, g_optionName[0], 31)
    else
        num_to_str(get_user_userid(player), g_optionName[0], 31)
    
    new authid[32], name[32]
    
    get_user_authid(id, authid, 31)
    get_user_name(id, name, 31)
    log_amx("Vote: ^"%s<%d><%s><>^" vote %s (target ^"%s^")", name, get_user_userid(id), authid, voteban ? "ban" : "kick", arg)

    new activity = get_cvar_num("amx_show_activity")
    if (activity > 0)
    {
        new players[32], pnum, lTag[16]
        
        get_players(players, pnum, "c")
        for (new i = 0; i < pnum; i++)
        {
            format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "USER")
            format(lKickBan, 15, "%L", players[i], voteban ? "BAN" : "KICK")
            
            switch (activity)
            {
                case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_FOR_2", lTag, name, lKickBan, arg)
                case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_FOR_1", lTag, lKickBan, arg)
            }
        }
    }

    g_execResult = true
    
    new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
    
    set_cvar_float("amx_last_voting", get_gametime() + vote_time)
    g_voteRatio = get_cvar_float(voteban ? "amx_voteban_ratio" : "amx_votekick_ratio")
    g_Answer = voteban ? "banid 30.0 %s kick" : "kick #%s"
    show_menu(0, keys, menu_msg, floatround(vote_time), voteban ? "Ban " : "Kick ")
    set_task(vote_time, "checkVotes", 99889988)
    g_voteCaller = id
    console_print(id, "%L", id, "VOTING_STARTED")
    g_voteCount = {0, 0, 0, 0}
    
    return PLUGIN_HANDLED
}
this is the amx code from the old POS amx...

Code:
/* AMX Mod script.
*
* (c) 2003, OLO
* This file is provided as is (no warranties).
*
* Adapted for MS:C by Thothie
* Changes:
* Global client commands: votemap [mapname] Example: votemap edana
* Works from console or chat, players can start votes for one map only
* Players may only vote for adjacent maps, root towns, or pre-defined custom maps
* - Some hacks involved here, having problems echoing string vars to chat/console.
* CVARS[defalts] 
* custommaps["ww1 unrest pvp_archery pvp_arena"] - List of available custom maps
* LIMITATIONS: Custom maps with partially matched names may cause voting issues.
* amx_votemap_ratio[0.40] % of voting players that need to vote yes for new map.
* amx_vote_time[10] seconds before vote tallying ends
* amx_vote_time[60] seconds between votes
* amx_vote_answers[1] set to 0 to make voting anonymous
*
* ms_votemap_type[0] : restricts/unrestricts vote types
* - 0: Standard - Adjacent, root towns, and custom maps votable only
* - 1: Ultra - All maps votable except boss and gauntlet maps
* - 2: Restricted - Only root towns and custom maps are votable
* Note: You can never vote for the map you are currently on, save through admin vote (pending)
* There is currently no way to block voting for root towns
* If you wish to block voting for custom maps, clear your custommaps cvar in your config
*
* Client Command: votepvp in chat
* cvar: amx_allow_pvp_vote[1] set 0 to disable pvp vote
*
* Internal function: force_map_xxx - where xxx = mapname. For use by MSC mappers.
*
* This vote system will not work with other mods (or even MS 1.35) due to the menu number reversal
*
* These other commands require ADMIN_VOTE access (level j) and have not been changed:
* amx_votekick <name or #userid> Example: amx_votekick "Player"
* amx_voteban <name or #userid> Example: amx_voteban "Player"
* amx_vote < question > < g_Answer1 > < g_Answer2 >
* Examples:
* amx_vote "sv_restart" "5" "0"
* amx_vote "mp_timelimit" "20" "45"
* amx_vote "are you hungry?" "yes" "no"
*
* TO INSTALL:
* copy to msc/addons/amx/plugins - overwrite existing file.
* make sure that adminvote.amx is enabled in your msc/addons/amx/config/plugins.ini
*
*/
  
#include <translator>
#include <amxmodx>
#include <amxmisc>
#include <VexdUM>
#include <string>
#include <file.inc>

#define TOUCH_DELAY 15.0 //delay before checking for transition generated votes (as players oft spawn inside transitions)
#define VOTE_DELAY 20.0 //secondary of above
#define NT_VOTE_DELAY 90.0 //how long before a non-transition activated map can happen after joining a map (prevents map hopping)
#define PLAYER_DIED_DELAY 5.0 //delay for touch votes to stop after player died
#define ERROR_DELAY 1.0 //one message per second, plzktnx
#define VOTE_ULTRA 2
#define VOTE_RESTRICT 1


//globals added by Thothie
new g_customMaps[1280];
new g_cmap_names[256][32]
new g_rootTowns[] = "edana deralia helena";
new g_adjacentMaps[256];
new g_maxplayers;
new g_votedFromChat;
new g_passCommand[256]; //part of changelevel delay hack
new g_touchmap[4][32]
new g_against;
new g_for;
new g_touched;
new Float:loadTime[33];
new Float:g_lastplayerdied[33];

//originals     
new g_Answer[128]
new g_optionName[4][32]
new g_voteCount[4]
new g_validMaps
new g_yesNoVote
new g_logFile[16]
new g_cstrikeRunning
new g_voteCaller
new g_Execute[256]
new g_execLen
new g_invalid_select

new g_alredyVoting[]= "There is already a vote in progress..."
new g_notAllowed[] = "Too soon to start another vote..."
new g_votingStarted[] = "Voting has started..."

new g_playerTag[] = "PLAYER"
new g_adminTag[] = "ADMIN"
 
new bool:g_execResult
new Float:g_voteRatio

public plugin_init() { 
  load_translations("adminvote")

  register_plugin("MSC Adminvote","1.5","mods by Thothie") 

  register_menucmd(register_menuid("Change map to ") ,(1<<0)|(1<<1),"voteCount") 
  register_menucmd(register_menuid("Choose map: ") ,(1<<0)|(1<<1)|(1<<2)|(1<<3),"voteCount") 
  register_menucmd(register_menuid("Kick "),(1<<0)|(1<<1),"voteCount")
  register_menucmd(register_menuid("Ban "),(1<<0)|(1<<1),"voteCount")
  register_menucmd(register_menuid("Vote: ") ,(1<<0)|(1<<1),"voteCount") 
  register_menucmd(register_menuid("The result: ") ,(1<<0)|(1<<1),"actionResult") 

  register_concmd("votemap","cmdVoteMap",0,"<map> must be adjacent or root town") 
  //register_concmd("VOTEMAP","cmdVoteMap",0,"<map> must be adjacent or root town") 
  //register_concmd("Votemap","cmdVoteMap",0,"<map> must be adjacent or root town") 
  register_concmd("amx_votekick","cmdVoteKickBan",ADMIN_VOTE,"<name or #userid>") 
  register_concmd("amx_voteban","cmdVoteKickBan",ADMIN_KICK,"<name or #userid>") 
  register_concmd("amx_vote","cmdVote",ADMIN_KICK,"<question> <answer#1> <answer#2>") 
  register_concmd("amx_cancelvote","cmdCancelVote",ADMIN_KICK,"- cancels last vote")  

  register_srvcmd("dochangelevel","cmdChangeLevel")

  register_cvar("amx_votekick_ratio","0.40")
  register_cvar("amx_voteban_ratio","0.40")  
  register_cvar("amx_votemap_ratio","0.40")
  register_cvar("amx_vote_ratio","0.02")   
  register_cvar("amx_vote_time","10")
  register_cvar("amx_vote_answers","1")
  register_cvar("amx_vote_delay","60")   
  register_cvar("amx_last_voting","0")
  set_cvar_float("amx_last_voting",0.0)
  register_cvar("amx_show_activity","2")
  register_cvar("amx_allow_pvp_vote","1")
  register_cvar("ms_votemap_type","0")

 loadTime[0] = get_gametime(); //store current game time for to delay transition generated votes

  g_cstrikeRunning = (is_running("cstrike") || is_running("czero"))

  get_logfile(g_logFile,15)

    //Thothie
    g_maxplayers = get_maxplayers();
    register_clcmd("say_text","vote_check") ;
    register_cvar("custommaps","ww1 unrest pvp_archery pvp_arena");

    set_task(5.0,"clear_crap");
}

public cmdCancelVote(id,level,cid){

  if (!cmd_access(id,level,cid,0))   
    return PLUGIN_HANDLED

  if ( task_exists( 99889988 , 1 ) ) {
    new authid[32],name[32]

    get_user_authid(id,authid,31) 
    get_user_name(id,name,31)

    log_to_file(g_logFile,"Vote: ^"%s<%d><%s><>^" cancel vote session",name,get_user_userid(id),authid)

    switch(get_cvar_num("amx_show_activity")) {
    case 2: 
      client_print(0,print_chat,"%s %s: cancel vote", (get_user_flags(id) & ADMIN_USER) ? g_playerTag : g_adminTag, name)
    case 1:
      client_print(0,print_chat,"%s: cancel vote", (get_user_flags(id) & ADMIN_USER) ? g_playerTag : g_adminTag)
    } 

    console_print(id, "Voting canceled" )
    client_print(0,print_chat,"Voting canceled")

    remove_task( 99889988, 1 )

    set_cvar_float( "amx_last_voting" , get_gametime() )
  }
  else
    console_print(id, _T("There is no voting to cancel or the vote session can't be canceled with that command") ) 

  return PLUGIN_HANDLED
}

    
public delayedExec(cmd[]) 
{
    server_cmd(cmd)
    //client_print(0,print_chat,"debug: got here with %s",cmd)
}
  
new g_resultRef[] = "Result refused"
new g_resultAcpt[] = "Result accepted"
new g_votingFailed[] = "Voting failed" 
new g_votingSuccess[] = "Voting successful"

public autoRefuse(){ 
  log_to_file(g_logFile,"Vote: %s" , g_resultRef)
  client_print(0,print_chat,_T(g_resultRef) )
}

public actionResult(id,key) { 

  remove_task( 4545454 )

  switch(key){
    case 0:{ 
      set_task(2.0,"delayedExec",0,g_Execute,g_execLen)
      log_to_file(g_logFile,"Vote: %s",g_resultAcpt) 
      client_print(0,print_chat,_T(g_resultAcpt) )
    }
    case 1:
      autoRefuse()
  }

  return PLUGIN_HANDLED
}

public checkVotes() { 

  new best = 0

  if ( !g_yesNoVote ) {
    for(new a = 0; a < 4; ++a)
      if (g_voteCount[a] > g_voteCount[best])
        best = a
  }

  new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3]
  new iRatio = votesNum ? floatround( g_voteRatio * float( votesNum ) ,floatround_ceil) : 1
  new iResult = g_voteCount[best]

 //client_print(0,print_chat,"Debug Iresult %d g_for %d g_against %d", iResult, g_for, g_against )

      if ( iResult <= g_against )
    {
        ++g_against
        client_print(0,print_chat,"There were %d objections, voting failed", g_against )
        g_against = 0
        //g_for = 0
         iResult = 0
    }

  if ( iResult <  iRatio ){
    if (g_yesNoVote)
      client_print(0,print_chat,_T("%s (yes ^"%d^") (no ^"%d^") (needed ^"%d^")"),_T(g_votingFailed), g_voteCount[0], g_voteCount[1] , iRatio )
    else
      client_print(0,print_chat,_T("%s (got ^"%d^") (needed ^"%d^")"),_T(g_votingFailed), iResult , iRatio ) 

    return PLUGIN_CONTINUE
  }


  g_execLen = format(g_Execute,255,g_Answer,g_optionName[best]) + 1

  if (g_execResult) { 
      if ( is_user_connected(g_voteCaller) ) {
        g_execResult = false
        set_task(2.0,"delayedExec",0,g_Execute,g_execLen)
    }

  }

  client_print(0,print_chat,_T("%s (got ^"%d^") (needed ^"%d^"). The result: %s"), _T(g_votingSuccess), iResult , iRatio , g_Execute )

    g_votedFromChat = 0

  return PLUGIN_CONTINUE
}  // End Public Checkvotes

public voteCount(id,key){
  if ( get_cvar_num("amx_vote_answers") ) {  
    new name[32]

    get_user_name(id,name,31)

    if (g_yesNoVote) 
    {
          client_print(0,print_chat,"%s voted %s",name,key ? _T("against") : _T("for") );
        //(1<<0)|(1<<1)|(1<<2)
        if ( key == 1 ) ++g_for
        if ( key == 2 ) ++g_against
    }
    else
    { 
         client_print(0,print_chat,"%s voted for option %d",name,key+1)
    }
  } 

  ++g_voteCount[key]

  return PLUGIN_HANDLED
} 

public cmdVote(id,level,cid) {

  if (!cmd_access(id,level,cid,4))  
    return PLUGIN_HANDLED

  new Float:voting = get_cvar_float("amx_last_voting")

  if (voting > get_gametime()) {  
    console_print(id, g_alredyVoting)
    if ( g_votedFromChat == 1 )  client_print(id,print_chat,g_alredyVoting)
    return PLUGIN_HANDLED
  } 

  if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime()) { 
    console_print(id, g_notAllowed )
    if ( g_votedFromChat == 1 ) client_print(id,print_chat,g_notAllowed)
    return PLUGIN_HANDLED
  }  

  new quest[48]

  read_argv(1,quest,47)

  if ((contain(quest,"sv_password")!=-1)||(contain(quest,"rcon_password")!=-1)||
    (contain(quest,"kick")!=-1)||(contain(quest,"addip")!=-1)||(contain(quest,"ban")!=-1)){  
    console_print(id,_T("Voting for that has been forbidden"))
    return PLUGIN_HANDLED
  }  

  read_argv(2,g_optionName[0],31)
  read_argv(3,g_optionName[1],31)
  
  new authid[32],name[32]

  get_user_authid(id,authid,31)
  get_user_name(id,name,31)

  log_to_file(g_logFile,"Vote: ^"%s<%d><%s><>^" vote custom (question ^"%s^") (option#1 ^"%s^") (option#2 ^"%s^")",name,get_user_userid(id),authid,quest,g_optionName[0],g_optionName[1])
 
  switch(get_cvar_num("amx_show_activity")) {
    case 2:
      client_print(0,print_chat,_T("%s %s: vote custom"),(get_user_flags(id) & ADMIN_USER) ? _T(g_playerTag) : _T(g_adminTag),name )
    case 1:
      client_print(0,print_chat,_T("%s: vote custom"),(get_user_flags(id) & ADMIN_USER) ? _T(g_playerTag) : _T(g_adminTag))
  }
   
  new menu_msg[256]
  new keys = (1<<0)|(1<<1)
  new players[32]
  new numplayers
  new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0

  get_players(players,numplayers,"c")
  
  for(numplayers--;numplayers>=0;numplayers--){
    format(menu_msg,255, g_cstrikeRunning ? _T("\yVote: %s\w^n^n1.  %s^n2.  %s", players[numplayers]) : _T("Vote: %s^n^n1.  %s^n2.  %s", players[numplayers]),quest,g_optionName[0],g_optionName[1])
    show_menu(players[numplayers],keys,menu_msg,floatround(vote_time),"Vote: ")
  }
   
  g_execResult = false

  set_cvar_float("amx_last_voting", get_gametime() + vote_time )

  g_voteRatio = get_cvar_float("amx_vote_ratio")

  format(g_Answer,127,"%s - %%s",quest)

  set_task(vote_time,"checkVotes" , 99889988 )    

  g_voteCaller = id

  console_print(id, _T(g_votingStarted) )

  g_voteCount ={ 0,0,0,0}

  g_yesNoVote = 0

  return PLUGIN_HANDLED
} 

public cmdVoteKickBan(id,level,cid) {

  if (!cmd_access(id,level,cid,2))  
    return PLUGIN_HANDLED

  new Float:voting = get_cvar_float("amx_last_voting")

  if (voting > get_gametime()){  
    console_print(id, g_alredyVoting)
    if ( g_votedFromChat == 1 )  client_print(id,print_chat,g_alredyVoting)
    return PLUGIN_HANDLED
  } 

  if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime()) { 
    console_print(id, g_notAllowed )
    if ( g_votedFromChat == 1 ) client_print(id,print_chat,g_notAllowed)
    return PLUGIN_HANDLED
  }     

  new cmd[32]
  read_argv(0,cmd,31)
  new voteban = equal(cmd,"amx_voteban")
  new arg[32]

    //g_votedFromChat = 1;
    //g_kickName = saytext

    if ( g_votedFromChat != 1 )
    {
        read_argv(1,arg,31)
    }

    if ( g_votedFromChat == 1 )
    {
        read_argv(3,arg,31)
    }

    g_votedFromChat = 0
  
  new player = cmd_target(id,arg,1)
  //console_print(id,"debug gotname: %s",arg)

  if (!player)
    return PLUGIN_HANDLED

  if (voteban && is_user_bot(player)) { 
    new imname[32]
    get_user_name(player,imname,31)
    console_print(id,_T("That action can't be performed on bot ^"%s^""),imname)
    return PLUGIN_HANDLED
  }
   
  new keys = (1<<0)|(1<<1)|(1<<2)
  new menu_msg[256]
  new players[32]
  new numplayers
  new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0

  get_user_name(player,arg,31)
  get_players(players,numplayers) 

  //for(numplayers--;numplayers>=0;numplayers--){
  //  format(menu_msg,255,"\y%s %s?\w^n^n1. Exit^n2. Yes^n3. No", players[numplayers]) : ("%s %s?^n^n1.  Yes^n2.  No", players[numplayers]),
  //    voteban ? _T("Ban", players[numplayers]) : _T("Kick", players[numplayers]), arg) 
  //  show_menu(players[numplayers],keys,menu_msg,floatround(vote_time),voteban?"Ban ":"Kick ")
  //}

  g_against = -1
    g_for = -1 //not used yet

  for(numplayers--;numplayers>=0;numplayers--){
    format(menu_msg,255,"^n^n ^n^n^n^nKick player %s?^n^n1.  Exit Menu^n2.  Yes^n3.  No", arg, players[numplayers])
    keys = (1<<0)|(1<<1)|(1<<2)
    g_yesNoVote = 1
    show_menu(players[numplayers],keys,menu_msg,floatround(vote_time),voteban?"Ban ":"Kick ")
  }
  g_yesNoVote = 1

  if (voteban)  
    get_user_authid(player,g_optionName[0],31)
  else
    numtostr(get_user_userid(player),g_optionName[0],31)

  new authid[32],name[32]
  get_user_authid(id,authid,31)
  get_user_name(id,name,31)
  log_to_file(g_logFile,"Vote: ^"%s<%d><%s><>^" vote %s (target ^"%s^")",name,get_user_userid(id),authid,voteban ? "ban" : "kick",arg)
   
  switch(get_cvar_num("amx_show_activity")) {
    case 2:
      client_print(0,print_chat,_T("%s %s: vote %s for %s"),(get_user_flags(id) & ADMIN_USER) ? _T(g_playerTag) : _T(g_adminTag),name,voteban ? "ban" : "kick",arg )
    case 1:
      client_print(0,print_chat,_T("%s: vote %s for %s"),(get_user_flags(id) & ADMIN_USER) ? _T(g_playerTag) : _T(g_adminTag),voteban ? "ban" : "kick",arg)
  }
   
  g_execResult = true

  set_cvar_float("amx_last_voting", get_gametime() + vote_time )

  g_voteRatio = get_cvar_float(voteban ? "amx_voteban_ratio" : "amx_votekick_ratio")

  g_Answer = voteban ? "banid 30.0 %s kick" : "kick #%s"

  set_task(vote_time,"checkVotes" , 99889988 )

  g_voteCaller = id

  console_print(id, _T(g_votingStarted) )  

  g_voteCount = {0,0,0,0}

  return PLUGIN_HANDLED
} 

public cmdChangeLevel() {
  //force all players to delay reconnect to prevent map crash
      for ( new iPlayer = 1; iPlayer <= g_maxplayers; iPlayer++ )
    {
        if ( is_user_connected(iPlayer) )
        {
            if(iPlayer == 1) continue 
            client_cmd(iPlayer," alias waiter1 ^"wait;wait;wait;wait;wait;wait;wait;wait;wait;wait^"");
            client_cmd(iPlayer, "wait")
            client_cmd(iPlayer, " alias tenwaiter ^"waiter1;waiter1;waiter1;waiter1;waiter1;waiter1;waiter1;waiter1;waiter1;waiter1^"");
            client_cmd(iPlayer, "wait")
            client_cmd(iPlayer, " alias delayrec ^"disconnect;toggleconsole;tenwaiter;tenwaiter;tenwaiter;tenwaiter;echo Reconnecting...;retry^"");
            client_cmd(iPlayer, "wait")
            //client_cmd(iPlayer, "echo DEBUG: ^"quote test^" XD");
            client_cmd(iPlayer, "clear;wait;echo MAPCHANGE: YOU WILL BE RECONNECTED SHORTLY... PLEASE WAIT!");
            client_cmd(iPlayer, "wait")
            client_cmd(iPlayer, "delayrec");
        }
    }
    new nextmap[32]
    read_argv(1, nextmap, 31)

    //message_begin(MSG_ALL, SVC_INTERMISSION)
    //message_end()
    
    //write next map to crashed.cfg, in case transition fails
    new recCommand[33];
    format(recCommand, 32, "map %s", nextmap);
    write_file("crashed.cfg",recCommand,0);
    server_cmd ("echo VOTEMAP: Wrote to crashed.cfg: %s", recCommand)
    
    //delay to give time for aliases to get to players
    g_passCommand = nextmap
    set_task(1.0, "secondphase")
}

//thothie
public secondphase() {

  //getting tired, nothing but hacks now :D
  //this seemed the only way to add a delay to changelevel safely and still pass string
  server_cmd("changelevel %s", g_passCommand)

}

//thothie
public displayAdjacent_console(id) {

  //I really shouldn't have to do this (hack)
  //but for the life of me I can't get a dynamic global string echo to chat or console
  new map[33];
  get_mapname(map, 32);

    new ultra_enabled = get_cvar_num("ms_votemap_type");
    
    if ( ultra_enabled == 0 )
    {
        if ( contain(map,"calruin2") > -1 ) { client_print(id, print_console, "Adjacent Areas: sfor"); }
        if ( contain(map,"challs") > -1 ) { client_print(id, print_console, "Adjacent Areas: sfor"); }
        if ( contain(map,"daragoth") > -1 ) { client_print(id, print_console, "Adjacent Areas: helena deralia mines"); }
        if ( contain(map,"deralia") > -1 ) { client_print(id, print_console, "Adjacent Areas: daragoth"); }
        //this is to deal with duplicate name
        if ( contain(map,"edana") > -1 ) { 
        if ( contain(map,"edanasewers") > -1 ) 
        { 
            client_print(id, print_console, "Adjacent Areas: edana"); 
        } 
            else 
        {
            client_print(id, print_console, "Adjacent Areas: thornlands edanasewers");
        }
        }
        if ( contain(map,"gatecity") > -1 ) { client_print(id, print_console, "Adjacent Areas: mscave"); }
        if ( contain(map,"goblintown") > -1 ) { client_print(id, print_console, "Adjacent Areas: mscave"); }
        if ( contain(map,"helena") > -1 ) { client_print(id, print_console, "Adjacent Areas: thornlands daragoth keledrosprelude2"); }
        if ( contain(map,"heras") > -1 ) { client_print(id, print_console, "Adjacent Areas: thornlands"); }
        if ( contain(map,"keledrosprelude2") > -1 ) { client_print(id, print_console, "Adjacent Areas: helena [bossmap]"); }
        if ( contain(map,"keledrosprelude2") > -1 ) { client_print(id, print_console, "Adjacent Areas: keledrosprelude2"); }
        if ( contain(map,"mines") > -1 ) { client_print(id, print_console, "Adjacent Areas: daragoth"); }
        if ( contain(map,"mscave") > -1 ) { client_print(id, print_console, "Adjacent Areas: gatecity goblintown thornlands"); }
        if ( contain(map,"sfor") > -1 ) { client_print(id, print_console, "Adjacent Areas: calruin2 [hiddenmap] thornlands"); }
        if ( contain(map,"thornlands") > -1 ) { client_print(id, print_console, "Adjacent Areas: heras helena sfor mscave edana"); }
    }
}

//thothie
public displayAdjacent_chat(id) {

  //I really shouldn't have to do this (hack)
  //but for the life of me I can't get a dynamic global string echo to chat or console
  new map[33];
  get_mapname(map, 32);

    new ultra_enabled = get_cvar_num("ms_votemap_type");
    if ( ultra_enabled == 0 )
    {

      if ( contain(map,"calruin2") > -1 ) { client_print(id, print_chat, "Adjacent Areas: sfor"); }
      if ( contain(map,"challs") > -1 ) { client_print(id, print_chat, "Adjacent Areas: sfor"); }
      if ( contain(map,"daragoth") > -1 ) { client_print(id, print_chat, "Adjacent Areas: helena deralia mines"); }
      if ( contain(map,"deralia") > -1 ) { client_print(id, print_chat, "Adjacent Areas: daragoth"); }
      //this is to deal with duplicate name
      if ( contain(map,"edana") > -1 ) { 
        if ( contain(map,"edanasewers") > -1 ) { 
            client_print(id, print_chat, "Adjacent Areas: edana"); 
        } else {
            client_print(id, print_chat, "Adjacent Areas: thornlands edanasewers");
          }
      }
      if ( contain(map,"gatecity") > -1 ) { client_print(id, print_chat, "Adjacent Areas: mscave"); }
      if ( contain(map,"goblintown") > -1 ) { client_print(id, print_chat, "Adjacent Areas: mscave"); }
      if ( contain(map,"helena") > -1 ) { client_print(id, print_chat, "Adjacent Areas: thornlands daragoth keledrosprelude2"); }
      if ( contain(map,"heras") > -1 ) { client_print(id, print_chat, "Adjacent Areas: thornlands"); }
      if ( contain(map,"keledrosprelude2") > -1 ) { client_print(id, print_chat, "Adjacent Areas: helena [bossmap]"); }
      if ( contain(map,"keledrosruins") > -1 ) { client_print(id, print_chat, "Adjacent Areas: keledrosprelude2"); }
      if ( contain(map,"mines") > -1 ) { client_print(id, print_chat, "Adjacent Areas: daragoth"); }
      if ( contain(map,"mscave") > -1 ) { client_print(id, print_chat, "Adjacent Areas: gatecity goblintown thornlands"); }
      if ( contain(map,"sfor") > -1 ) { client_print(id, print_chat, "Adjacent Areas: calruin2 [hiddenmap] thornlands"); }
      if ( contain(map,"thornlands") > -1 ) { client_print(id, print_chat, "Adjacent Areas: heras helena sfor mscave edana"); }
    }
}

//thothie
public listMaps(id) {

    if ( g_invalid_select == 1 )
    {
        g_invalid_select = 0
        return PLUGIN_HANDLED;
    }

  get_cvar_string ("custommaps",g_customMaps,1279)
  
  client_print(id, print_console, "Format is votemap [mapname], example: votemap edana");
  if ( g_votedFromChat == 1 ) client_print(id, print_chat, "Format is votemap [mapname], example: votemap edana");

    new ultra_enabled = get_cvar_num("ms_votemap_type");

    if ( ultra_enabled == 0 ) client_print(0,print_console,"[Votetype: Normal] You may vote for adjacent maps, root towns, and custom maps.");
    if ( ultra_enabled == VOTE_ULTRA ) client_print(0,print_console,"[Votetype: Ultra] You may vote for any map you can name, save boss and gauntlet maps.");
    if ( ultra_enabled == VOTE_RESTRICT ) client_print(0,print_console,"[Votetype: Restricted] You may only vote at transitions, root towns, and these custom maps:");

    if ( g_votedFromChat == 1 )
    {
        if ( ultra_enabled == 0 ) client_print(0,print_chat,"[Votetype: Normal] You may vote for adjacent maps, root towns, and custom maps.");
        if ( ultra_enabled == VOTE_ULTRA ) client_print(0,print_chat,"[Votetype: Ultra] You may vote for any map you can name, save boss and gauntlet maps.");
        if ( ultra_enabled == VOTE_RESTRICT ) client_print(0,print_chat,"[Votetype: Restricted] You may only vote at transitions, root towns, and these custom maps:");
    }
    
    if ( ultra_enabled == 0 )
    {
        //if ( g_votedFromChat == 1 ) client_print(id, print_chat, "You may vote for the following maps:");
        //client_print(id, print_console, "You may vote for the following maps:");
        displayAdjacent_console(id);
        if ( g_votedFromChat == 1 ) displayAdjacent_chat(id);
        client_print(id, print_console, "Root Towns: %s", g_rootTowns);
        if ( g_votedFromChat == 1 ) client_print(id, print_chat, "Root Towns: %s", g_rootTowns);
    }

    //parse custom maps into g_cmap_names
    new new_name[32];
    new cmap_counter = 0;
    new r = 0;
    copy(g_cmap_names[0],32,new_name);
    new bool:store_flag = false;
    for ( new i = 0; i < (strlen(g_customMaps)); i++ )
    {
        store_flag = true;
        if ( g_customMaps[i] == 32 ) store_flag = false;
        if ( g_customMaps[i] == 59 ) store_flag = false;
        if ( g_customMaps[i] == 44 ) store_flag = false;
        if ( g_customMaps[i] == 124 ) store_flag = false;
        //client_print(id, print_console, "debug: reading %s",g_customMaps[i]);
        if ( store_flag )
        {
            copy(g_cmap_names[cmap_counter][r],1,g_customMaps[i]);
            ++r;
        }
        if ( !store_flag || i == strlen(g_customMaps)-1 ) 
        {
            //client_print(id, print_console, "debug: WROTE %s of %d",g_cmap_names[cmap_counter],cmap_counter);
            ++cmap_counter;
            r = 0;
            copy(g_cmap_names[cmap_counter],32,new_name);
        }
    }

    if ( ultra_enabled != VOTE_RESTRICT )
    {
        //client_print(id, print_console, "Custom Maps (fast downloads):")
        //if ( g_votedFromChat == 1 ) client_print(id, print_chat, "Custom Maps (fast downloads):");
    }

    //parse g_cmap_names into cmap_string and echo to console
    new cmap_string[256];
    new cmap_clear[256];
    new maplen = 0;
    new header[] = "Custom Maps (fast downloads):"
    for ( new i = 0; i < cmap_counter; i++ ) //switch to r if cause error
    {
        maplen = strlen(g_cmap_names[i]);
        add(cmap_string,255,g_cmap_names[i]);
        add(cmap_string,255," ")
        //client_print(id, print_console, "debug: got %s map ( %d of %d len %d ) stringisnow: %s",g_cmap_names[i],i,cmap_counter,maplen,cmap_string);
        if ( strlen(cmap_string) > 60 || i == cmap_counter-1 )
        {
            client_print(id, print_console, "%s %s",header, cmap_string);
            if ( g_votedFromChat == 1 ) client_print(id, print_chat, "%s %s",header, cmap_string);
            add(header,1,cmap_clear)
            copy(cmap_string,256,cmap_clear);
        }
    }

    g_votedFromChat = 0
}

public cmdVoteMap(id,level,cid) {

  //Thothie - lots of minor edits in here

  g_against = -1
  g_for = -1 //not used yet

  get_cvar_string ("custommaps",g_customMaps,512)
  
  new Float:voting = get_cvar_float("amx_last_voting")

  if ( voting > get_gametime() ) {  
    console_print(id, _T(g_alredyVoting))
    if ( g_votedFromChat == 1 )  client_print(id,print_chat,g_alredyVoting)
    return PLUGIN_HANDLED
  } 

  if ( voting && voting + get_cvar_float("amx_vote_delay") > get_gametime() ) { 
    console_print(id, g_notAllowed )
    if ( g_votedFromChat == 1 ) client_print(id,print_chat,g_notAllowed)
    return PLUGIN_HANDLED
  }   

  new argc = read_argc()

    if ( argc < 2 )
    {
        listMaps(id);
        return PLUGIN_HANDLED;
    }

    if ( g_touched != 1 )
    {
        new Float:difference = get_gametime() - loadTime[0];
        if ( difference < NT_VOTE_DELAY )
        {
            console_print(id,"Map voting is not permitted 90 seconds after map change, except by transition.")
            client_print(id,print_chat,"Map voting is not permitted 90 seconds after map change, except by transition.")
            return PLUGIN_HANDLED
        }

    if (argc > 5)
    argc = 5

      g_validMaps = 0
      g_optionName[0][0] = g_optionName[1][0] = g_optionName[2][0] = g_optionName[3][0] = 0

      for(new i = 1; i < argc; ++i)
    { 
          read_argv(i,g_optionName[g_validMaps],31)
          if (is_map_valid(g_optionName[g_validMaps])) 
        {
            g_optionName[0]=g_optionName[g_validMaps]
              g_validMaps++;
          }
    } //next i

    if ( is_map_valid(g_optionName[0]) ) g_validMaps = 1;

    if ( is_map_valid(g_optionName[0]) == 0 )
    {
         g_validMaps = 0;
        //listMaps(id)
        
        if ( argc > 3 )
        {
            client_print(0,print_chat,"Map %s not found on server.",g_optionName[0]);
        }

        if ( argc <= 3 ) listMaps(id);
        
        return PLUGIN_HANDLED
    }

    //Thothie - Check for map legality
    new alias_calruin[] = "calruin"
    new alias_keledrosprelude[] = "keledrosprelude"
    new map_to_convert[32]
    copy(map_to_convert,31,g_optionName[0])
    if ( equali(map_to_convert,alias_calruin) ) copy(g_optionName[0],31,"calruin2")
    if ( equali(map_to_convert,alias_keledrosprelude) ) copy(g_optionName[0],31,"keledrosprelude2")
    if ( g_validMaps == 1 ) getLegalMaps( g_optionName[0] );

    if ( g_validMaps == 0 ) 
    {
        new ultra_enabled = get_cvar_num("ms_votemap_type");
        if ( ultra_enabled == 0 ) listMaps(id)
        return PLUGIN_HANDLED;
    }


  } //EndIf g_touched != 1

    if ( g_touched == 1 )
    {
        g_optionName[0] = g_touchmap[0]
        g_touched = 0
        //client_print(0,print_chat,"Debug Starting Vote for:%s",g_optionName[0]);
    }

  new menu_msg[256]
  new keys = 0
  new players[32]
  new numplayers
  new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0

  get_players(players,numplayers,"c")

  for(numplayers--;numplayers>=0;numplayers--){
    format(menu_msg,255,"^n^n ^n^n^n^nChange map to %s?^n^n1.  Exit Menu^n2.  Yes^n3.  No", g_optionName[0])
    keys = (1<<0)|(1<<1)|(1<<2)
    g_yesNoVote = 1
    show_menu(players[numplayers],keys,menu_msg,floatround(vote_time),"Change map to ")
  }
   
  new authid[32],name[32]

  g_execResult = true

  set_cvar_float("amx_last_voting", get_gametime() + vote_time )

  g_voteRatio = get_cvar_float("amx_votemap_ratio")

  g_Answer = "dochangelevel %s"

  set_task(vote_time,"checkVotes" , 99889988 )    

  g_voteCaller = id

  console_print(id, _T(g_votingStarted) )

  g_voteCount = { 0,0, 0,0 }

  return PLUGIN_HANDLED
} 

//thothie
public getLegalMaps( checkMap[] ) {

  //Hoping to have legal and custom maps read in by file later

  new map[33];
    new mapvalidator = is_map_valid(checkMap)
  get_mapname(map, 32);


    new ultra_enabled = get_cvar_num("ms_votemap_type");

    //if ( ultra_enabled == 0 ) client_print(0,print_chat,"[Votetype: Normal]");
    //if ( ultra_enabled == VOTE_ULTRA ) client_print(0,print_chat,"[Votetype: Ultra]");
    //if ( ultra_enabled == VOTE_RESTRICT ) client_print(0,print_chat,"[Votetype: Restricted]");

    g_adjacentMaps = "none known";
    if ( contain(map,"calruin2") > -1 ) { g_adjacentMaps = "sfor"; }
    if ( contain(map,"challs") > -1 ) { g_adjacentMaps = "sfor"; }
    if ( contain(map,"daragoth") > -1 ) { g_adjacentMaps = "helena deralia mines"; }
    if ( contain(map,"deralia") > -1 ) { g_adjacentMaps = "daragoth"; }
    //this is to deal with duplicate name
    if ( contain(map,"edana") > -1 ) { 
    if ( contain(map,"edanasewers") > -1 ) { 
        g_adjacentMaps = "edana"; 
    } 
    else
    {
        g_adjacentMaps = "thornlands edanasewers";
    }
    }
    if ( contain(map,"gatecity") > -1 ) { g_adjacentMaps = "mscave"; }
    if ( contain(map,"goblintown") > -1 ) { g_adjacentMaps = "mscave"; }
    if ( contain(map,"helena") > -1 ) { g_adjacentMaps = "thornlands daragoth keledrosprelude2"; }
    if ( contain(map,"heras") > -1 ) { g_adjacentMaps = "thornlands"; }
    if ( contain(map,"keledrosprelude2") > -1 ) { g_adjacentMaps = "helena [bossmap]"; }
    if ( contain(map,"keledrosruins") > -1 ) { g_adjacentMaps = "keledrosprelude2"; }
    if ( contain(map,"mines") > -1 ) { g_adjacentMaps = "daragoth"; }
    if ( contain(map,"mscave") > -1 ) { g_adjacentMaps = "gatecity goblintown thornlands"; }
    if ( contain(map,"sfor") > -1 ) { g_adjacentMaps = "calruin2 [hiddenmap] thornlands"; }
    if ( contain(map,"thornlands") > -1 ) { g_adjacentMaps = "heras helena sfor mscave edana"; }

    if ( ultra_enabled == VOTE_RESTRICT ) g_adjacentMaps = "";

    g_validMaps = 0;

    new bool:MapIsCustom = false;
    if ( contain(g_adjacentMaps, checkMap) > -1 ) 
    {
        client_print(0,print_console,"debug: Found %s in adjacent maps", checkMap);
        g_validMaps = 1;
    }
    if ( contain(g_rootTowns, checkMap) > -1 )
    {
        client_print(0,print_console,"debug: Found %s in root towns", checkMap);
        g_validMaps = 1;
    }
    if ( SearchCustom(checkMap) )
    {
        client_print(0,print_console,"debug: Found %s in custom maps: %s", checkMap, g_customMaps);
        MapIsCustom = true;
        g_validMaps = 1;
    }

    new bool:IsBossMap = false;
    if ( contain(checkMap,"ww2") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"ww3") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"highlands") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"lostcastle") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"skycastle") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"orcplace") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"old_helena") > -1 ) IsBossMap = true;
    if ( contain(checkMap,"keledrosruins") > -1 ) IsBossMap = true;
    if ( IsBossMap ) 
    {
        g_validMaps = 0;
        client_print(0,print_chat,"You may only vote for boss and gauntlet maps from transitions.");
        g_invalid_select = 1;
    }


    if ( is_map_valid(checkMap) != 1 ) 
    {
        client_print(0,print_chat,"Map %s found on server.",checkMap);
        g_invalid_select = 1;
    }

    new this_map[256];
    new req_map[256];
    new comp_results = 0;
    get_mapname(this_map,255);
    copy(req_map,strlen(checkMap),checkMap);
    //client_print(0,print_console,"debug: this_map %s req_map %s checkMap %s",this_map,req_map,checkMap);
    if ( equali(this_map,req_map) )
    {
        client_print(0,print_console,"You cannot vote for a map you are already on.");
        client_print(0,print_chat,"You cannot vote for a map you are already on.");
        g_invalid_select = 1;
    }
    if ( strlen(checkMap) < 2 )
    {
        client_print(0,print_console,"No map name provided");
        g_validMaps = 0;
        g_invalid_select = 1;
        mapvalidator = 0;
        
    }
    if ( g_validMaps == 0 )
    {
        if ( mapvalidator == 1 ) 
        {
            if ( g_invalid_select == 0 )
            {
                if ( ultra_enabled == 0 )
                {
                    if ( !MapIsCustom || !IsBossMap ) client_print(0,print_chat,"[Votetype: Normal] You may only vote for %s from an adjoining map.",checkMap);
                    if ( MapIsCustom ) client_print(0,print_chat,"[Votetype: Normal] You may only vote for %s from a transition.",checkMap);
                }
                if ( ultra_enabled == VOTE_RESTRICT ) client_print(0,print_chat,"[Votetype: Restricted] You may only vote for %s at a transition.",checkMap);
            }
        }
        g_invalid_select = 1;
    }


    //client_print(0,print_console,"debug: ms_votemap_type returned %d for [%s] exist %d invalid %d g_valid %d",ultra_enabled,checkMap,mapvalidator,g_invalid_select,g_validMaps);


  //set_cvar_string ("adjacentmaps",g_adjacentMaps); - this wont work either

}

//thothie
public vote_check(id,level,cid) {

  //read in command 
  new saytext[64];  
  read_args(saytext,63);  
  //server_cmd ("say Debug: A Player Said %s", saytext);

  if ( contain(saytext,"Votemap") > -1 ) { 
    g_votedFromChat = 1;
    cmdVoteMap(id,level,cid);
  }

  if ( contain(saytext,"VOTEMAP") > -1 ) { 
    g_votedFromChat = 1;
    cmdVoteMap(id,level,cid);
  }


  if ( contain(saytext,"votemap") > -1 ) { 
    g_votedFromChat = 1;
    cmdVoteMap(id,level,cid);
  }

  if ( contain(saytext,"votekick") > -1 ) { 
    g_votedFromChat = 1;
    cmdVoteKickBan(id,level,cid);
  }

  if ( contain(saytext,"votepvp") > -1 ) { 
    g_votedFromChat = 1;
    cmdVotePVP(id,level,cid);
  }
}

public alertmessage(atype, message[])
{


    if ( containi(message,"force_map_") > -1 )
    {
        new sstart = containi(message,"force_map_") + 10;
        new empty[32];
        g_touchmap[0] = empty;
        for ( new i = sstart; i < (strlen(message) -2); i++ )
        {
            g_touchmap[0][i - sstart] = message[i];
        }
        client_print(0,print_chat,"Forcing map change to: %s",g_touchmap)
        client_print(0,print_console,"Forcing map change to: %s",g_touchmap)
        //client_print(0,print_chat,"Forcing map change to: %s",g_touchmap)
        //client_print(0,print_console,"Forcing map change to: %s",g_touchmap)
        //cmdChangeLevel(g_touchmap)

        g_Answer = "dochangelevel %s";
        g_execLen = format(g_Execute,255,g_Answer,g_touchmap) + 1;
        set_task(0.1,"delayedExec",0,g_Execute,g_execLen);

        return PLUGIN_HANDLED;
    }

    if ( containi(message,"player_died") > -1 ) g_lastplayerdied[0] = get_gametime();

    if ( containi(message,"game_playerspawn") > -1 ) g_lastplayerdied[0] = get_gametime();

    new Float:pdifference = get_gametime() - g_lastplayerdied[0];
    if ( pdifference < PLAYER_DIED_DELAY ) return PLUGIN_HANDLED;

    new Float:difference = get_gametime() - loadTime[0];
    if ( difference > TOUCH_DELAY )
    {
        if ( containi(message,"touch_trans_") > -1 )
        {
            new sstart = containi(message,"touch_trans_") + 12;
            new empty[32];
            new para_invalid[0] = ")"
            g_touchmap[0] = empty;
            for ( new i = sstart; i <= (strlen(message) -2); i++ )
            {
                if ( message[i] != para_invalid[0] ) g_touchmap[0][i - sstart] = message[i];
            }
            client_print(0,print_chat,"votemap:%s",g_touchmap);
            g_touched = 1;
            cmdVoteMap(1,1,1);
        }
    }
}

public cmdVotePVP(id,level,cid) {

  new Float:voting = get_cvar_float("amx_last_voting")

  if (voting > get_gametime()){  
    console_print(id, g_alredyVoting)
    if ( g_votedFromChat == 1 )  client_print(id,print_chat,g_alredyVoting)
    return PLUGIN_HANDLED
  } 

  if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime()) { 
    console_print(id, g_notAllowed )
    if ( g_votedFromChat == 1 ) client_print(id,print_chat,g_notAllowed)
    return PLUGIN_HANDLED
  }     

  new Float:PVPvote_enabled = get_cvar_float("amx_allow_pvp_vote")

    if ( PVPvote_enabled < 1 )
    {
        console_print(id,"PvP Votes are disabled on this server.")
        if ( g_votedFromChat == 1 ) client_print(id,print_chat,"PvP Votes are disabled on this server.")
        return PLUGIN_HANDLED
    }

  new keys = 0
  new menu_msg[256]
  new players[32]
  new numplayers
  new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
  new Float:pvp_mode = get_cvar_float("ms_pklevel") + 0.0

  get_players(players,numplayers,"c")

  g_against = -1
    g_for = -1 //not used yet

    g_yesNoVote = 1

    if ( pvp_mode <= 0 )
    {
        //client_print(0,print_chat,"ENABLEVOTE:debug %d",pvp_mode)
        for(numplayers--;numplayers>=0;numplayers--){
            format(menu_msg,255,"^n^n ^n^n^n^nEnable PVP on next map %s?^n^n1.  Exit Menu^n2.  Yes^n3.  No", numplayers)
            keys = (1<<0)|(1<<1)|(1<<2)
            g_yesNoVote = 1
            show_menu(players[numplayers],keys,menu_msg,floatround(vote_time),"Change map to ")
        }
        g_Answer = "ms_pklevel 1"
    }

    if ( pvp_mode >= 1 )
    {
        //client_print(0,print_chat,"DISABLEVOTE:debug %d",pvp_mode)
        for(numplayers--;numplayers>=0;numplayers--)
        {
            format(menu_msg,255,"^n^n ^n^n^n^nDisable PVP on next map %s?^n^n1.  Exit Menu^n2.  Yes^n3.  No", players[numplayers])
            keys = (1<<0)|(1<<1)|(1<<2)
            g_yesNoVote = 1
            show_menu(players[numplayers],keys,menu_msg,floatround(vote_time),"Change map to ")
        }
        g_Answer = "ms_pklevel 0"
    }

  
    new authid[32],name[32]
    
    g_execResult = true
    
    set_cvar_float("amx_last_voting", get_gametime() + vote_time )
    
    g_voteRatio = get_cvar_float("amx_votemap_ratio")
    
    //g_Answer = "dochangelevel %s"
    
    set_task(vote_time,"checkVotes" , 99889988 )    
    
    g_voteCaller = id
    
    console_print(id, _T(g_votingStarted) )
    
    g_voteCount = { 0,0, 0,0 }
    
    return PLUGIN_HANDLED
} 


public clear_crap() {

    new menu_msg[256];
    new players[32];
    new numplayers;
    new keys = (1<<0)|(1<<1);
    get_players(players,numplayers,"c");

    for(numplayers--;numplayers>=0;numplayers--)
    {
        format(menu_msg,255," ", players[numplayers])
        show_menu(players[numplayers],keys,menu_msg,0.1,"nadda ")
    }
}


public SearchCustom(search_map[])
{
    //parse custom maps into g_cmap_names
    new new_name[32];
    new cmap_counter = 0;
    new r = 0;
    copy(g_cmap_names[0],32,new_name);
    new bool:store_flag = false;
    for ( new i = 0; i < (strlen(g_customMaps)); i++ )
    {
        store_flag = true;
        if ( g_customMaps[i] == 32 ) store_flag = false;
        if ( g_customMaps[i] == 59 ) store_flag = false;
        if ( g_customMaps[i] == 44 ) store_flag = false;
        if ( g_customMaps[i] == 124 ) store_flag = false;
        //client_print(id, print_console, "debug: reading %s",g_customMaps[i]);
        if ( store_flag )
        {
            copy(g_cmap_names[cmap_counter][r],1,g_customMaps[i]);
            ++r;
        }
        if ( !store_flag || i == strlen(g_customMaps)-1 ) 
        {
            //client_print(id, print_console, "debug: WROTE %s of %d",g_cmap_names[cmap_counter],cmap_counter);
            if ( equali(search_map,g_cmap_names[cmap_counter]) ) return true;
            ++cmap_counter;
            r = 0;
            copy(g_cmap_names[cmap_counter],32,new_name);
        }
    }
}
Could someone help me and tell me what I need to do to get the votemap to work please? Is it possible that I can create a new amxx file with the voting system and not worry about the adminvote?
daffy4jr is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode