Raised This Month: $12 Target: $400
 3% 

Detected player problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-19-2018 , 07:45   Detected player problem
Reply With Quote #1

I have for exaple 3 players alive

This function detect if less than 2 players alive : for(new e = 1 ; e <= g_iMaxPlayers ; e++)

everything OK

If i change : for(new e = 1 ; e >= g_iMaxPlayers ; e++)
The function no detect if more than 2 players

Why?

Code:
stock check_origin(id)
{
	new iOrigin[3]
	get_user_origin(id, iOrigin, 0)
	

	new X[2];
	for(new e = 1 ; e <= g_iMaxPlayers ; e++)
	{
		if(!is_user_alive(e))
			continue;
		
		if(get_user_team(e) == 1)
			++X[0];
		else if(get_user_team(e) == 2)
			++X[1];
	}
	if((X[0] == 1) && (X[1] == 1))
        {


	            for(new i = 0; i < MAX_ZONES; ++i)
	            {

		    if((g_KnifeZoneOrgins[i][OriginX] == 0) 
		    && (g_KnifeZoneOrgins[i][OriginY] == 0) 
		    && g_KnifeZoneOrgins[i][OriginZ] == 0)
			    continue
		
		    new ZoneSizeX = get_pcvar_num(cvar_kzsize)
		    new ZoneSizeY = get_pcvar_num(cvar_kzsize)
		    new ZoneSizeZ = get_pcvar_num(cvar_kzsizez)
		
		    if ((g_KnifeZoneOrgins[i][OriginX] - iOrigin[0] > ZoneSizeX) || (g_KnifeZoneOrgins[i][OriginX] - iOrigin[0] < -ZoneSizeX) 
		    || (g_KnifeZoneOrgins[i][OriginY] - iOrigin[1] > ZoneSizeY) || (g_KnifeZoneOrgins[i][OriginY] - iOrigin[1] < -ZoneSizeY)
		    || (g_KnifeZoneOrgins[i][OriginZ] - iOrigin[2] > ZoneSizeZ) || (g_KnifeZoneOrgins[i][OriginZ] - iOrigin[2] < -ZoneSizeZ))
			    continue

		    return true
        }
	}
	return false
}

Last edited by Saint Sinner; 02-19-2018 at 07:46.
Saint Sinner is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-19-2018 , 08:01   Re: Detected player problem
Reply With Quote #2

That's a for-loop. Don't touch it.
You tell the code that it can run the loop as long as e is over g_iMaxPlayers.
e is however 1, making the statement false to begin with, so it does nothing.
Since the loop never runs, the variables X[0] (Terrorists) and X[1] (CT) are both 0, making the if-statement impossible as well.

What you want to change is this line:
if((X[0] == 1) && (X[1] == 1))
It says:
if ( terrorists == 1 AND counter_terrorists == 1 ) do...

Perhaps you want to change it to:
if ( X[0] <= 2 && X[1] <= 2 )
But then it would react to 0 players as well. So just to be safe...
if ( 1 <= X[0] <= 2 && 1 <= X[1] <= 2 )
Which means terrorists have to be more than or equal to 1 and also less than or equal to 2. Basically setting a span between 1 and 2. Same with CT.
You can change the numbers to whatever you want.

Last edited by Black Rose; 02-19-2018 at 08:05.
Black Rose is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-19-2018 , 08:17   Re: Detected player problem
Reply With Quote #3

Still not work

I want to detect if more than 2 players in the zone get function to player 3,4,5 ....

I want to make a zone like arena to play 1v1 not 2v1, 3v1...

do you think you can help me please?

Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <engine>
#include <colorchat> 

#define MAX_ZONES	5
#define TASK_ID		1234

#define OriginX		0
#define OriginY		1
#define OriginZ		2

new cvar_delay
new cvar_kzsize
new cvar_kzsizez
new cvar_height
new cvar_nadepro

new bool:g_DirExist
new g_ConfigsDir[64]
new g_KnifeZoneDir[64]

