Raised This Month: $79 Target: $400
 19% 

Cup plugin sort problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wAyz
Senior Member
Join Date: Feb 2010
Location: Germany
Old 09-25-2020 , 09:08   Cup plugin sort problem
Reply With Quote #1

Hello,

So I'm using an alternative version of xPaw's cup plugin, there's a hud display which shows following: 1. Player (x%). x is just the number depending on which marker the player is at currently. So if both players are at the last marker for example, it just sorts positions alphabetical, but i'd prefer to always keep the player who was first at his position. On screenshot for example player B should be first place on display, but still ends up being shown as second. comparePercent function is at line 385 ff. but i couldn't make it work yet. tried if( iElem1[ 0 ] == iElem2[ 0 ] ) return 1; but that just made player B always first despite attempts where Player A was the winner.

Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <cstrike>
#include <fakemeta>
#include <colorchat>
#include <hamsandwich>
#include <fun>
#include <dhudmessage>


#pragma semicolon 1

#define PREFIX "[SiMen Cup]"
#define ADMIN_LEVEL	ADMIN_KICK
#define MARKER_MODEL	"models/can.mdl"
#define MAX_MARKERS	2000

#define MARKER_KEYS	(1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<9)
#define ADMIN_KEYS (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<6) | (1<<8) | (1<<9)

enum {
	CUP_NONE = 0,
	CUP_RUNNING,
	CUP_FINISHED
}

#define HUD_HIDE_TIMER (1<<4)
new kz_hidetime;
new bool:g_bHideTimer;
new g_msgHideWeapon;
new g_msgBarTime;

new const KZ_DIR[] = "addons/amxmodx/configs/kz";
new const KZ_STARTFILE[] = "start.ini";
new bool:DefaultStart;
new Float:DefaultStartPos[3];

new bool:faster_nc[33];
new bool:in_cup[33];
new bool:gCheckCupPos[33];

new gClimbers;
new gClimber[33][33];
new gClimberIndex[33];
new Float:gClimbersPos[33][3];	

new gCupStatus;
new gCupTime;
new gAnnTime;
new gCountDown;
new gMaxPlayers;
new gMenuPos[ 33 ];

new gCupStartTime;
new iAnnouncments;

enum { N1, N2, N3, N4, N5, N6, N7, N8, N9, N0 };

new bool:gUserConnected[ 33 ];
new bool:gUserIsBOT[ 33 ];
new gUserIsAlive[ 33 ];
new gszMarkersMenu[ 256 ];
new gszCupMenuStart[ 128 ];
new gszCupMenuEnd[ 128 ];

new gMarkersCount;
new gszMarkersFile[ 64 ];
new gMarkerEnt[ MAX_MARKERS ];
new bool:gbMarkersVisible;
new Float:gflMarkerPos[ MAX_MARKERS ][ 3 ];

public plugin_natives()	//向Prokreedz扩展在CUP的接口
{
	register_native("kz_player_in_cup", "native_player_in_cup", 1);
}

public native_player_in_cup(id)
{
	if(in_cup[id])
		return true;
	else 
		return false;

	return false ;
}

public plugin_init() {
	register_plugin( "SiMen CUP", "1.0", "xPaw" );
	
	g_msgHideWeapon = get_user_msgid("HideWeapon");
	register_event("ResetHUD", "onResetHUD", "b");
	register_message(g_msgHideWeapon, "msgHideWeapon");
	kz_hidetime = register_cvar("kz_hidetime", "1");

	// Forwards
	register_think( "pasla_cup_countdown", "fwdThink_Countdown" );
	register_think( "pasla_cup_timer", "fwdThink_Timer" );
	
	// Events
	register_event( "ResetHUD", "Event_Health", "b" );
	register_event( "Health", "Event_Health", "b" );
	
	// Commands
	register_clcmd( "say /poscheck", "cmdPosMenu" );
	register_clcmd( "say /pc", "cmdPosMenu" );
	register_clcmd( "say /cup",	 "cmdAdminMenu" );
	register_clcmd( "say /cm",	 "cmdAdminMenu" );
	register_clcmd( "say /admincup",	 "cmdAdminMenu" );
	register_clcmd( "say /cupmenu",	 "cmdAdminMenu" );
	register_clcmd( "say /markers", "cmdMarkersMenu" );
	register_clcmd( "say /locs", "cmdMarkersMenu" );

	register_clcmd( "say /see", "CheckCupPos" );

	// Console commands
	register_concmd( "cup_setmarker", "cmdMarkersSet", ADMIN_LEVEL, "Create cup marker" );
	register_concmd( "cup_nearestmarker", "cmdMarkersNearest", ADMIN_LEVEL, "Print nearest cup marker" );
	
	// fastnoclip
	register_forward( FM_CmdStart, "FwdCmdStart" ) ;

	// Menus
	register_menucmd( register_menuid( "PosMenu" ), 1023, "handlePosMenu" );
	register_menucmd( register_menuid( "CupMenu" ), ADMIN_KEYS, "handleAdminMenu" );
	register_menucmd( register_menuid( "MarkersMenu" ), MARKER_KEYS, "handleMarkersMenu" );

	gMaxPlayers	= get_maxplayers();
	
	gCupStatus	= CUP_NONE;
	gCupTime	= 10;	//菜单内默认比赛时间
	gAnnTime 	= 30;	//菜单内默认报时间隔
	gCountDown 	= 3;	//倒计时时间

	g_msgBarTime = get_user_msgid( "BarTime" );
	HudApplyCVars();
	//set_task(120.0,"outputmsg2", .flags="b");
}

