#using scripts\codescripts\struct; #using scripts\shared\util_shared; #using scripts\mp\gametypes\_dev; #using scripts\mp\gametypes\_globallogic_utils; #using scripts\mp\_util; #namespace gameadvertisement; function init() { /# level.sessionAdvertStatus = true; thread sessionAdvertismentUpdateDebugHud(); #/ level.gameAdvertisementRuleScorePercent = GetGametypeSetting( "gameAdvertisementRuleScorePercent" ); level.gameAdvertisementRuleTimeLeft = ( 1000 * 60 ) * GetGametypeSetting( "gameAdvertisementRuleTimeLeft" ); level.gameAdvertisementRuleRound = GetGametypeSetting( "gameAdvertisementRuleRound" ); level.gameAdvertisementRuleRoundsWon = GetGametypeSetting( "gameAdvertisementRuleRoundsWon" ); thread sessionAdvertisementCheck(); } function setAdvertisedStatus( onOff ) { /# level.sessionAdvertStatus = onOff; #/ changeAdvertisedStatus( onOff ); } function sessionAdvertisementCheck() { if( SessionModeIsPrivate() ) return; runRules = getGameTypeRules(); if( !isdefined( runRules ) ) return; level endon( "game_end" ); level waittill( "prematch_over" ); currentAdvertisedStatus = undefined; while( true ) { sessionAdvertCheckwait = GetDvarInt( "sessionAdvertCheckwait", 1 ); wait( sessionAdvertCheckwait ); advertise = [[runRules]](); if ( !isdefined( currentAdvertisedStatus ) || ( isdefined( advertise ) && ( currentAdvertisedStatus != advertise ) ) ) { setAdvertisedStatus( advertise ); } currentAdvertisedStatus = advertise; } } function getGameTypeRules() { gametype = level.gametype; switch( gametype ) { case "gun": return &gun_rules; default: return &default_rules; } return; } function teamScoreLimitCheck( ruleScorePercent, debug_count ) { scoreLimit = 0; //==================================================================== // score check if ( level.roundScoreLimit ) { scoreLimit = util::get_current_round_score_limit(); } else if ( level.scoreLimit ) { scoreLimit = level.scoreLimit; } if ( scoreLimit ) { minScorePercentageLeft = 100; foreach ( team in level.teams ) { scorePercentageLeft = 100 - ( ( game[ "teamScores" ][ team ] / scoreLimit ) * 100 ); if( minScorePercentageLeft > scorePercentageLeft ) minScorePercentageLeft = scorePercentageLeft; if( ruleScorePercent >= scorePercentageLeft ) { /# debug_count = updateDebugHud( debug_count, "Score Percentage Left: ", int( scorePercentageLeft ) ); #/ return false; } } /# debug_count = updateDebugHud( debug_count, "Score Percentage Left: ", int( minScorePercentageLeft ) ); #/ } return true; } function timeLimitCheck( ruleTimeLeft ) { maxTime = level.timeLimit; if( maxTime != 0 ) { timeLeft = globallogic_utils::getTimeRemaining(); if( ruleTimeLeft >= timeLeft ) { return false; } } return true; } //======================================================================================================================================== //======================================================================================================================================== //======================================================================================================================================== function default_rules() { //==================================================================== currentRound = game[ "roundsplayed" ] + 1; debug_count = 1; //==================================================================== //==================================================================== // score check if( level.gameAdvertisementRuleScorePercent ) { /# debug_count = updateDebugHud( debug_count, "Any player/team is within percent of score cap: ", level.gameAdvertisementRuleScorePercent ); #/ if ( level.teambased ) { if ( (currentRound >= (level.gameAdvertisementRuleRound - 1)) ) { if ( teamScoreLimitCheck( level.gameAdvertisementRuleScorePercent, debug_count ) == false ) return false; /# debug_count++; #/ } } else { if ( level.scoreLimit ) { highestScore = 0; players = GetPlayers(); for( i = 0; i < players.size; i++) { if( players[i].pointstowin > highestScore ) highestScore = players[i].pointstowin; } scorePercentageLeft = 100 - ( ( highestScore / level.scoreLimit ) * 100 ); /# debug_count = updateDebugHud( debug_count, "Score Percentage Left: ", int( scorePercentageLeft ) ); #/ if( level.gameAdvertisementRuleScorePercent >= scorePercentageLeft ) { return false; } } } } //==================================================================== // time left check if( level.gameAdvertisementRuleTimeLeft && (currentRound >= (level.gameAdvertisementRuleRound - 1)) ) { /# debug_count = updateDebugHud( debug_count, "Time limit has less than minutes remaining: ", level.gameAdvertisementRuleTimeLeft/( 1000 * 60 ) ); #/ if ( timeLimitCheck( level.gameAdvertisementRuleTimeLeft ) == false ) return false; } //==================================================================== // round check if( level.gameAdvertisementRuleRound ) { /# debug_count = updateDebugHud( debug_count, "Is round: ", level.gameAdvertisementRuleRound ); debug_count = updateDebugHud( debug_count, "Current Round: ", currentRound ); #/ if ( level.gameAdvertisementRuleRound <= currentRound ) return false; } //==================================================================== // round won check if ( level.gameAdvertisementRuleRoundsWon ) { /# debug_count = updateDebugHud( debug_count, "Any team has won rounds: ", level.gameAdvertisementRuleRoundsWon ); #/ maxRoundsWon = 0; foreach ( team in level.teams ) { roundsWon = game[ "teamScores" ][ team ]; if( maxRoundsWon < roundsWon ) maxRoundsWon = roundsWon; if( level.gameAdvertisementRuleRoundsWon <= roundsWon ) { /# debug_count = updateDebugHud( debug_count, "Max Rounds Won: ", maxRoundsWon ); #/ return false; } } /# debug_count = updateDebugHud( debug_count, "Max Rounds Won: ", maxRoundsWon ); #/ } return true; } function gun_rules() { // Any player is within 3 weapons from winning //==================================================================== ruleWeaponsLeft = 3; // within 3 weapons of winning //==================================================================== /# updateDebugHud( 1, "Any player is within X weapons from winning: ", ruleWeaponsLeft ); #/ //==================================================================== // weapons check minWeaponsLeft = level.gunProgression.size; foreach ( player in level.activePlayers ) { if ( !isdefined( player ) ) continue; if ( !isdefined( player.gunProgress ) ) continue; weaponsLeft = level.gunProgression.size - player.gunProgress; if( minWeaponsLeft > weaponsLeft ) minWeaponsLeft = weaponsLeft; if( ruleWeaponsLeft >= minWeaponsLeft ) { /# updateDebugHud( 3, "Weapons Left: ", minWeaponsLeft ); #/ return false; } } /# updateDebugHud( 3, "Weapons Left: ", minWeaponsLeft ); #/ return true; } //======================================================================================================================================== //======================================================================================================================================== //======================================================================================================================================== /# function sessionAdvertismentCreateDebugHud( lineNum, alignX ) { debug_hud = dev::new_hud( "session_advert", "debug_hud", 0, 0, 1 ); debug_hud.hidewheninmenu = true; debug_hud.horzAlign = "right"; debug_hud.vertAlign = "middle"; debug_hud.alignX = "right"; debug_hud.alignY = "middle"; debug_hud.x = alignX; debug_hud.y = -50 + (lineNum * 15); debug_hud.foreground = true; debug_hud.font = "default"; debug_hud.fontScale = 1.5; debug_hud.color = ( 1.0, 1.0, 1.0 ); debug_hud.alpha = 1; debug_hud setText( "" ); return debug_hud; } function updateDebugHud( hudIndex, text, value ) { switch( hudIndex ) { case 1: level.sessionAdvertHud_1A_text = text; level.sessionAdvertHud_1B_text = value; break; case 2: level.sessionAdvertHud_2A_text = text; level.sessionAdvertHud_2B_text = value; break; case 3: level.sessionAdvertHud_3A_text = text; level.sessionAdvertHud_3B_text = value; break; case 4: level.sessionAdvertHud_4A_text = text; level.sessionAdvertHud_4B_text = value; break; } return hudIndex+1; } function sessionAdvertismentUpdateDebugHud() { level endon( "game_end" ); sessionAdvertHud_0 = undefined; sessionAdvertHud_1A = undefined; sessionAdvertHud_1B = undefined; sessionAdvertHud_2A = undefined; sessionAdvertHud_2B = undefined; sessionAdvertHud_3A = undefined; sessionAdvertHud_3B = undefined; sessionAdvertHud_4A = undefined; sessionAdvertHud_4B = undefined; level.sessionAdvertHud_0_text = ""; level.sessionAdvertHud_1A_text = ""; level.sessionAdvertHud_1B_text = ""; level.sessionAdvertHud_2A_text = ""; level.sessionAdvertHud_2B_text = ""; level.sessionAdvertHud_3A_text = ""; level.sessionAdvertHud_3B_text = ""; level.sessionAdvertHud_4A_text = ""; level.sessionAdvertHud_4B_text = ""; while( true ) { wait( 1 ); showDebugHud = GetDvarInt( "sessionAdvertShowDebugHud", 0 ); //==================================================================== level.sessionAdvertHud_0_text = "Session is advertised"; if( level.sessionAdvertStatus == false ) level.sessionAdvertHud_0_text = "Session is not advertised"; //==================================================================== if( !isdefined( sessionAdvertHud_0 ) && showDebugHud != 0 ) { host = util::getHostPlayer(); if( !isdefined( host ) ) continue; sessionAdvertHud_0 = host sessionAdvertismentCreateDebugHud( 0, 0 ); sessionAdvertHud_1A = host sessionAdvertismentCreateDebugHud( 1, -20 ); sessionAdvertHud_1B = host sessionAdvertismentCreateDebugHud( 1, 0 ); sessionAdvertHud_2A = host sessionAdvertismentCreateDebugHud( 2, -20 ); sessionAdvertHud_2B = host sessionAdvertismentCreateDebugHud( 2, 0 ); sessionAdvertHud_3A = host sessionAdvertismentCreateDebugHud( 3, -20 ); sessionAdvertHud_3B = host sessionAdvertismentCreateDebugHud( 3, 0 ); sessionAdvertHud_4A = host sessionAdvertismentCreateDebugHud( 4, -20 ); sessionAdvertHud_4B = host sessionAdvertismentCreateDebugHud( 4, 0 ); sessionAdvertHud_1A.color = ( 0.0, 0.5, 0.0 ); sessionAdvertHud_1B.color = ( 0.0, 0.5, 0.0 ); sessionAdvertHud_2A.color = ( 0.0, 0.5, 0.0 ); sessionAdvertHud_2B.color = ( 0.0, 0.5, 0.0 ); } if( isdefined( sessionAdvertHud_0 ) ) { if( showDebugHud == 0 ) { sessionAdvertHud_0 destroy(); sessionAdvertHud_1A destroy(); sessionAdvertHud_1B destroy(); sessionAdvertHud_2A destroy(); sessionAdvertHud_2B destroy(); sessionAdvertHud_3A destroy(); sessionAdvertHud_3B destroy(); sessionAdvertHud_4A destroy(); sessionAdvertHud_4B destroy(); sessionAdvertHud_0 = undefined; sessionAdvertHud_1A = undefined; sessionAdvertHud_1B = undefined; sessionAdvertHud_2A = undefined; sessionAdvertHud_2B = undefined; sessionAdvertHud_3A = undefined; sessionAdvertHud_3B = undefined; sessionAdvertHud_4A = undefined; sessionAdvertHud_4B = undefined; } else { if( level.sessionAdvertStatus == true ) sessionAdvertHud_0.color = ( 1.0, 1.0, 1.0 ); else sessionAdvertHud_0.color = ( 0.9, 0.0, 0.0 ); sessionAdvertHud_0 setText( level.sessionAdvertHud_0_text ); if( level.sessionAdvertHud_1A_text != "" ) { sessionAdvertHud_1A setText( level.sessionAdvertHud_1A_text ); sessionAdvertHud_1B setValue( level.sessionAdvertHud_1B_text ); } if( level.sessionAdvertHud_2A_text != "" ) { sessionAdvertHud_2A setText( level.sessionAdvertHud_2A_text ); sessionAdvertHud_2B setValue( level.sessionAdvertHud_2B_text ); } if( level.sessionAdvertHud_3A_text != "" ) { sessionAdvertHud_3A setText( level.sessionAdvertHud_3A_text ); sessionAdvertHud_3B setValue( level.sessionAdvertHud_3B_text ); } if( level.sessionAdvertHud_4A_text != "" ) { sessionAdvertHud_4A setText( level.sessionAdvertHud_4A_text ); sessionAdvertHud_4B setValue( level.sessionAdvertHud_4B_text ); } } } } } #/