new Float:g_fDelay[33]
new g_ProtectionTime[33]
new bool:g_InTheZone[33]

new zoneID
new sprite_zbeam
new g_KnifeZoneOrgins[MAX_ZONES][3]
new bool:g_KnifeZoneLogos[MAX_ZONES]

new g_iMaxPlayers;
#define PLAYER_PUSH_FORCE -1000

new Float:g_toucheR_velocity[ 33 ][ 3 ];

static const PLUGIN_NAME[] 	= "Knife Zone"
static const PLUGIN_AUTHOR[] 	= "Cheap_Suit"
static const PLUGIN_VERSION[]	= "1.6"

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_cvar(PLUGIN_NAME, PLUGIN_VERSION, FCVAR_SPONLY|FCVAR_SERVER)
	register_clcmd("amx_kzmenu", "open_KnifeZone", ADMIN_LEVEL_A, "Knife Zone Menu")
	register_menucmd(register_menuid("Knife Zone Menu"), 1023, "action_KnifeZone")

	cvar_delay	= register_cvar("amx_kzdelay", 	"3")
	cvar_height	= register_cvar("amx_kzheight", "140")
	cvar_kzsize 	= register_cvar("amx_kzsize", 	"140")
	cvar_kzsizez 	= register_cvar("amx_kzsizez", 	"50")
	cvar_nadepro	= register_cvar("amx_kznadepro", "1")
	
	register_forward(FM_TraceLine, "fwd_TraceLine")
	register_directory()
        g_iMaxPlayers = get_maxplayers();
}

public plugin_precache() 
{
	precache_model("sprites/knifezone.spr")
	sprite_zbeam = precache_model("sprites/zbeam4.spr")
}

register_directory()
{
	get_configsdir(g_ConfigsDir, 63)
	format(g_KnifeZoneDir, 63, "%s/knifezone", g_ConfigsDir)
	
	if(!dir_exists(g_KnifeZoneDir))
	{
		log_amx("Knife Zone directory does not exist")
		g_DirExist = false
	} 
	else 
	{
		g_DirExist = true
		
		new curMap[32]
		get_mapname(curMap, 31)
		load_origins(curMap)
		
		set_task(1.0, "task_visuals", TASK_ID, _, _, "b")
	}
}

public open_KnifeZone(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1))
		return PLUGIN_HANDLED
	
	if(!g_DirExist) 
		console_print(id, "Knife Zone directory does not exist")
	else
		display_KnifeZone(id)
	
	return PLUGIN_HANDLED
}

public display_KnifeZone(id)
{
	new menuBody[512]
	new len = format(menuBody, 511, "\yKnife Zone Menu^n")
	len += format(menuBody[len], 511-len, "^n\w1. Create a zone")
	len += format(menuBody[len], 511-len, "^n\r2. Remove all zones")
	len += format(menuBody[len], 511-len, "^n\d3. Exit menu")

	new keys = (1<<0|1<<1|1<<2)
	show_menu(id, keys, menuBody, -1, "Knife Zone Menu")	
}

public action_KnifeZone(id, key)
{
	switch(key) 
	{
		case 0:	
		{
			if(zoneID >= MAX_ZONES)
			{
				client_print(id, print_chat, "Max Knife Zones reached")
				return PLUGIN_HANDLED
			}
			
			if(!is_user_alive(id)) 
			{
				client_print(id, print_chat, "You have to be alive to make a knife zone")
				return PLUGIN_HANDLED
			}
			
			_makeZone(id)
			display_KnifeZone(id)
			client_print(id, print_chat, "knife zone created")
		}			
		case 1: 
		{
			_removeZones()
			display_KnifeZone(id)
			client_print(id, print_chat, "All Knife Zones removed")
		}
	}
	return PLUGIN_HANDLED
}