public plugin_precache() {
	precache_sound( "simencup/zero.wav" );
	precache_sound( "simencup/one.wav" );
	precache_sound( "simencup/two.wav" );
	precache_sound( "simencup/three.wav" );
	precache_sound( "simencup/four.wav" );
	precache_sound( "simencup/five.wav" );
	precache_sound( "simencup/six.wav" );
	precache_sound( "simencup/seven.wav" );
	precache_sound( "simencup/eight.wav" );
	precache_sound( "simencup/nine.wav" );
	precache_sound( "simencup/ten.wav" );
	
	precache_sound( "simencup/fifty.wav" );
	precache_sound( "simencup/fifteen.wav" );
	precache_sound( "simencup/fourty.wav" );
	precache_sound( "simencup/thirty.wav" );
	
	precache_sound( "simencup/minutes.wav" );
	precache_sound( "simencup/seconds.wav" );
	precache_sound( "simencup/remaining.wav" );
	
	precache_model( MARKER_MODEL );
}

public FwdCmdStart( client, ucHandle ) //Hawk552 (Exolent)
{
	if( !is_user_alive( client )
	|| pev( client, pev_movetype ) != MOVETYPE_NOCLIP
	|| !( pev( client, pev_button ) & IN_FORWARD ) || !faster_nc[ client ] ) 
	{
		return FMRES_IGNORED;
	}
	
	static Float:fForward, Float:fSide;
	get_uc( ucHandle, UC_ForwardMove, fForward );
	get_uc( ucHandle, UC_SideMove, fSide );
	
	if( fForward == 0.0 && fSide == 0.0 ) 
	{
		return FMRES_IGNORED;
	}
	
	static Float:fMaxSpeed;
	pev( client, pev_maxspeed, fMaxSpeed );
	
	
	{
		static Float:vOrigin[ 3 ];
		pev( client, pev_origin, vOrigin );
		
		static Float:vAngle[ 3 ];
		pev( client, pev_v_angle, vAngle );
		engfunc( EngFunc_MakeVectors, vAngle );
		global_get( glb_v_forward, vAngle );
		
		vOrigin[ 0 ] += ( vAngle[ 0 ] * 10.0 );
		vOrigin[ 1 ] += ( vAngle[ 1 ] * 10.0 );
		vOrigin[ 2 ] += ( vAngle[ 2 ] * 10.0 );
		
		engfunc( EngFunc_SetOrigin, client, vOrigin );
	}
	return FMRES_IGNORED;
}

public client_connect(id)
{
	in_cup[id]=false;
}

public plugin_cfg( ) {

	new startcheck[100], data[256], mapname[64], map[64], x[13], y[13], z[13];
	get_mapname( mapname, 63);
	formatex(startcheck, 99, "%s/%s", KZ_DIR, KZ_STARTFILE);
	new f = fopen(startcheck, "rt" );
	while( !feof( f ) )
	{
		fgets( f, data, sizeof data - 1 );
		parse( data, map, 63, x, 12, y, 12, z, 12);
			
		if( equali( map, mapname ) )
		{
			DefaultStartPos[0] = str_to_float(x);
			DefaultStartPos[1] = str_to_float(y);
			DefaultStartPos[2] = str_to_float(z);
			
			DefaultStart = true;
			break;
		}
	}
	fclose(f);
	
	new iSize = sizeof( gszMarkersMenu );
	add( gszMarkersMenu, iSize, "\r#kz.xPaw \wCup Markers Menu^n^n" );
	add( gszMarkersMenu, iSize, "\r1. \wSet a marker^n" );
	add( gszMarkersMenu, iSize, "\r2. \wDelete last cup marker^n^n" );
	add( gszMarkersMenu, iSize, "\r3. \wHide cup markers^n" );
	add( gszMarkersMenu, iSize, "\r4. \wShow cup markers^n^n" );
	add( gszMarkersMenu, iSize, "\r5. \wLoad cup markers^n" );
	add( gszMarkersMenu, iSize, "\r6. \wSave cup markers^n^n" );
	add( gszMarkersMenu, iSize, "\r9. \wShow nearest cup marker^n" );
	add( gszMarkersMenu, iSize, "\r0. \wExit" );
	
	iSize = sizeof( gszCupMenuStart );
	add( gszCupMenuStart, iSize, "\r#kz.xPaw \wCup Admin Menu^n^n" );
	add( gszCupMenuStart, iSize, "\r1. \wStart Cup^n" );
	add( gszCupMenuStart, iSize, "\r2. \wStop Cup^n^n" );
	
	iSize = sizeof( gszCupMenuEnd );
	add( gszCupMenuEnd, iSize, "\r5. \wDelete finish positions^n^n" );
	add( gszCupMenuEnd, iSize, "\r9. \wGoto markers menu^n" );
	add( gszCupMenuEnd, iSize, "\r0. \wExit" );
	
	// Other Stuff
	new szDataDir[ 48 ], szMapname[ 32 ];
	get_localinfo( "amxx_datadir", szDataDir, charsmax( szDataDir ) );
	get_mapname( szMapname, charsmax( szMapname ) );
	
	format( gszMarkersFile, charsmax( gszMarkersFile ), "%s/kreedz/cup/%s.txt", szDataDir, szMapname );
	
	LoadMarkers( );
}

