[Cerere Plugin] Custom Votemap

Categoria cu cereri de pluginuri si nu numai.

Moderators: Moderatori ajutatori, Moderatori, Echipa eXtreamCS.com

Forum rules
Accesează link-ul pentru a putea vedea regulile forumului

Daca doriti sa vi se modifice un plugin, va rugam postati aici .
Post Reply
Mihuu.FREE
Membru, skill 0
Membru, skill 0
Posts: 68
Joined: 11 Aug 2019, 16:07
Detinator Steam: Da
CS Status: Pe Inferno cu băieții
Detinator server CS: FREE.LALEAGANE.RO
SteamID: PM.
Fond eXtream: 0
Has thanked: 2 times
Been thanked: 1 time

29 Nov 2021, 15:39

Plugin Cerut: Custom Votemap
Descriere (adica ce face el mai exact): Dă vot cu anumite hărți în funcție de numărul playerilor de pe server
Serverul impune conditii strict HLDS/REHLDS?: Nu
Ai cautat pluginul?(daca da, precizeaza cum): Da, l-am și găsit: modificari-pluginuri/modificare-mapchooser-t292126.html doar că primesc Error: Must be assigned to an array on line 204 în dreptul linie "pid = players"
Necesita mod special?: Nu
Configuratie server: Clasic
RoyalServer
User avatar
Mutex
Fost administrator
Fost administrator
Posts: 4726
Joined: 24 Mar 2011, 22:32
Detinator Steam: Da
Reputatie: Fost administrator
Location: Bucuresti
Discord: mutex21
Has thanked: 108 times
Been thanked: 167 times
Contact:

29 Nov 2021, 22:41

| Afiseaza codul
#include <amxmodx>

new const PLUGIN[] = "Mapchooser"
new const VERSION[] = "3.0"
new const AUTHOR[] = "Prayer/Safety1st"

new g_teamScore[2]

new nextmap, vote_answers, maxspeed
new mp_timelimit, mp_winlimit, mp_maxrounds, mp_roundtime
new extendmapmax_pcvar, extendmapstep_pcvar, votetime_pcvar, votemaps_pcvar
new result_red_pcvar, result_green_pcvar, result_blue_pcvar

#define TASK_PLUGIN_ID 44747477
#define TASK_SCREEN_ID 979699
#define TASK_RESULT_ID 12111

const HudLen = 512

new Array:g_mapName
new g_mapNums
new g_saveids[10]

new g_voteCount[10]
new g_nextName[10]
new g_lastMap[32]
new g_currentMap[32]
new g_mapVoteNum

new g_votemaps
new g_maxspeed = 320

new Float:f_timelimit = 0.0	// we want to restore timelimit only if we touched it

new bool:willbevote = false	// there will be a vote
new bool:voteStarted = false	// there is vote in progress
new bool:forceBlock = true	// block player's selections if vote is canceled
new bool:hasExtend = false	// map was extended
new bool:lastRound = false	// map changing will be at the current round end
new bool:forceChange = true	// we should force map end in case if it is not round-based limit coming soon

new bool:hasBlind[33] = { false, ... }
new g_msgScreenFade

new g_PlayersVoted = 0
new g_PlayersNum = 0

new
	g_result_red,
	g_result_green,
	g_result_blue

new const g_mape_mici[] = "mape_mici.ini"
new const g_mape_mari[] = "mape_mari.ini"

new delimiter

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_cvar("super_mapchooser",VERSION,FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
	register_dictionary("mapchooser.txt")
	
	extendmapmax_pcvar = register_cvar("amx_extendmap_max", "90")
	extendmapstep_pcvar = register_cvar("amx_extendmap_step", "15")
	register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
	register_event("TextMsg", "Event_RestartRound", "a", "2&#Game_C", "2&#Game_w")
	register_event("ScreenFade", "Event_ScreenFade", "be")
	register_event("TeamScore", "team_score", "a")
	register_logevent("Event_RoundEnd", 2, "0=World triggered","1=Round_End")
	
	votetime_pcvar = register_cvar("mapchooser_votetime", "15")
	votemaps_pcvar = register_cvar("mapchooser_votemaps", "5")
	
	result_red_pcvar = register_cvar("mapchooser_result_red", "0")
	result_green_pcvar = register_cvar("mapchooser_result_green", "255")
	result_blue_pcvar = register_cvar("mapchooser_result_blue", "100")

	delimiter = register_cvar("mapchooser_delimiter", "9")
	
	g_msgScreenFade = get_user_msgid("ScreenFade")
	
	set_task(8.0, "taskListening", TASK_PLUGIN_ID, "", 0, "b")
}