public fwd_TraceLine(Float:v1[3], Float:v2[3], noMonsters, id)
{  
	if(!is_user_alive(id))
		return FMRES_IGNORED
	
	new victim = get_tr(TR_pHit)
	if(!is_user_alive(victim))
		return FMRES_IGNORED
		
	new tmp[2], weapon = get_user_weapon(victim, tmp[0], tmp[1]) 
	if(weapon == CSW_KNIFE && g_InTheZone[victim])
		set_tr(TR_flFraction, 1.0)
		
	return FMRES_IGNORED
}

public client_PreThink(id)
{
	if(!task_exists(TASK_ID) || !is_user_alive(id)) 
	{
		g_ProtectionTime[id] = -1
		g_InTheZone[id] = false
		
		return PLUGIN_CONTINUE
	}
	
	if(!check_origin(id))
	{
		g_InTheZone[id] = false
		g_ProtectionTime[id] = -1
		
		return PLUGIN_CONTINUE
	}
	
	new protectionDelay = get_pcvar_num(cvar_delay)
	if(g_ProtectionTime[id] < protectionDelay)
	{
		if(g_fDelay[id] + 1.0 < get_gametime())
		{
			g_ProtectionTime[id] += 1
			g_fDelay[id] = get_gametime()
		}
		
		set_hudmessage(255, 0, 0, -1.0, -1.0, _, _, 0.5, _, _, 4)
		show_hudmessage(id, "Protection in %d...", (protectionDelay - g_ProtectionTime[id]))
	}
	else if(g_ProtectionTime[id] >= protectionDelay)
	        g_InTheZone[id] = false

        ColorChat( id, RED, "^4You don't ^3have ^4sufficient ^3money to buy ^4this");
        //g_players = true
        set_pev( id, pev_velocity, g_toucheR_velocity[ id ] );
        g_toucheR_velocity[ id ][ 0 ] = 0.0;
        g_toucheR_velocity[ id ][ 1 ] = 0.0;
        g_toucheR_velocity[ id ][ 2 ] = 0.0;
        velocity_by_aim( id, PLAYER_PUSH_FORCE, g_toucheR_velocity[ id ] )
            
	
	return PLUGIN_CONTINUE
}

stock check_origin(id)
{
	new iOrigin[3]
	get_user_origin(id, iOrigin, 0)
	

	new X[2];
	for(new e = 1 ; e <= g_iMaxPlayers ; e++)
	{
		if(!is_user_alive(e))
			continue;
		
		if(get_user_team(e) == 1)
			++X[0];
		else if(get_user_team(e) == 2)
			++X[1];
	}
	if ( 0 > X[0] >= 1 && 0 > X[1] >= 1 )
        {


	            for(new i = 0; i < MAX_ZONES; ++i)
	            {

		    if((g_KnifeZoneOrgins[i][OriginX] == 0) 
		    && (g_KnifeZoneOrgins[i][OriginY] == 0) 
		    && g_KnifeZoneOrgins[i][OriginZ] == 0)
			    continue
		
		    new ZoneSizeX = get_pcvar_num(cvar_kzsize)
		    new ZoneSizeY = get_pcvar_num(cvar_kzsize)
		    new ZoneSizeZ = get_pcvar_num(cvar_kzsizez)
		
		    if ((g_KnifeZoneOrgins[i][OriginX] - iOrigin[0] > ZoneSizeX) || (g_KnifeZoneOrgins[i][OriginX] - iOrigin[0] < -ZoneSizeX) 
		    || (g_KnifeZoneOrgins[i][OriginY] - iOrigin[1] > ZoneSizeY) || (g_KnifeZoneOrgins[i][OriginY] - iOrigin[1] < -ZoneSizeY)
		    || (g_KnifeZoneOrgins[i][OriginZ] - iOrigin[2] > ZoneSizeZ) || (g_KnifeZoneOrgins[i][OriginZ] - iOrigin[2] < -ZoneSizeZ))
			    continue

		    return true
        }
	}
	return false
}

