Raised This Month: $ Target: $400
 0% 

Help me edit this


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mazmaajinsh
Senior Member
Join Date: Apr 2005
Location: Latvia
Old 05-01-2011 , 15:28   Help me edit this
Reply With Quote #1

Hi guys. Could someone help me and edit it for me, so that this plugin not only shows a menu, but also prints in chat like this - 1. szName [ PlayerPos[i] ] , 2. szName - [ PlayerPos[i] ] and so on. Also, something is wrong with remove_task. After closing the menu, it still does open it up again and again.
Thanks guys ;)

Code:
public say_pos(id, level, cid)
{
	if(cmd_access(id, level, cid, 1))
	{
		new myteam = get_user_team(id)
		g_iMenuTeam[id] = ( myteam < 3 ) ? myteam : 1
		displaypos(id)
	}
	return PLUGIN_HANDLED
}

public displaypos(id)
{
	new msg[MENU_CHARS+1], len = 0
	new keys = 1023
	len += formatex(msg[len], MENU_CHARS-len, (g_iMenuTeam[id] == 1) ? "\yTerrorists\w^n^n" : "\yCounter-Terrorists\w^n^n")

	new i
	new iPlayerID[33], iPlayerPos[33]
	new myMenuTeam = g_iMenuTeam[id]
	
	for(i = 1; i <= MaxPlayers; i++)
	{
		if(is_user_alive(i))
		{
			iPlayerPos[i] = get_nearest_marker(i)
			iPlayerID[i] = i
		}
		else
		{
			iPlayerID[i] = 0
		}
	}
	
	insertion_sort2(iPlayerPos,iPlayerID,MaxPlayers+1)  // Sakartot pec pozicijas
	
	for(i = 0; i < MaxPlayers; i++)
	{
		if(iPlayerID[i])
		{
			new szName[32], iTeam
			
			get_user_name(iPlayerID[i], szName, 31)
			iTeam = get_user_team(iPlayerID[i])
			// CT = 2, T = 1
			if(myMenuTeam == iTeam)
			{
				len += formatex(msg[len], MENU_CHARS-len,"[\r%d\w] %s^n", iPlayerPos[i], szName)
			}
		}
	}
	
	len += formatex(msg[len], MENU_CHARS-len, (g_iMenuTeam[id] == 1) ? "^n1. Counter-Terrorists^n" : "^n1. Terrorists^n")
	len += formatex(msg[len], MENU_CHARS-len, "2. Exit")

	show_menu(id, keys, msg, -1, "Player positions")
	set_task(1.0, "displaypos", id)
}

public positions(id,key)
{
	switch(key)
	{
		case 0:
		{
			g_iMenuTeam[id] = ( g_iMenuTeam[id] == 1 ) ? 2 : 1
			displaypos(id)
		}
		default:
		{
			remove_task(id)
			return
		}
	}
}

public insertion_sort2(Array1[],Array2[], length)
{ // Sort Array1 and Array2 by Array1
	new temp1, temp2
	new j

	for(new i=1; i<length; i++){
		j = i-1
		temp1 = Array1[i]
		temp2 = Array2[i]
		while((j >= 0) && (temp1 > Array1[j])) // '>' is Descending, '<' is Ascending
		{
			Array1[j+1] = Array1[j]
			Array2[j+1] = Array2[j]
			j--
		}
		Array1[j+1] = temp1
		Array2[j+1] = temp2
	}
}
__________________
Ahujena
mazmaajinsh is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-02-2011 , 03:17   Re: Help me edit this
Reply With Quote #2

Quote:
prints in chat like this - 1. szName [PlayerPos[i]] , 2. szName - [PlayerPos[i]]
add client_print(0, print_chat, "Player %d PlayerPos: %d", i, PlayerPos[i])

Quote:
After closing the menu, it still does open it up again and again.
Because you call a task from its body, it generates multi-tasks with same ID, and remove_task fails to remove them (or skips when new is called). Instead start task with set_task(1.0, "displaypos", id, _, _, "b") - flag "b" means that task will be called every 1.0 sec automatically until removed. Use it NOT FROM displaypos(id)!
__________________

SonicSonedit is offline
Reply



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 04:30.


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