public plugin_cfg()
{
	nextmap = get_cvar_pointer("amx_nextmap")
	vote_answers = get_cvar_pointer("amx_vote_answers")
	maxspeed = get_cvar_pointer("sv_maxspeed")
	
	mp_timelimit = get_cvar_pointer("mp_timelimit")
	mp_winlimit = get_cvar_pointer("mp_winlimit")
	mp_maxrounds = get_cvar_pointer("mp_maxrounds")
	mp_roundtime = get_cvar_pointer("mp_roundtime")
	
	g_votemaps = get_pcvar_num(votemaps_pcvar)
	
	if(g_votemaps > 8)
		g_votemaps = 8
	else if(g_votemaps < 1)
		g_votemaps = 1
	
	register_menucmd(register_menuid("superMapChooserMenu"), (-1^(-1<<(g_votemaps + 1))), "countVote")
	
	g_mapName = ArrayCreate(32)
	
	get_localinfo("lastMap", g_lastMap, sizeof g_lastMap -1)
	set_localinfo("lastMap", "")
	
	new maps_ini_file[64]
	get_localinfo("amxx_configsdir", maps_ini_file, sizeof maps_ini_file -1)
	
	format(maps_ini_file, sizeof maps_ini_file -1, "%s/maps.ini", maps_ini_file)
	
	if(!file_exists(maps_ini_file))
		get_cvar_string("mapcyclefile", maps_ini_file, sizeof maps_ini_file -1)
	
	if(loadSettings(maps_ini_file))
		Reset()
	
	g_maxspeed = get_pcvar_num(maxspeed)
	get_mapname(g_currentMap, sizeof g_currentMap -1)
}

public client_disconnect(id)
{
	remove_task(id+TASK_SCREEN_ID)
	remove_task(id+TASK_RESULT_ID)
	
	hasBlind[id] = false
}

public Event_RestartRound()
	Reset()

public Event_RoundEnd()
{
	if(lastRound && forceChange)
		set_task(4.5,"ForceChangeMap")
}

public ForceChangeMap()
{
	// trick: decrease mp_timelimit value to force map change. 0.3 min was carefully chosen by experiments
	set_pcvar_float(mp_timelimit, get_gametime() / 60.0 - 0.3)
}

public Reset()
{
	g_PlayersVoted = 0
	g_PlayersNum = 0
	
	if(voteStarted)
	{
		voteStarted = false
		forceBlock = true
		remove_task(TASK_PLUGIN_ID)	// remove 'checkVotes' task
		
		if(!hasExtend)
		{
		chat_color(0, "%L", LANG_SERVER, "INTERRUPTED")
		}
		else hasExtend = false
	}
	
	if(willbevote)
	{
		set_task(8.0, "taskListening", TASK_PLUGIN_ID, "", 0, "b")
		
		if(f_timelimit > 0.0)
			set_pcvar_float(mp_timelimit, f_timelimit)
	}
	
	willbevote = false
	lastRound = false
	forceChange = true
}

public PauseGame()
{
	new players[32], pid;
	get_players(players, g_PlayersNum)
	for(new i=0;i<g_PlayersNum;i++)
	{
		pid = players
		hasBlind[pid] = true
		
		message_begin(MSG_ONE, g_msgScreenFade, _, pid)
		write_short(1<<12)	// Duration
		write_short(1<<9)	// Hold time
		write_short(1<<0)	// Fade type
		write_byte(0)		// Red
		write_byte(0)		// Green
		write_byte(0)		// Blue
		write_byte(255)		// Alpha
		message_end()
		
		set_task(1.0, "cmdFadeScreen", pid+TASK_SCREEN_ID, "", 0, "b")
	}
	
	set_pcvar_num(maxspeed, 0)
}

public ContinueGame()
{
	new players[32], num, pid
	get_players(players, num)
	for(new i=0;i<num;i++)
	{
		pid = players
		
		hasBlind[pid] = false
		
		remove_task(pid+TASK_SCREEN_ID)
		remove_task(pid+TASK_RESULT_ID)
		
		message_begin(MSG_ONE, g_msgScreenFade, _, pid)
		write_short(1<<0)
		write_short(1<<0)
		write_short(1<<0)
		write_byte(0)
		write_byte(0)
		write_byte(0)
		write_byte(0)
		message_end()
	}
	
	set_pcvar_num(maxspeed, g_maxspeed)
}