stock check_GrenadeOrigin(Origin[3])
{	
	new Ent = -1
	while((Ent = find_ent_by_class(Ent, "grenade")))
	{
		new szModel[32]
		entity_get_string(Ent, EV_SZ_model, szModel, 31)
		if(equal(szModel, "models/w_smokegrenade.mdl") 
		|| equal(szModel, "models/w_hegrenade.mdl") 
		|| equal(szModel, "models/w_flashbang.mdl"))
		{
			new Float:vOrigin[3], iOrigin[3]
			entity_get_vector(Ent, EV_VEC_origin, vOrigin)
			FVecIVec(vOrigin, iOrigin)
 
			if(get_distance(iOrigin, Origin) <= get_pcvar_num(cvar_kzsize))
				remove_entity(Ent)
		}
	}
}

load_origins(mapname[])
{
	new mapFile[64]
	format(mapFile, 63, "%s/%s.cfg", g_KnifeZoneDir, mapname)

	if(!file_exists(mapFile)) 
	{
		server_print("There are no Knife Zone(s) for %s", mapname)
		return PLUGIN_CONTINUE
	}

	new Text[64], Line = 0, Len = 0
	while(read_file(mapFile, Line++, Text, 63, Len))
	{
		if((Text[0]==';') || !Len)
		 	continue
		
		if(zoneID >= MAX_ZONES)
		{
			log_amx("Max Knife Zones reached, increase MAX_ZONES")
			break
		}
		
		new iOrigin[3][16]
		parse(Text, iOrigin[OriginX], 15, iOrigin[OriginY], 15, iOrigin[OriginZ], 15)
		
		g_KnifeZoneOrgins[zoneID][OriginX] = str_to_num(iOrigin[OriginX])
		g_KnifeZoneOrgins[zoneID][OriginY] = str_to_num(iOrigin[OriginY])
		g_KnifeZoneOrgins[zoneID][OriginZ] = str_to_num(iOrigin[OriginZ])
		
		zoneID += 1
	}
	return PLUGIN_CONTINUE
}

save_origin(mapname[], Origin[3])
{
	new mapFile[64], Text[64]
	format(mapFile, 63, "%s/%s.cfg", g_KnifeZoneDir, mapname)
	if(!file_exists(mapFile)) 
	{
		new Comments[64]
		format(Comments, 63, "; Knife Zone origins for %s", mapname)
		write_file(mapFile, Comments, -1)
	}
	
	format(Text, 64, "%i %i %i", Origin[OriginX], Origin[OriginY], Origin[OriginZ])
	write_file(mapFile, Text, -1)
}

public task_visuals()
{
	for(new i = 0; i < MAX_ZONES; ++i)
	{
		if((g_KnifeZoneOrgins[i][OriginX] == 0) 
		&& (g_KnifeZoneOrgins[i][OriginY] == 0) 
		&& g_KnifeZoneOrgins[i][OriginZ] == 0)
				continue
		
		create_kzring(g_KnifeZoneOrgins[i])
		
		if(get_pcvar_num(cvar_nadepro))
			check_GrenadeOrigin(g_KnifeZoneOrgins[i])
		
		if(!g_KnifeZoneLogos[i]) 
		{
			g_KnifeZoneLogos[i] = true
			create_logo(g_KnifeZoneOrgins[i])
		}
	}
}

stock create_kzring(Origin[3])
{
	new shape[4][2] = {{1,1}, {-1,1}, {-1,-1}, {1,-1}}
	new x1, y1, x2, y2, height, i, j
	new ZoneSize = get_cvar_num("amx_kzsize")
	
	for(j = 0; j < 2; j++)
	{
		height = (30 * j - 30)
		for(i = 0; i < 4; i++)
		{
			x1 = (shape[i][0] * ZoneSize)
			y1 = (shape[i][1] * ZoneSize)
			if(i < 3)
			{
				x2 = (shape[i+1][0] * ZoneSize)
				y2 = (shape[i+1][1] * ZoneSize)
			}
			else
			{
				x2 = (shape[0][0] * ZoneSize)
				y2 = (shape[0][1] * ZoneSize)
			}
			
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
			write_byte(0)
			write_coord(Origin[OriginX] + x1)
			write_coord(Origin[OriginY] + y1)
			write_coord(Origin[OriginZ] + height)
			write_coord(Origin[OriginX] + x2)
			write_coord(Origin[OriginY] + y2)
			write_coord(Origin[OriginZ] + height)
			write_short(sprite_zbeam)
			write_byte(0)
			write_byte(0)
			write_byte(30)
			write_byte(15)
			write_byte(0)
			write_byte(255)
			write_byte(0)
			write_byte(0)  
			write_byte(100)
			write_byte(0)
			message_end()
		}
	}
}