public fwdThink_Countdown( iEntity ) {
	fnShowTimeRemining( gCountDown, 1 );
	
	gCountDown--;
	
	if( gCountDown <= -1 ) 
	{
		engfunc( EngFunc_RemoveEntity, iEntity );
		
		for( new i = 1; i < gMaxPlayers; i++ ) 
		{
			if( gUserIsAlive[i] )
				set_pev( i, pev_flags, pev(i, pev_flags) & ~FL_FROZEN );
			else if( gUserConnected[ i ] && !gUserIsAlive[i] )
				set_pev( i, pev_flags, pev(i, pev_flags) & ~FL_FROZEN );

			if(callfunc_begin("start_climb_cup","prokreedz_2.32.amxx") == 1) 
			{
				callfunc_push_int(i);
				callfunc_end();
			}
		}
		
		gCupStartTime	=  floatround(get_gametime());
		gCupStatus	= CUP_RUNNING;
		gCountDown	= 10;
		
		new iEntityTimer = engfunc( EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target") );
		set_pev( iEntityTimer, pev_classname, "pasla_cup_timer" );
		set_pev( iEntityTimer, pev_nextthink, get_gametime() + 1.0 );
		ColorChat(0, RED,"%s ^4比赛开始 ^3Go Go Go ^1! ", PREFIX );
	} 
	else
		set_pev( iEntity, pev_nextthink, get_gametime() + 1.0 );
}

public fwdThink_Timer( iEntity ) {
	static iClimbTime, iLeftTime;
	iClimbTime	= floatround( get_gametime() ) - gCupStartTime;
	iLeftTime	= gCupTime - iClimbTime;
	
	if( (gAnnTime * iAnnouncments) <= iClimbTime ) {
		iAnnouncments++;
		
		fnShowTimeRemining( iLeftTime, 0 );
	}
	
	// Map status start
	static i, szName[ 32 ], szFormat[ 40 ], iMarker, Float:iPercent;
	new szHud[ 512 ];
	
	new szCreators[ 32 ][ 32 ], iCreated[ 32 ][ 2 ];
	for( i = 0; i < sizeof iCreated; i++ ) {
		iCreated[ i ][ 1 ] = i;
	}
	
	for( i = 1; i <= gMaxPlayers; i++ ) {
		if( !gUserIsAlive[ i ] )
			continue;
		
		iMarker = GetNearestMarker( i );
		
		if( iMarker > 0 ) {
			iPercent = float( iMarker ) / float( gMarkersCount ) * 100.0;
			
			get_user_name( i, szName, charsmax( szName ) ); 
			format( szCreators[ i ], sizeof( szCreators ), szName );
			
			iCreated[ i ][ 0 ] = floatround( iPercent );
		}
	}
	
	SortCustom2D( iCreated, sizeof iCreated, "ComparePercent" );
	
	static iIndex;
	for( i = 0; i < sizeof( szCreators ); i++ ) 
	{
		iIndex = iCreated[ i ][ 1 ];
		
		if( gUserIsAlive[ iIndex ] ) 
		{
			format( szFormat, charsmax( szFormat ), "%d. %s (%i%s)^n",i+1, szCreators[ iIndex ] ,iCreated[ i ][ 0 ], "%%");
			add( szHud, charsmax( szHud ), szFormat );
		}
	}

	new Alive[32], Dead[32], alivePlayers, deadPlayers,mode;
	get_players(Alive, alivePlayers, "ach");
	get_players(Dead, deadPlayers, "bch");

	for(new i=0;i<alivePlayers;i++)
	{
		if( gCheckCupPos[Alive[i]])
		{
			set_hudmessage( 255, 255, 255, 0.01, 0.13, 0, 0.0, 1.1, 0.0, 0.0, 2 );
			show_hudmessage(Alive[i], szHud );
		}
	}

	for(new i=0;i<deadPlayers;i++)
	{
		mode = pev(Dead[i],pev_iuser1);

		if( mode == 2 || mode == 4 )
		{
			set_hudmessage( 255, 255, 255,  0.01, 0.13, 0, 0.0, 1.1, 0.0, 0.0,  2 );
			show_hudmessage(Dead[i], szHud );
		}
	}
	// Map status end
	
	if( iLeftTime < 11 )
		fnShowTimeRemining( iLeftTime, 0 );
	
	if( iLeftTime <= 0 )
		fnFinishCup();
	
	if( pev_valid( iEntity ) )
		set_pev( iEntity, pev_nextthink, get_gametime() + 1.0 );
}

public ComparePercent( const iElem1[], const iElem2[], const iArray[], szData[], iSize ) {
	if( iElem1[ 0 ] < iElem2[ 0 ] ) {
		return 1;
	}
	else if( iElem1[ 0 ] > iElem2[ 0 ] ) {
		return -1;
	}
	
	return 0;
}

public outputmsg2(id)
{
	new Players[32],inum;
	get_players(Players,inum, "c");
	if(inum < 1)
	{
		return;
	}
	set_hudmessage(255, 255, 255, -1.0, 0.25, 2, 0.5, 10.0, 0.02, 0.5,4);
	show_hudmessage(0, "JUMP CUP is about to begin!");
}		

// COMMANDS
public cmdPosMenu( id ) {
	fnPositionsMenu( id, gMenuPos[id] = 0 );
	
	return PLUGIN_CONTINUE;
}

/*
public cmdLoopMarkersSet( id ) {
	if( get_user_flags( id ) & ADMIN_LEVEL )
		set_task(id, "cmdMarkersSet")
	
	return PLUGIN_HANDLED;
}
*/

public cmdMarkersMenu( id ) {
	if( get_user_flags( id ) & ADMIN_LEVEL )
		show_menu( id, MARKER_KEYS, gszMarkersMenu, -1, "MarkersMenu" );
	
	return PLUGIN_HANDLED;
}

public cmdAdminMenu( id ) {
	if ( get_user_flags( id ) & ADMIN_LEVEL ) {
		new szMenu[ 512 ], szGay[ 64 ];
		add( szMenu, charsmax( szMenu ), gszCupMenuStart );
		formatex( szGay, charsmax( szGay ), "\r3. \wTime of cup: \d%d minutes^n", ( gCupTime / 60 ) );
		add( szMenu, charsmax( szMenu ), szGay );
		formatex( szGay, charsmax( szGay ), "\r4. \wAnnouncement interval of time: \d%d seconds^n^n", gAnnTime );
		add( szMenu, charsmax( szMenu ), szGay );
		add( szMenu, charsmax( szMenu ), gszCupMenuEnd );
		
		show_menu( id, ADMIN_KEYS, szMenu, -1, "CupMenu" );
	}
	
	return PLUGIN_HANDLED;
}

public fnPositionsMenu( id, pos ) {
	if( pos < 0 )
		return PLUGIN_CONTINUE;
	
	if( gCupStatus != CUP_FINISHED ) {
		ColorChat(id, BLUE, "^x04%s^x01 Cup-menu is only available when the climb cup has finished.", PREFIX );
		
		return PLUGIN_CONTINUE;
	}
	
	new iPage = pos + 1, iKeys = (1<<9), iKey, szMenu[512];
	new iPages = (gClimbers / 8) + ( (gClimbers % 8) ? 1 : 0 );
	new iLen = format(szMenu, 511, "\r#kz.xPaw \wPositions check menu\R \d%d/%d^n\w^n", iPage, iPages );
	
	new iMarker, Float:iPercent;
	for( new i = pos * 8; i < gMaxPlayers; i++ ) {
		if( !equal( gClimber[i], "" ) && iKey < 8 ) {
			if( gClimbersPos[i][0] != 0 && gClimbersPos[i][1] != 0 && gClimbersPos[i][2] != 0 ) {
				gClimberIndex[iKey] = i;
				iKeys |= (1<<iKey);
				iKey++;
				
				iMarker = GetNearestMarkerByOrigin( gClimbersPos[i] );
				if( iMarker > 0 ) {
					iPercent = float( iMarker ) / float( gMarkersCount ) * 100.0;
					
					iLen += format( szMenu[iLen], 511 - iLen, "\r%d.\w %s \r\R %i%%^n", iKey, gClimber[i], floatround( iPercent ) );
				} else
					iLen += format( szMenu[iLen], 511 - iLen, "\r%d.\w %s^n", iKey, gClimber[i] );
			} else {
				gClimberIndex[iKey] = i;
				iKey++;
				
				iLen += format( szMenu[iLen], 511 - iLen, "\r%d.\d %s^n", iKey, gClimber[i] );
			}
		}
	}
	
	if( iPage != iPages ) {
		iLen += format( szMenu[iLen], 511 - iLen, "^n\r9. \wNext...^n\r0. \wBack" );
		
		iKeys |= (1<<8);
	} else
		iLen += format( szMenu[iLen], 511 - iLen, "^n\r0. \wExit" );
	
	show_menu( id, iKeys, szMenu, -1, "PosMenu" );
	
	return PLUGIN_CONTINUE;
}

// MENU HANDLES
public handleMarkersMenu( id, iKey ) {
	switch( iKey ) {
		case N1: { cmdMarkersSet( id ); }
		case N2: { cmdMarkersRemove( id ); }
		case N3: { HideMarkers( ); }
		case N4: { ShowMarkers( ); }
		case N5: { LoadMarkers( id ); }
		case N6: { SaveMarkers( id ); }
		
		case N9: { cmdMarkersNearest( id ); }
		case N0: { return; }
	}
	
	cmdMarkersMenu( id );
}

public handlePosMenu( id, key ) {
	if( gCupStatus != CUP_FINISHED )
		return PLUGIN_HANDLED;
	
	switch( key ) {
		case 8: fnPositionsMenu( id, ++gMenuPos[id] );
		case 9: fnPositionsMenu( id, --gMenuPos[id] );
		default: {
			ForceDuck( id );
			engfunc( EngFunc_SetOrigin, id, gClimbersPos[gMenuPos[id] * 8 + gClimberIndex[key]] );
			ColorChat(id, RED, "%s^x01 You have been teleported to the finish position of climber^x03 %s^x01.", PREFIX, gClimber[gMenuPos[id] * 8 + gClimberIndex[key]] );
			
			fnPositionsMenu( id, gMenuPos[id] );
		}
	}
	
	return PLUGIN_HANDLED;
}

public handleAdminMenu( id, key ) {
	switch( key ) 
	{
		case 0: {
			//server_cmd("sv_restart 1");
		//	set_task(2.5,"fnStartCup",id);
			fnStartCup( id );
		}
		case 1: fnStopCup( id );
		case 2: 
		{
			gCupTime += 60;
			
			if( gCupTime > 600 )
				gCupTime = 60;
			
			cmdAdminMenu( id );
		}
		case 3: 
		{
			gAnnTime += 15;
			
			if( gAnnTime > 45 )
				gAnnTime = 15;
			
			cmdAdminMenu( id );
		}
		case 4: 
		{
			if( faster_nc[ id ] )
			{
				faster_nc[ id ] = false;
			}
			else
			{
				faster_nc[ id ] = true;
			}
			
			cmdAdminMenu( id );
		}

		case 5: 
		{
			for( new i = 0; i < gMaxPlayers; i++ ) {
				gClimbersPos[i][0] = 0.0;
				gClimbersPos[i][1] = 0.0;
				gClimbersPos[i][2] = 0.0;
				gClimber[i] = "";
				gClimberIndex[i] = 0;
			}
			
			gClimbers = 0;
			gCupStatus = CUP_NONE;
			ColorChat(id, RED, "%s^x01 Players position was deleted.", PREFIX);
			
			cmdAdminMenu( id );
		}
		case 6: {
			new name[32];
			get_user_name(id,name,31);
			for( new i = 0; i < gMaxPlayers; i++ ) 
			{
				set_pev(i, pev_flags, pev(i, pev_flags) & ~FL_FROZEN);
				in_cup[i] = false;
			}
			ColorChat(0, RED,"^4%s ^3Admin ^4%s ^3Player freezing was stopped.",PREFIX,name);
			cmdAdminMenu( id );
		}
		case 8: cmdMarkersMenu( id );
		default: return PLUGIN_HANDLED;
	}
	
	return PLUGIN_HANDLED;
}

// START & STOP
public fnStartCup( id ) {
	for( new i = 1; i < gMaxPlayers; i++ ) {
		gClimbersPos[i][0] = 0.0;
		gClimbersPos[i][1] = 0.0;
		gClimbersPos[i][2] = 0.0;
		gClimber[i] = "";
		gClimberIndex[i] = 0;
	}
	
	gCountDown	= 2;
	iAnnouncments	= 0;
	gClimbers = 0;
	
	new iEntityTimer = engfunc( EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target") );
	set_pev( iEntityTimer, pev_classname, "pasla_cup_countdown" );
	set_pev( iEntityTimer, pev_nextthink, get_gametime() + 1.0 );
	
	for( new i = 1; i < gMaxPlayers; i++ ) {
		if( gUserIsAlive[i] ) 
		{
			in_cup[i] = true;

			// set_task(9.0, "restart",i);	
			if ( DefaultStart )
			{
				set_pev(i, pev_velocity, Float:{0.0, 0.0, 0.0});
				set_pev(i, pev_origin, DefaultStartPos);
			}
			set_pev( i, pev_flags, pev(i, pev_flags) | FL_FROZEN );
			set_task(1.0, "MsgBar",i);	//加载进度条

			if(callfunc_begin("reset_checkpoints","prokreedz_2.32.amxx") == 1)  //清除计时器和存读点
			{
				callfunc_push_int(i);
				callfunc_end();
			}
			
			if(callfunc_begin("InvisMenu","prokreedz_2.32.amxx") == 1)  //屏蔽菜单
			{
				callfunc_push_int(i);
				callfunc_end();
			}
		}
	}
	new szAdminName[32];
	get_user_name( id, szAdminName, 31 );
	set_dhudmessage(255, 30, 0, -1.0, 0.2, 2, 0.1, 10.0, 0.02, 0.5);
	show_dhudmessage(0, "The game has entered the countdown. Please select whether to block the player model?");
	ColorChat(0, RED, "%s^x04 Jump Cup has been started!^x01 Admin:^x04 %s^x01.", PREFIX, szAdminName );
	return PLUGIN_HANDLED;
}

public fnStopCup( id ) {
	new iEntityTimer = -1;
	while( ( iEntityTimer = engfunc(EngFunc_FindEntityByString, iEntityTimer, "classname", "pasla_cup_timer" ) ) )
		engfunc( EngFunc_RemoveEntity, iEntityTimer );
	
	iEntityTimer = -1;
	while( ( iEntityTimer = engfunc(EngFunc_FindEntityByString, iEntityTimer, "classname", "pasla_cup_countdown" ) ) )
		engfunc( EngFunc_RemoveEntity, iEntityTimer );
	
	for( new i = 1; i < gMaxPlayers; i++ ) 
	{
		if( gUserConnected[ i ] ) 
		{
			if( gUserIsAlive[i] ) 
			{
				pev( i, pev_origin, gClimbersPos[i] );
				Splash( i );
			}
			get_user_name( i, gClimber[i], 32 );
			gClimbers++;
			in_cup[i] = false;
			set_pev( i, pev_flags, pev(i, pev_flags) & ~FL_FROZEN );

			if(callfunc_begin("reset_checkpoints","prokreedz_2.32.amxx") == 1)  //清除计时器和存读点
			{
				callfunc_push_int(i);
				callfunc_end();
			}
		}
	}
	gCupStatus = CUP_FINISHED;
	
	///server_cmd( "sv_restart 1" );

	new szAdminName[32];
	get_user_name( id, szAdminName, 31 );
	ColorChat(0, RED, "%s^x01 Admin^x04 %s^x01 forced to finish Jump Cup.", PREFIX, szAdminName );
}

public fnFinishCup() {
	new iEntityTimer = -1;
	while( ( iEntityTimer = engfunc(EngFunc_FindEntityByString, iEntityTimer, "classname", "pasla_cup_timer" ) ) )
		engfunc( EngFunc_RemoveEntity, iEntityTimer ); 
	
	for( new i = 1; i < gMaxPlayers; i++ ) 
	{
		if( gUserConnected[ i ] ) 
		{
			if( gUserIsAlive[i] ) 
			{
				pev( i, pev_origin, gClimbersPos[i] );
				Splash( i );

				if(callfunc_begin("reset_checkpoints","prokreedz_2.32.amxx") == 1)  //清除计时器和存读点
				{
					callfunc_push_int(i);
					callfunc_end();
				}
				set_pev(i, pev_flags, pev(i, pev_flags) | FL_FROZEN);	//完成冻结
			}
			
			get_user_name( i, gClimber[i], 32 );
			gClimbers++;
			set_task(0.1,"cmdPosMenu",i);
		}
	}
	gCupStatus = CUP_FINISHED;
	
	ColorChat(0, RED, "%s^x04 Jump Cup has ended.^x01 Say^x03 /pc^x01 to check the finish positions.", PREFIX );
}

public restart(id)
{
	if (!is_user_alive(id) || !is_user_connected(id)) 
		return;

	// new Float:vOrigin[3];
	// pev( id, pev_origin, vOrigin );
	// set_pev( id, pev_origin, vOrigin );

	if ( DefaultStart )
	{
		set_pev(id, pev_velocity, Float:{0.0, 0.0, 0.0});
		set_pev(id, pev_origin, DefaultStartPos);
	}
	set_pev( id, pev_flags, pev(id, pev_flags) | FL_FROZEN );
	
	// if(get_user_noclip(id))
	// {
		// set_user_noclip(id,0);
	// }

	// strip_user_weapons(id);
	// give_item(id,"weapon_knife");
	// give_item(id,"weapon_usp");

	// if(user_has_weapon(id,CSW_USP))
	// {
		// cs_set_user_bpammo(id, CSW_USP, 132);
	// }
}

// TIME STUFF
public fnShowTimeRemining( iTime, iType ) {
	if( iTime < 0 )
		return PLUGIN_CONTINUE;
	
	new szMessage[128], iSeconds = iTime % 60, iMinutes = iTime / 60;
	
	if( iTime < 11 ) {
		
		if( iType )
			ColorChat(0, BLUE,"^4%s The round will start in: ^3%d",PREFIX,iSeconds);
		else
			ColorChat(0, RED,"^4%s The round will end in: ^3%d",PREFIX,iSeconds);
		
		new iSecondsString[32];
		num_to_word( iSeconds, iSecondsString, 31 );
		
		format( szMessage, 127, "%s", iSecondsString );
	} else {
		
		if( iMinutes != 0 && iSeconds != 0 )
			ColorChat(0, BLUE,"^4%s ^1Time Remaining ^3%02d:%02d",PREFIX,iMinutes,iSeconds);
		else if( iMinutes!= 0 && iSeconds == 0 )
			ColorChat(0, RED,"^4%s ^1Time Remaining ^3%02d:%02d ",PREFIX,iMinutes,iSeconds);
		else if( iMinutes == 0 && iSeconds != 0 )
			ColorChat(0, RED,"^4%s ^1Time Remaining ^3%02d:%02d",PREFIX,iMinutes,iSeconds);
		
		new iSecondsString[32];
		num_to_word( iSeconds, iSecondsString, 31 );
		
		if( iMinutes != 0 ) {
			new iMinutesString[32];
			num_to_word( iMinutes, iMinutesString, 31 );
			
			if( iSeconds != 0 )
				format( szMessage, 127, "%sminutes %sseconds remaining", iMinutesString, iSecondsString );
			else
				format( szMessage, 127, "%sminutes remaining", iMinutesString);
		} else
			format( szMessage, 127, "%sseconds remaining", iSecondsString );
	}
	
	client_cmd( 0, "spk ^"simencup/%s^" ", szMessage );
	
	return PLUGIN_CONTINUE;
	
}

// COMMANDS
public cmdMarkersSet( id ) {
	if( get_user_flags( id ) & ADMIN_LEVEL ) {
		new Float:vOrigin[ 3 ];
		GetPlayerOrigin( id, vOrigin );
		
		gMarkerEnt[ gMarkersCount ] = CreateMarker( vOrigin );
		gflMarkerPos[ gMarkersCount ] = vOrigin;
		gMarkersCount++;
		
		ColorChat( id, RED, "%s^x01 Create Markers (^x04%f %f %f^x01).", PREFIX, vOrigin[ 0 ], vOrigin[ 1 ], vOrigin[ 2 ] );
	}
	
	return PLUGIN_HANDLED;
}

public cmdMarkersRemove( id ) {
	if( get_user_flags( id ) & ADMIN_LEVEL ) {
		new iOldMarker = gMarkersCount - 1;
		
		if( iOldMarker >= 0 ) {
			if( pev_valid( gMarkerEnt[ iOldMarker ] ) )
				remove_entity( gMarkerEnt[ iOldMarker ] );
			
			--gMarkersCount;
			
			ColorChat( id, RED, "%s^x01 Delete Markersx04 #%i^x01 (^x04%f %f %f^x01).", PREFIX, iOldMarker + 1, gflMarkerPos[ iOldMarker ][ 0 ], gflMarkerPos[ iOldMarker ][ 1 ], gflMarkerPos[ iOldMarker ][ 2 ] );
		} else
			ColorChat( id, RED, "%s^x01 There's no markers at this time.", PREFIX );
	}
	
	return PLUGIN_HANDLED;
}

public cmdMarkersNearest( id ) {
	if( get_user_flags( id ) & ADMIN_LEVEL ) {
		new iMarker = GetNearestMarker( id );
		
		if( iMarker > 0 )
			ColorChat( id, RED, "%s^x01 There's no markers at this time^x04 %i^x01 号标记点.", PREFIX, iMarker );
		else
			ColorChat( id, RED, "%s^x01 There's no markers at this time.", PREFIX );
	}
	
	return PLUGIN_HANDLED;
}

// GET PLAYERS ORIGIN TO FLOOR
//////////////////////////////////////////////////
GetPlayerOrigin( id, Float:vOrigin[ 3 ] ) {
	pev( id, pev_origin, vOrigin );
	
	vOrigin[ 2 ] -= 30;
	
	if( pev( id, pev_flags ) & FL_DUCKING )
		vOrigin[ 2 ] += 18;
}

// GET NEAREST MARKER TO PLAYER
//////////////////////////////////////////////////
GetNearestMarker( id ) {
	static iNum;
	iNum = 0;
	
	if( gMarkersCount > 0 ) {
		static Float:vOrigin[ 3 ], Float:flDistance, Float:flNearest, i;
		pev( id, pev_origin, vOrigin );
		
		flDistance = 0.0;
		flNearest = vector_distance( vOrigin, gflMarkerPos[ 0 ] );
		iNum = 1;
		
		for( i = 0; i < gMarkersCount; i++ ) {
			flDistance = vector_distance( vOrigin, gflMarkerPos[ i ] );
			
			if( flDistance < flNearest ) {
				flNearest = flDistance;
				iNum = i + 1;
			}
		}
	}
	
	return iNum;
}

GetNearestMarkerByOrigin( Float:vOrigin[ 3 ] ) {
	static iNum;
	iNum = 0;
	
	if( gMarkersCount > 0 ) {
		static Float:flDistance, Float:flNearest, i;
		
		flDistance = 0.0;
		flNearest = vector_distance( vOrigin, gflMarkerPos[ 0 ] );
		iNum = 1;
		
		for( i = 0; i < gMarkersCount; i++ ) {
			flDistance = vector_distance( vOrigin, gflMarkerPos[ i ] );
			
			if( flDistance < flNearest ) {
				flNearest = flDistance;
				iNum = i + 1;
			}
		}
	}
	
	return iNum;
}

// SHOW / HIDE MARKERS
//////////////////////////////////////////////////
ShowMarkers( ) {
	if( !gbMarkersVisible ) {
		for( new i = 0; i < gMarkersCount; i++ )
			gMarkerEnt[ i ] = CreateMarker( gflMarkerPos[ i ] );
	
		gbMarkersVisible = true;
	}
}

HideMarkers( ) {
	new iEntity = FM_NULLENT;
	
	while( ( iEntity = find_ent_by_class( iEntity, "pasla_cup_marker" ) ) )
		remove_entity( iEntity );
	
	gbMarkersVisible = false;
}

// CREATE FAKE MARKER
//////////////////////////////////////////////////
CreateMarker( Float:vOrigin[ 3 ] ) {
	new iEntity = create_entity( "info_target" );
	
	if( !pev_valid( iEntity ) )
		return 0;
	
	set_pev( iEntity, pev_classname, "pasla_cup_marker" );
	entity_set_model( iEntity, MARKER_MODEL );
	entity_set_origin( iEntity, vOrigin );
	set_pev( iEntity, pev_angles, { 90.0, 0.0, 0.0 } );
	
	return iEntity;
}

// LOAD MARKERS
//////////////////////////////////////////////////
LoadMarkers( id = 0 ) {
	gMarkersCount = 0;
	
	if( file_exists( gszMarkersFile ) ) {
		new iLenght, iLineNum, szX[ 12 ], szY[ 12 ], szZ[ 12 ], szData[ 128 ], iSize = charsmax( szX );
		
		do {
			iLineNum = read_file( gszMarkersFile, iLineNum, szData, charsmax( szData ), iLenght );
			parse( szData, szX, iSize, szY, iSize, szZ, iSize );
			
			gflMarkerPos[ gMarkersCount ][ 0 ] = str_to_float( szX );
			gflMarkerPos[ gMarkersCount ][ 1 ] = str_to_float( szY );
			gflMarkerPos[ gMarkersCount ][ 2 ] = str_to_float( szZ );
			
			gMarkersCount++;
		} while( iLineNum > 0 );
		
		new iOldMarker = gMarkersCount - 1;
		
		if( iOldMarker >= 0 ) {
			if( pev_valid( gMarkerEnt[ iOldMarker ] ) )
				remove_entity( gMarkerEnt[ iOldMarker ] );
			
			--gMarkersCount;
		}
		
		if( id > 0 )
			ColorChat( id, RED, "%s^x01 Loaded^x04 %i^x01 cup markers.", PREFIX, gMarkersCount );
	} else {
		if( id > 0 )
			ColorChat( id, RED, "%s^x04 %s^x01 does not exist.", PREFIX, gszMarkersFile );
	}
}


// SAVE MARKERS
//////////////////////////////////////////////////
SaveMarkers( id ) {
	if( file_exists( gszMarkersFile ) )
		delete_file( gszMarkersFile );
	
	new szLine[ 128 ];
	for( new i = 0; i < gMarkersCount; i++ ) {
		format( szLine, charsmax( szLine ), "%f %f %f", gflMarkerPos[ i ][ 0 ], gflMarkerPos[ i ][ 1 ], gflMarkerPos[ i ][ 2 ] );
		write_file( gszMarkersFile, szLine );
	}
	
	ColorChat( id, RED, "%s^x01 save^x04 %i^x01 points.", PREFIX, gMarkersCount );
}

// OTHER STUFF
/////////////////////////////////////////////
ForceDuck( id ) {
	set_pev( id, pev_flags, pev(id, pev_flags) | FL_DUCKING );
	engfunc( EngFunc_SetSize, id, {-16.0, -16.0, -18.0 }, { 16.0,  16.0,  18.0 } );
}

Splash( id ) {
	if( gUserConnected[ id ] ) {
		new Float:vOrigin[3];
		pev( id, pev_origin, vOrigin );
		
		message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
		write_byte( TE_TELEPORT );
		engfunc( EngFunc_WriteCoord, vOrigin[0] );
		engfunc( EngFunc_WriteCoord, vOrigin[1] );
		engfunc( EngFunc_WriteCoord, vOrigin[2] );
		message_end( );
	}
}

public CheckCupPos(id)
{
	gCheckCupPos[id] = !gCheckCupPos[id];

	if(gCheckCupPos[id])
	{
		ColorChat( id, RED, "^4%s^1 status of cup end display: ^3%s ", PREFIX,  gCheckCupPos[id] ? "开":"关" );
	}
	else
	{
		ColorChat( id, RED, "^4%s^1 status of cup end display: ^3%s ", PREFIX, gCheckCupPos[id] ? "开":"关"  );

	}
	return PLUGIN_HANDLED;
}

public MsgBar(id)
{
	message_begin( MSG_ONE , g_msgBarTime , {0,0,0} , id );
	write_short( 10 );
	message_end();
}


public onResetHUD(id, level, cid)
{
	HudApplyCVars();
	new iHideFlags = GetHudHideFlags();
	if(iHideFlags)
	{
		message_begin(MSG_ONE, g_msgHideWeapon, _, id);
		write_byte(iHideFlags);
		message_end();
	}	
}

GetHudHideFlags()
{
	new iFlags;

	if( g_bHideTimer )
		iFlags |= HUD_HIDE_TIMER;

	return iFlags;
}

public msgHideWeapon()
{
	new iHideFlags = GetHudHideFlags();
	if(iHideFlags)
		set_msg_arg_int(1, ARG_BYTE, get_msg_arg_int(1) | iHideFlags);
}

HudApplyCVars()
{
	g_bHideTimer = bool:get_pcvar_num(kz_hidetime);
}


// ALIVE SHIT
/////////////////////////////////////////////
public client_putinserver( id ) {
	gUserConnected[ id ] = true;
	gUserIsAlive[ id ] = false;
	gUserIsBOT[ id ] = bool:( is_user_bot( id ) );
	gCheckCupPos[id] = true;
}

public client_disconnect( id ) {
	gUserConnected[ id ] = false;
	gUserIsAlive[ id ] = false;
	gUserIsBOT[ id ] = false;
	gCheckCupPos[id] = true;
}

public Event_Health( id ) gUserIsAlive[ id ] = is_user_alive( id );
https://imagesharing.com//photo.php?s=3yk5egmb

Last edited by wAyz; 09-25-2020 at 12:52.
wAyz is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 09-25-2020 , 11:50   Re: Cup plugin sort problem
Reply With Quote #2

I was writing big answer and trying to change calculation of the method but at the end i figured out its not catching AT ALL which marker you touched but which marker is NEAREST you, which means we dont know if you already passed that marker or you are very close to new marker, which is not the idea which i like to have in cup plugins

with having register_touch and storing all players last touched marker, it will be totally different story, but with the current code you sent i have no idea how to implement your plan :/

ps: hi wayz, im glad you are back at kz! also its cool im seeing my part of codes into other's cup plugins

EDIT: if the problem only happens for 100% passed markers, adding of detecting buttons will be ez-fix, though adding your plan (with different percentages of 100) in this code i think can not be made..but i hope im wrong, good luck!
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...)

Last edited by JocAnis; 09-25-2020 at 11:54.
JocAnis is offline
wAyz
Senior Member
Join Date: Feb 2010
Location: Germany
Old 09-25-2020 , 13:19   Re: Cup plugin sort problem
Reply With Quote #3

Quote:
Originally Posted by JocAnis View Post
I was writing big answer and trying to change calculation of the method but at the end i figured out its not catching AT ALL which marker you touched but which marker is NEAREST you, which means we dont know if you already passed that marker or you are very close to new marker, which is not the idea which i like to have in cup plugins

with having register_touch and storing all players last touched marker, it will be totally different story, but with the current code you sent i have no idea how to implement your plan :/

ps: hi wayz, im glad you are back at kz! also its cool im seeing my part of codes into other's cup plugins

EDIT: if the problem only happens for 100% passed markers, adding of detecting buttons will be ez-fix, though adding your plan (with different percentages of 100) in this code i think can not be made..but i hope im wrong, good luck!
hey, thanks for your fast reply!
I thought about it once again and came to the conclusion that it would be the best just to add button detection to fix it. Though I have no real clue how to realize it.

Last edited by wAyz; 09-25-2020 at 13:43.
wAyz 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 20:18.


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