public taskListening()
{
	new winlimit = get_pcvar_num(mp_winlimit)
	
	if(winlimit)
	{
		new c = winlimit - 2
		if(!((c > g_teamScore[0]) && (c > g_teamScore[1])))
		{
			forceChange = false
			willbevote = true
		}
	}

	new maxrounds = get_pcvar_num(mp_maxrounds)
	
	if(maxrounds)
	{
		if(!((maxrounds - 2) > (g_teamScore[0] + g_teamScore[1])))
		{
			forceChange = false
			willbevote = true
		}
	}
	
	new Float:f_timeleft
	new Float:f_diff
	new Float:f_roundtime
	
	f_timeleft = float(get_timeleft())
	
	if (f_timeleft)
	{
		f_roundtime = get_pcvar_float(mp_roundtime) * 60.0
		f_diff = f_roundtime - f_timeleft + get_pcvar_float(votetime_pcvar) + 15.0
		// we need additional 10 seconds upper to don't get countdown voice
		
		if(!(f_timeleft < 1.0 || f_timeleft > f_diff))
			willbevote = true
	}
	
	if(!willbevote)
		return
	
	remove_task(TASK_PLUGIN_ID)	// remove 'taskListening' task
	
	chat_color(0, "%L", LANG_SERVER, "VOTE_NEXT_ROUND")
	
	// increase timelimit if it might elapse earlier than needed
	if (f_timeleft)
	{
		f_timelimit = get_pcvar_float(mp_timelimit)	// save current timelimit
		set_pcvar_float(mp_timelimit, f_timelimit + f_diff / 60.0)
	}
}

public Event_NewRound()
{
	if(willbevote && !lastRound)
	{
		forceBlock = false
		hasExtend = false
		
		g_result_red = get_pcvar_num(result_red_pcvar)
		g_result_green = get_pcvar_num(result_green_pcvar)
		g_result_blue = get_pcvar_num(result_blue_pcvar)
		
		cmdVoteNextmap()
	}
}

public cmdVoteNextmap()
{
	new file[64]
	get_localinfo("amxx_configsdir", file, sizeof file -1)

	if( get_playersnum() > get_pcvar_num(delimiter) )
	{
		format(file, sizeof file -1, "%s/%s", file, g_mape_mari)
		loadSettings(file)
	}
	else
	{
		format(file, sizeof file -1, "%s/%s", file, g_mape_mici)
		loadSettings(file)
	}

	new
		mkeys = ((1<<g_votemaps) + 1),
		menu[HudLen],
		a
	
	new pos = format(menu, HudLen -1, "     \r%L:^n^n", LANG_SERVER, "VOTE_TITLE")
	new dmax = (g_mapNums > g_votemaps) ? g_votemaps : g_mapNums
	
	new unki = 0
	
	for(g_mapVoteNum = 0; g_mapVoteNum < dmax; g_mapVoteNum++)
	{
		a = random_num(0, g_mapNums -1)
		
		while(isInMenu(a))
		{
			if(++a >= g_mapNums)
			{
				a = 0
			}
		}
		
		g_nextName[g_mapVoteNum] = a
		
		new map[32]
		ArrayGetString(g_mapName, a, map, sizeof map -1)
		
		pos += format(menu[pos], HudLen -1, "     \y%d.\w %s^n", g_mapVoteNum + 1, map)
		
		g_saveids[unki] = a
		unki++
		
		mkeys |= (1<<g_mapVoteNum)
		
		g_voteCount[g_mapVoteNum] = 0
	}
	
	g_voteCount[g_votemaps] = 0
	g_voteCount[g_votemaps + 1] = 0
	
	new winlimit = get_pcvar_num(mp_winlimit)
	new maxrounds = get_pcvar_num(mp_maxrounds)
	
	if((winlimit + maxrounds) == 0 && f_timelimit < get_pcvar_float(extendmapmax_pcvar))
	{
		pos += format(menu[pos], HudLen -1, "     \y%d.\w %s \y[%L]", g_votemaps + 1, g_currentMap, LANG_SERVER, "PROLONG")
		mkeys |= (1<<g_votemaps)
	}
	
	show_menu(0, mkeys, menu, get_pcvar_num(votetime_pcvar), "superMapChooserMenu")
	
	chat_color(0, "%L", LANG_SERVER, "VOTE_STARTED")
	
	client_cmd(0, "spk gman/gman_choose2")
	set_task(get_pcvar_float(votetime_pcvar), "checkVotes", TASK_PLUGIN_ID)
	
	PauseGame()
	
	voteStarted = true
	
	log_amx("Super Vote: Voting for the nextmap started")
}