stock create_logo(Origin[3]) 
{
	new Float:flOrigin[3]
	IVecFVec(Origin, flOrigin)
	
	new sprite = create_entity("info_target")
	if(is_valid_ent(sprite))
	{
		entity_set_string(sprite, EV_SZ_classname, "kzlogo")
		entity_set_model(sprite, "sprites/knifezone.spr")
		
		flOrigin[2] += get_pcvar_num(cvar_height)
		entity_set_origin(sprite, flOrigin)
	}
}

_makeZone(id)
{
	new iOrigin[3], CurMap[32]
	get_user_origin(id, iOrigin, 0)
	get_mapname(CurMap, 31)

	zoneID = 0
	save_origin(CurMap, iOrigin)
	load_origins(CurMap)
	
	if(task_exists(TASK_ID))
		remove_task(TASK_ID)
		
	set_task(1.0, "task_visuals", TASK_ID, _, _, "b")
}

_removeZones()
{
	new MapFile[64], CurMap[32]
	get_mapname(CurMap, 31)
	format(MapFile, 63, "%s/%s.cfg", g_KnifeZoneDir, CurMap)
	if(file_exists(MapFile))
		delete_file(MapFile)
	
	if(task_exists(TASK_ID))
		remove_task(TASK_ID)
	
	zoneID = 0
	
	for(new i = 0; i < MAX_ZONES; ++i)
	{
		g_KnifeZoneLogos[i] = false
		g_KnifeZoneOrgins[i][OriginX] = 0
		g_KnifeZoneOrgins[i][OriginY] = 0
		g_KnifeZoneOrgins[i][OriginZ] = 0
	}
	
	new logo = -1
	while((logo = find_ent_by_class(logo, "kzlogo")))
		remove_entity(logo)
}

Last edited by Saint Sinner; 02-19-2018 at 08:20.
Saint Sinner is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-19-2018 , 15:26   Re: Detected player problem
Reply With Quote #4

"get function"? What the hell does that mean?

The original code is 1v1 already so what's the problem here?
You have to explain EXACTLY what you want. Otherwise I can just sit here and code for hours with your response being "That's not what I wanted". I'm not going to do that. So take your time and explain in details what it is you want. Assume I know nothing of this plugin (which I don't).

0 > X[] >= 1
This checks if X[] is lower than 0 and higher than or equal to 1, which is impossible.

Last edited by Black Rose; 02-19-2018 at 15:28.
Black Rose is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-19-2018 , 16:15   Re: Detected player problem
Reply With Quote #5

Man i want to make this:

If 2 players in the zone 1 tero and 1 ct nothing happens

if 3 players in the zone i want to get to pleyer 3 slap, slay if touch this zone the last one to come

For example : player 1 tero entry in the zone , player 2 Ct entry in the zone If want to entry player 3 in the zone get command (slap,slay)

look this video https://www.youtube.com/watch?v=NAQubB4Ymjg


This script is difficult to make .. i dont know if someone can help me

Last edited by Saint Sinner; 02-20-2018 at 02:34.
Saint Sinner is offline
AkioDono
Junior Member
Join Date: Feb 2018
Old 02-19-2018 , 17:37   Re: Detected player problem
Reply With Quote #6

Nice idea, I hope I can help you .
AkioDono is offline
Reply


Thread Tools
Display Modes

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:03.


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