Post by ShaunCraft15 on Dec 14, 2022 12:57:38 GMT
Hello Guys someone can fix a problem in gamemode manager by lord death i rewrite it but i have problem in participation doesn't work can someone fix
Here Code:
/*-----------------------------------------------------------------------------------------------------
[ZP50] Addon: Gamemode Manager
- Credits:
* Lord Death: For The Original plugin
* ShaunCraft: For Rewriting And Some BugFixes
- Plugin Information:
* This Plugin Made For Manage The Gamemodes By Admin Vote
Sorry For bad english!!!
Enjoy With This Plugin :)
------------------------------------------------------------------------------------------------------*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <zp50_gamemodes>
#include <zp50_colorchat>
// Tasks
#define TASK_ID 2020
#define MODE_TASK 2021
new g_countdown, g_countdown_sound
new const g_iSoundCount[][]=
{
"fvox/one.wav",
"fvox/two.wav",
"fvox/three.wav",
"fvox/four.wav",
"fvox/five.wav",
"fvox/six.wav",
"fvox/seven.wav",
"fvox/eight.wav",
"fvox/nine.wav",
"fvox/ten.wav"
}
// Cvars
new cvar_random_mode_access, cvar_maxrounds_random
// GameModes
new Infection_Mode, Multi_Mode, Nemesis_Mode, Survivor_Mode, Plague_Mode
new Swarm_Mode, Armageddon_Mode
new g_VoteMenuTitle[256], g_AdminName[32], g_GamemodeName[64], g_SelectedName[32] ,g_SelectedMode
new gParticipateText[128]
// Admin Voting Variables
new gVoteIn[33], gVoteOut[33], gAlreadyVoted[33], iParticipating[33], iTotalParticipations, SelectedPlayer
new gVoteYes[64], gVoteNo[64], gYesCount, gNoCount, gVoteOnGoing, gSpecialRound
new gNextRoundShouldBe, OldMode, iRandom, iPlayers
new iCount = 11; /* For The Countdown (Hud Message) */
new Trie:g_tAuthIdBlackList
new AuthID[ 35 ]
new vMenu
#define PLUGIN "[ZP50] Gamemode Manager"
#define VERSION "1.0"
#define AUTHOR "Lord Death. || ShaunCraft"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_tAuthIdBlackList = TrieCreate()
register_clcmd("say /votemode", "Pre_AdminSelectMode")
register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
cvar_random_mode_access = register_cvar("zp_gm_manager_random_gm_players", "16")
cvar_maxrounds_random = register_cvar("zp_gm_manager_random_gm_after", "3")
}
public plugin_cfg()
{
Nemesis_Mode = zp_gamemodes_get_id("Nemesis Mode")
Survivor_Mode = zp_gamemodes_get_id("Survivor Mode")
Armageddon_Mode = zp_gamemodes_get_id("Armageddon Mode")
Swarm_Mode = zp_gamemodes_get_id("Swarm Mode")
Plague_Mode = zp_gamemodes_get_id("Plague Mode")
Multi_Mode = zp_gamemodes_get_id("Multiple Infection Mode")
Infection_Mode = zp_gamemodes_get_id("Infection Mode")
}
public plugin_precache()
{
new i
for( i = 0; i < sizeof g_iSoundCount;i++) engfunc(EngFunc_PrecacheSound, g_iSoundCount[i])
}
public Pre_AdminSelectMode(id)
{
zp_gamemodes_get_name(g_SelectedMode, g_GamemodeName, charsmax(g_GamemodeName))
new get_cm = zp_gamemodes_get_current()
// Admin Flag
if(get_user_flags(id) & ADMIN_KICK)
{
if(!gSpecialRound)
{
if(!gVoteOnGoing)
{
if(get_cm == Multi_Mode || get_cm == Infection_Mode)
{
AdminSelectMode(id)
}
else zp_colored_print(id, "You can only vote for a special round during an infecton round")
}
else zp_colored_print(id, "Please wait till the current vote ends")
}
else zp_colored_print(id, "Next round is voted to be %s. please try again later", g_GamemodeName)
}
else zp_colored_print(id, "Special Round Votes can be only started by admins and above")
}
public FormatText(id)
{
get_user_name(id, g_AdminName, charsmax(g_AdminName))
zp_gamemodes_get_name(g_SelectedMode, g_GamemodeName, charsmax(g_GamemodeName))
format(g_VoteMenuTitle, charsmax(g_VoteMenuTitle), "\wAdmin \y%s \whas started a vote for \y%s\w^n^n", g_AdminName, g_GamemodeName)
}
public FormatPreText(id)
{
gVoteOnGoing = 1
FormatText(id) //Let's format the vote text
new iPlayer
for (iPlayer = 1; iPlayer <= get_maxplayers(); iPlayer++)
{
if(is_user_connected(iPlayer))
{
gVoteIn[iPlayer] = 0
gVoteOut[iPlayer] = 0
gAlreadyVoted[iPlayer] = 0
iParticipating[iPlayer] = 0
AdminVoteMenu(iPlayer)
}
}
set_task(15.0,"EndVote", TASK_ID)
}
public client_disconnect(id)
{
if(iParticipating[id])
{
iParticipating[id] = 0
iTotalParticipations--
}
}
public AdminSelectMode(id)
{
new Menu = menu_create("\ySelect \wa \rMode", "SelectedMode")
menu_additem(Menu, "Survivor Mode", "", 0)
menu_additem(Menu, "Nemesis Mode", "", 0)
menu_additem(Menu, "Armageddon Mode", "", 0)
menu_additem(Menu, "Swarm Mode", "", 0)
menu_additem(Menu, "Plague Mode", "", 0)
menu_setprop( Menu, MPROP_EXIT, MEXIT_ALL );
menu_display( id, Menu, 0 );
}
public SelectedMode(id, menu, item)
{
switch( item )
{
case 0:
{
g_SelectedMode = Survivor_Mode
FormatPreText(id)
}
case 1:
{
g_SelectedMode = Nemesis_Mode
FormatPreText(id)
}
case 2:
{
g_SelectedMode = Armageddon_Mode
FormatPreText(id)
}
case 3:
{
g_SelectedMode = Swarm_Mode
FormatPreText(id)
}
case 4:
{
g_SelectedMode = Plague_Mode
FormatPreText(id)
}
}
}
public AdminVoteMenu(id)
{
FormatVote(id)
vMenu = menu_create(g_VoteMenuTitle, "VoteHandler")
menu_additem(vMenu, gVoteYes, "", 0)
menu_additem(vMenu, gVoteNo, "", 0)
if(g_SelectedMode == Nemesis_Mode || g_SelectedMode == Survivor_Mode) menu_additem(vMenu, gParticipateText, "", 0)
menu_additem(vMenu, "Refresh", "", 0)
menu_setprop( vMenu, MPROP_EXIT, MEXIT_ALL );
if(gVoteOnGoing) menu_display( id, vMenu, 0 );
}
public FormatVote(id)
{
if(!gVoteIn[id] && !gVoteOut[id])
{
format(gVoteYes, charsmax(gVoteYes), "Yes \y[%d]^n", gYesCount)
format(gVoteNo, charsmax(gVoteNo), "No \y[%d]^n", gNoCount)
}
if(gVoteIn[id])
{
format(gVoteYes, charsmax(gVoteYes), "Yes \y[%d] \r(Selected)^n", gYesCount)
format(gVoteNo, charsmax(gVoteNo), "No \y[%d]^n", gNoCount)
}
if(gVoteOut[id])
{
format(gVoteYes, charsmax(gVoteYes), "Yes \y[%d]^n", gYesCount)
format(gVoteNo, charsmax(gVoteNo), "No \y[%d] \r(Selected)^n", gNoCount)
}
if( !TrieKeyExists( g_tAuthIdBlackList, AuthID ) )
{
if(!iParticipating[id])
format(gParticipateText, charsmax(gParticipateText), "Play as the \r%s Special \y[NO]\r^n^n\rCurrentlly \y%d Players \rparticipating^n", g_GamemodeName, iTotalParticipations)
else
format(gParticipateText, charsmax(gParticipateText), "Play as the \y%s Special \r[YES]\r^n^n\rCurrentlly \y%d Players \rparticipating^n", g_GamemodeName, iTotalParticipations)
}
else
format(gParticipateText, charsmax(gParticipateText), "\dPlay as the %s Special \y[NEXT MAP]\r^n^n\rCurrentlly \y%d Players \rparticipating^n", g_GamemodeName, iTotalParticipations)
}
public zp_fw_gamemodes_end()
{
if(gVoteOnGoing == 1)
{
EndVote()
if(task_exists(TASK_ID)) remove_task(TASK_ID)
}
gVoteOnGoing = 0
}
public EndVote()
{
menu_destroy(vMenu)
if(gYesCount > gNoCount * 2)
{
zp_colored_print(0, "Vote success with ^04%d^03 votes for ^04Yes", gYesCount)
zp_colored_print(0, "Next round is ^04%s", g_GamemodeName)
gSpecialRound = 1
gNextRoundShouldBe = 0
}
else
{
zp_colored_print(0, "Vote failed with ^04%d^03 votes for ^04No", gNoCount)
gSpecialRound = 0
}
gYesCount = 0
gNoCount = 0
gVoteOnGoing = 0
iTotalParticipations = 0
}
public VoteHandler(id, menu, item)
{
switch(item)
{
case 0:
{
if(gVoteOnGoing)
{
if(!gAlreadyVoted[id])
{
gYesCount++
gVoteIn[id] = 1
gAlreadyVoted[id] = 1
}
if(gVoteOnGoing) AdminVoteMenu(id)
}
else
{
if(gVoteOut[id])
{
gYesCount++
gNoCount--
gVoteOut[id] = 0
gVoteIn[id] = 1
}
if(gVoteOnGoing) AdminVoteMenu(id)
}
}
case 1:
{
if(gVoteOnGoing)
{
if(!gAlreadyVoted[id])
{
gNoCount++
gVoteOut[id] = 1
gAlreadyVoted[id] = 1
}
AdminVoteMenu(id)
}
else
{
if(gVoteIn[id])
{
gYesCount--
gNoCount++
gVoteOut[id] = 1
gVoteIn[id] = 0
}
if(gVoteOnGoing) AdminVoteMenu(id)
}
}
case 2:
{
get_user_authid(id, AuthID, charsmax(AuthID))
if( !TrieKeyExists( g_tAuthIdBlackList, AuthID ) )
{
if(iParticipating[id] == 0)
{
iParticipating[id] = 1
zp_colored_print(id, "You are now participating as a ^4special")
iTotalParticipations++
AdminVoteMenu(id)
}
else
{
iParticipating[id] = 0
zp_colored_print(id, "You are no longer participating as a ^4special")
iTotalParticipations--
AdminVoteMenu(id)
}
}
else
{
zp_colored_print(id, "You've been selected as a ^04special^03 once. Try again later")
AdminVoteMenu(id)
}
}
case 3: AdminVoteMenu(id)
}
}
public StartMode()
{
if(SelectedPlayer != 0)
{
if(is_user_alive(SelectedPlayer))
{
get_user_name(SelectedPlayer, g_SelectedName, charsmax(g_SelectedName))
get_user_authid(SelectedPlayer, AuthID, charsmax(AuthID))
zp_gamemodes_start(g_SelectedMode, SelectedPlayer)
TrieSetCell( g_tAuthIdBlackList, AuthID, 1 )
zp_colored_print(0, "Player: ^4%s^3 is selected as a ^4special!", g_SelectedName)
}
}
else zp_gamemodes_start(g_SelectedMode)
gSpecialRound = 0
g_SelectedMode = 0
gVoteOnGoing = 0
SelectedPlayer = 0
}
public SelectParticipator()
{
if(!iTotalParticipations) //No Participators = Skip
{
SelectedPlayer = 0
return false;
}
if(g_SelectedMode == Nemesis_Mode || g_SelectedMode == Survivor_Mode)
{
SelectedPlayer = random_num(1, GetPCount())
if(!is_user_connected(SelectedPlayer))
SelectParticipator()
if(iParticipating[SelectedPlayer] != 1)
SelectParticipator()
zp_colored_print(SelectedPlayer, "You've been selected as the special for this round! preare yourself")
}
return true;
}
public CountDown()
{
if(iCount > 1)
{
iCount--
zp_gamemodes_get_name(g_SelectedMode, g_GamemodeName, charsmax(g_GamemodeName))
set_hudmessage(255, 0, 0, -1.0, 0.28, 0, 1.0, 0.5, 0.2, 0.8, -1)
show_hudmessage(0, "=| %s starts in %d |=",g_GamemodeName, iCount)
set_task(1.0,"CountDown")
}
else iCount = 11;
}
public CountDown_Sound()
{
if(g_countdown >= 1)
{
set_task(1.0,"CountDown_Sound", 1444)
if(g_countdown <= 10)
{
PlaySoundToClients(g_iSoundCount[g_countdown_sound])
g_countdown_sound--
}
g_countdown--
}
}
public Event_NewRound()
{
if(task_exists(1444)) remove_task(1444)
g_countdown = 10
g_countdown_sound = 9
set_task(0.1, "CountDown_Sound")
set_task(0.1, "CountDown")
if(gSpecialRound)
{
zp_gamemodes_get_name(g_SelectedMode, g_GamemodeName, charsmax(g_GamemodeName))
zp_colored_print(0, "Starting ^04[%s]^03 Voted by ^04%s^03 in 10 Seconds", g_GamemodeName, g_AdminName)
SelectParticipator()
set_task(9.75, "StartMode", MODE_TASK)
}
else
{
if(gNextRoundShouldBe == get_pcvar_num(cvar_maxrounds_random))
{
iRandom = random(4)
if(iRandom == OldMode) iRandom = random(4)
else
{
switch(iRandom)
{
case 0: g_SelectedMode = Survivor_Mode
case 1: g_SelectedMode = Nemesis_Mode
case 2: g_SelectedMode = Swarm_Mode
case 3: g_SelectedMode = Plague_Mode
case 4: g_SelectedMode = Armageddon_Mode
}
zp_gamemodes_get_name(g_SelectedMode, g_GamemodeName, charsmax(g_GamemodeName))
zp_colored_print(0, "Starting ^04[%s]^03 in 10 Seconds ^04[Random Mode]^03", g_GamemodeName)
set_task(9.75, "StartMode", MODE_TASK)
gNextRoundShouldBe = 0
OldMode = iRandom
}
}
else
{
new Multi_Access = random(20)
if(Multi_Access == 8)
{
g_SelectedMode = Multi_Mode
}
else g_SelectedMode = Infection_Mode
new gMinusNextRound = get_pcvar_num(cvar_maxrounds_random) - gNextRoundShouldBe
if(GetPCount() >= get_pcvar_num(cvar_random_mode_access))
{
zp_colored_print(0, "^04[%d Rounds Left]^03 for a random mode", gMinusNextRound)
gNextRoundShouldBe++
}
zp_gamemodes_get_name(g_SelectedMode, g_GamemodeName, charsmax(g_GamemodeName))
zp_colored_print(0, "Starting ^04[%s]^03 in 10 Seconds", g_GamemodeName)
set_task(9.75, "StartMode", MODE_TASK)
}
}
}
stock GetPCount()
{
new id
for (id = 1; id <= get_maxplayers(); id++)
{
if(is_user_connected(id))
iPlayers++
}
return iPlayers;
}
stock PlaySoundToClients(const sound[])
{
if (equal(sound[strlen(sound)-4], ".mp3"))
client_cmd(0, "mp3 play ^"sound/%s^"", sound)
else
client_cmd(0, "spk ^"%s^"", sound)
}