public checkVotes()
{
	voteStarted = false
	
	new bolt = 0
	
	for(new a = 0; a < g_mapVoteNum; a++)
	{
		if(g_voteCount[bolt] < g_voteCount[a])
			bolt = a
	}
	
	//clear channel #2
	set_hudmessage(.channel=2)
	show_hudmessage(0, "")
	
	set_hudmessage(255, 127, 0, -1.0, 0.42, 2, 0.1, 10.0, 0.05, 1.0, 2)
	
	if((g_voteCount[g_votemaps] > g_voteCount[bolt]) && (g_voteCount[g_votemaps] > g_voteCount[g_votemaps + 1]))
	{	
		new Float:steptime = get_pcvar_float(extendmapstep_pcvar)
		f_timelimit = f_timelimit + steptime
		
		chat_color(0, "%L", LANG_SERVER, "MAP_EXTENDING", steptime)
		show_hudmessage(0, "%L", LANG_SERVER, "MAP_EXTENDING_HUD", steptime)
		
		log_amx("Super Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes", g_currentMap, steptime)
		
		hasExtend = true
		
		Reset()
		ContinueGame()
		
		return
	}
	
	new smap[32]
	
	if(g_voteCount[bolt] && (g_voteCount[g_votemaps + 1] <= g_voteCount[bolt]))
	{
		ArrayGetString(g_mapName, g_nextName[bolt], smap, sizeof smap -1)
		set_pcvar_string(nextmap, smap)
	}
	else get_pcvar_string(nextmap, smap, sizeof smap -1)	// get nextmap name in case if no one voted
	
	chat_color(0, "%L", LANG_SERVER, "NEXT_MAP_CHOSEN", smap)
	show_hudmessage(0, "%L", LANG_SERVER, "NEXT_MAP_CHOSEN_HUD", smap)
	
	if(forceChange)
	{
		chat_color(0, "%L", LANG_SERVER, "LAST_ROUND")
		set_hudmessage(255, 0, 0, -1.0, 0.58, 2, 0.1, 10.0, 0.05, 1.0, 1)
		show_hudmessage(0, "%L", LANG_SERVER, "LAST_ROUND_HUD")
	}
	
	new players[32], num, pid
	get_players(players, num)
	
	for(new i=0;i<num;i++)
	{
		pid = players
		remove_task(pid+TASK_RESULT_ID)
	}
	
	log_amx("Super Vote: Voting for the nextmap finished. The nextmap will be %s", smap)
	
	lastRound = true
	
	// increase timelimit if it might elapse earlier than current round
	new Float:f_timeleft = float(get_timeleft())
	if(f_timeleft)	// there is timelimit for map definately
		set_pcvar_float(mp_timelimit, get_gametime() / 60.0 + get_pcvar_float(mp_roundtime))
	
	ContinueGame()
}

public countVote(id, key)
{
	if(!voteStarted && forceBlock)
		return PLUGIN_HANDLED
	
	if(get_pcvar_float(vote_answers))
	{
		new name[32]
		get_user_name(id, name, sizeof name -1)
		
		if(key == g_votemaps)
		{
			chat_color(0, "%L", LANG_SERVER, "VOTED_EXTEND", name)
		}
		else if(key < g_votemaps)
		{
			new map[32]
			ArrayGetString(g_mapName, g_nextName[key], map, sizeof map -1)
			
			chat_color(0, "%L", LANG_SERVER, "VOTED", name, map)
		}
		
		cmdShowResults(id+TASK_RESULT_ID)
		set_task(0.8, "cmdShowResults", id+TASK_RESULT_ID, "", 0, "b")
	}
	
	client_cmd(id, "spk UI/buttonclickrelease")
	
	g_voteCount[key]++
	g_PlayersVoted++
	
	return PLUGIN_HANDLED
}

public cmdShowResults(pid)
{
	static id
	id = pid-TASK_RESULT_ID
	
	if(is_user_connected(id))
	{
		static i, len, message[HudLen]
		
		len = format(message, sizeof message -1, "%L^n^n", LANG_SERVER, "VOTE_RESULTS")
		
		for(i=0;i<g_votemaps;i++)
		{
			new map[32]
			ArrayGetString(g_mapName, g_saveids, map, sizeof map -1)
			len += format(message[len], HudLen -1, "[%d] | %s^n", g_voteCount, map)
		}
		
		len += format(message[len], HudLen -1, "[%d] | %s [%L]^n^n", g_voteCount, g_currentMap, LANG_SERVER, "PROLONGED")
		len += format(message[len], HudLen -1, "%L", LANG_SERVER, "VOTE_TOTAL", g_PlayersVoted, g_PlayersNum)
		
		set_hudmessage(g_result_red, g_result_green, g_result_blue, 0.36, 0.3, 0, 1.0, 4.0, 0.1, 0.2, 2)
		show_hudmessage(id, message)
	}
}

public Event_ScreenFade(id)
{
	if(hasBlind[id])
	{
		set_task(0.6, "cmdFadeScreen", id+TASK_SCREEN_ID)
	}
}

public cmdFadeScreen(pid)
{
	new id = pid-TASK_SCREEN_ID
	
	if(is_user_connected(id))
	{
		message_begin(MSG_ONE, g_msgScreenFade, _, id)
		write_short(1<<0)	// Duration
		write_short(1<<0)	// Hold time
		write_short(1<<2)	// Fade type
		write_byte(0)		// Red
		write_byte(0)		// Green
		write_byte(0)		// Blue
		write_byte(255)		// Alpha
		message_end()
	}
}

public plugin_end()
{
	new current_map[32]
	
	set_pcvar_num(maxspeed, g_maxspeed)
	
	get_mapname(current_map, sizeof current_map -1)
	set_localinfo("lastMap", current_map)
}

stock bool:ValidMap(mapname[])
{
	if(is_map_valid(mapname))
	{
		return true
	}
	
	new len = strlen(mapname) -4
	
	if(len < 0)
	{
		return false
	}
	
	if(equali(mapname[len], ".bsp"))
	{
		mapname[len] = '^0'
		
		if(is_map_valid(mapname))
		{
			return true
		}
	}
	
	return false
}

loadSettings(filename[])
{
	if(!file_exists(filename))
		return 0

	new
		currentMap[32],
		szText[32],
		buff[256]
	
	get_mapname(currentMap, sizeof currentMap -1)

	new fp = fopen(filename, "r")
	
	while(!feof(fp))
	{
		buff[0] = '^0'
		
		fgets(fp, buff, sizeof buff -1)
		
		parse(buff, szText, sizeof szText -1)
		
		if((szText[0] != ';') && ValidMap(szText) && !equali(szText, g_lastMap) && !equali(szText, currentMap))
		{
			ArrayPushString(g_mapName, szText)
			
			g_mapNums++
		}
	}
	
	fclose(fp)

	return g_mapNums
}

bool:isInMenu(id)
{
	for(new a = 0; a < g_mapVoteNum; a++)
	{
		if(id == g_nextName[a])
		{
			return true
		}
	}
	
	return false
}

//From the AMXX nextmap base file
public team_score()
{
	new team[2]
	read_data(1,team,1)
	g_teamScore[(team[0]=='C') ? 0 : 1] = read_data(2)
}
stock chat_color(const id, const input[], any:...)
{
   new count = 1, players[32]
   static msg[320]
   vformat(msg, 190, input, 3)
   replace_all(msg, 190, "!g", "^4")
   replace_all(msg, 190, "!n", "^1")
   replace_all(msg, 190, "!t", "^3")
   replace_all(msg, 190, "!t2", "^0")
   if (id) players[0] = id; else get_players(players, count, "ch")
   {
      for (new i = 0; i < count; i++)
      {
         if (is_user_connected(players))
         {
            message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players)
            write_byte(players)
            write_string(msg)
            message_end()
         }
      }
   }
}


Vezi daca merge.
Mihuu.FREE
Membru, skill 0
Membru, skill 0
Posts: 68
Joined: 11 Aug 2019, 16:07
Detinator Steam: Da
CS Status: Pe Inferno cu băieții
Detinator server CS: FREE.LALEAGANE.RO
SteamID: PM.
Fond eXtream: 0
Has thanked: 2 times
Been thanked: 1 time

29 Nov 2021, 22:50

Primesc aceeași eroare. Poate greșesc eu la compilare, dacă îl poți compila și îl poți pune aici, ar fi perfect.
Mulțumesc!
User avatar
Mutex
Fost administrator
Fost administrator
Posts: 4726
Joined: 24 Mar 2011, 22:32
Detinator Steam: Da
Reputatie: Fost administrator
Location: Bucuresti
Discord: mutex21
Has thanked: 108 times
Been thanked: 167 times
Contact:

29 Nov 2021, 23:02

Am copiat gresit. Check: https://pastebin.com/paFVzqak
Post Reply

Return to “Cereri”

  • Information