• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Hunting for Desyncs - (Team Rush - formally Team Assault)

Status
Not open for further replies.
Level 4
Joined
Jun 8, 2004
Messages
66
I've been trying for a bit over a week now to try to narrow down the cause of a deync on my map with not much success. Would it be possible for some people to look over my code and look for any obvious memory leaks or anything that would likely cause a desync?

I can't say with any certainty of when it happens anymore, but my guess is around the death/revival of heroes. I've attached the entire map plus below is the majority of the code for the map, where I believe the desync may be occuring.


HOWEVER

After one final search of the forums I did find one promising possibility that would explain a possible cause of the desync.

Leopard said:
when you create 2 triggers with same event, the executing sequence for those trigger cannot be determined. sometimes one trigger executed first, but sometimes vice versa.

I have a couple of triggers that currently execute using the same event type, so if the above is true, those could cause a desync.

JASS:
////////////////////////////////////////////////
// Unit Creation Functions (replacement for the BJ stuff
//////////////////////////////////////////////////

function jrp_create_units_at_loc takes integer count, integer unitId, player whichPlayer, location loc, real face returns nothing
// Cleaned up and modified variation of the blizzard one.  Saves cycles and doesn't leak
    loop
        set count = count - 1
        exitwhen count < 0
		call CreateUnitAtLoc(whichPlayer, unitId, loc, face)
    endloop
endfunction

function jrp_create_and_return_unit_at_loc takes integer unitId, player whichPlayer, location loc, real face returns unit
// Cleaned up and modified variation of the blizzard one.  Saves cycles and doesn't leak
    return CreateUnitAtLoc(whichPlayer, unitId, loc, face)
endfunction

function jrp_create_and_destroy_effect takes location tpoint, string model returns nothing
// Quickly creates and destroys effects.  Doesn't destroy the location so you can reuse the location until you don't need it.
	local effect tempeffect
	set tempeffect = AddSpecialEffectLoc(model,tpoint)
	call DestroyEffect(tempeffect)
	set tempeffect = null
endfunction

////////////////////////////////////////////////
// Effect creation functions (replacement for BJ stuff
//////////////////////////////////////////////////

function jrp_create_effect takes location tpoint, string model returns effect
// Quickly creates and destroys effects.  Doesn't destroy the location so you can reuse the location until you don't need it.
	return AddSpecialEffectLoc(model,tpoint)
endfunction

function jrp_add_effect_on_unit takes string attachPointName, widget targetWidget, string modelName returns effect
	// Cleaned up variation of the BJ version
    return AddSpecialEffectTarget(modelName, targetWidget, attachPointName)
endfunction

function jrp_add_and_destroy_effect_on_unit takes string attachPointName, widget targetWidget, string modelName returns nothing
//Quickly creates and destroys effect
	local effect tempeffect
	set tempeffect = AddSpecialEffectTarget(modelName, targetWidget, attachPointName)
	call DestroyEffect(tempeffect)
	set tempeffect = null
endfunction

////////////////////////////////////////////////
// Territory defense squad
//////////////////////////////////////////////////

// Tower defense squad! To the rescue!
function jrp_spawn_territory_defense_squad takes player squadplayer, location targloc returns nothing
	local location tpoint1
	
	set tpoint1 = OffsetLocation(targloc, 200.00, 200.00)
		call jrp_create_units_at_loc( 1, 'earc', squadplayer, tpoint1, bj_UNIT_FACING )
		call jrp_create_and_destroy_effect( tpoint1, "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" )
	call RemoveLocation( tpoint1 )
	set tpoint1 = OffsetLocation(targloc, -200.00, 200.00)
		call jrp_create_units_at_loc( 1, 'earc', squadplayer, tpoint1, bj_UNIT_FACING )
		call jrp_create_and_destroy_effect( tpoint1, "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" )
	call RemoveLocation( tpoint1 )
	set tpoint1 = OffsetLocation(targloc, 200.00, -200.00)
		call jrp_create_units_at_loc( 1, 'earc', squadplayer, tpoint1, bj_UNIT_FACING )
		call jrp_create_and_destroy_effect( tpoint1, "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" )
	call RemoveLocation( tpoint1 )
	set tpoint1 = OffsetLocation(targloc, -200.00, -200.00)
		call jrp_create_units_at_loc( 1, 'earc', squadplayer, tpoint1, bj_UNIT_FACING )
		call jrp_create_and_destroy_effect( tpoint1, "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" )
	call RemoveLocation( tpoint1 )

	// Luckily we clean up the targloc too
	call RemoveLocation( targloc )

endfunction

////////////////////////////////////////////////
// Item Drops (creeps)
//////////////////////////////////////////////////

function jrp_creep_drop_item takes location mloc returns nothing

	local integer array types_runes
	local integer array types_rareweapons
	local integer typestotal_runes = 5
	local integer typestotal_rareweapons = 3

	// I like to start from 1
	
	// Rune of lesser healing (area)
	set types_runes[1] = 'rhel'
	// Rune of mana (area)
	set types_runes[2] = 'rman'
	// rune of dispel magic (area)
	set types_runes[3] = 'rdis'
	// Rune of speed (large area)
	set types_runes[4] = 'rspd'
	// Rune of shielding (blocks a spell)
	set types_runes[5] = 'rsps'
	
	// Neobezo
	set types_rareweapons[1] = 'frgd'
	// The UberMaster
	set types_rareweapons[2] = 'srtl'
	// L33t Curry (not a weapon, unless you know how to use 
	set types_rareweapons[3] = 'pghe'
	

	// *** Script order ***
	// Decide whether or not to drop anything at all
	// Decide which class to drop from
	// Choose out of the class what to drop

	// Should we drop anything at all?
	if (GetRandomInt(1,5) > 2) then
		// Should we drop a rune
		if (GetRandomInt(1,3) == 2) then
	        call CreateItemLoc( types_runes[GetRandomInt(1, typestotal_runes)], mloc )
		else
			// Rare weapon drops
			if (GetRandomInt(1,30) == 1) then
		        call CreateItemLoc( types_rareweapons[GetRandomInt(1, typestotal_rareweapons)], mloc )
			else
			endif
		endif
		call RemoveLocation( mloc )
	else
		call RemoveLocation( mloc )
		return
	endif

endfunction

////////////////////////////////////////////////
// Send messages to specific players rather than groups (more easily)
//////////////////////////////////////////////////

function jrp_msg_to_playerid takes integer playerid, string message returns nothing
	call DisplayTextToForce( udg_Singleplayer_Groups[playerid], message )
endfunction

////////////////////////////////////////////////
// Chat commands (or events)
//////////////////////////////////////////////////

function jrp_ce_website takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Map Website|r - www.jrpereira.com/warcraft3/team_assault" )
endfunction

function jrp_ce_help takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Help|r - Press F9 for detailed information about this map." )
endfunction

function jrp_ce_repick takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Repicking|r - The goblin merchant sells a hero repick item for 250 gold.  There is one right near your spawn area." )
endfunction

function jrp_ce_commands takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Chat Commands|r : -website, -help, -repick, -classinfo [classname]" )
endfunction

function jrp_ce_heroinfo takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	
	local string array classnames
	local string array classinfos
	local string msgtemp
	local integer intA = 0
	local integer intAEnd = 9
	local string classtype = SubStringBJ(GetEventPlayerChatString(), 11, 23)
	
	set classnames[0] = "Scholar"
	set classnames[1] = "Scout"
	set classnames[2] = "Assassin"
	set classnames[3] = "Priest"
	set classnames[4] = "Mage"
	set classnames[5] = "Berserker"
	set classnames[6] = "Brute"
	set classnames[7] = "Necromancer"
	set classnames[8] = "Builder"
	set classnames[9] = "Ranger"
	
	set classinfos[0] = "Great against magic users, and also excels at providing the team with a constant influx of mana."
	set classinfos[1] = "Fastest and best scouting unit in the game.  Also is excellent at capturing territories and transporting teammates."
	set classinfos[2] = "Excellent close-range killer - able to kill off enemies one at a time and disappear without a trace."
	set classinfos[3] = "Can heal and protect the team using a variety of very potent abilities.  Also the only class that can revive teammates."
	set classinfos[4] = "Can do a lot of damage in a very large area, but is relatively frail and vulnerable if not defended."
	set classinfos[5] = "Can do damage to a lot of enemies up close, and can take a fair amount of damage.  Great for clearing swarms of units."
	set classinfos[6] = "The most difficult hero to kill in a straight fight, and can absorb a lot of damage.  Can stun and taunt very well."
	set classinfos[7] = "Can create legions of undead units to attack the enemy.  Great against single-target attackers."
	set classinfos[8] = "Great for defending territories and supporting the team.  Also can absorb a fair amount of damage."
	set classinfos[9] = "Best at taking out single targets from afar - can do massive damage with its snipe ability.  Is very vulnerable up close."
	
	loop
	exitwhen intA > intAEnd
		if ( StringCase(classtype, false) == StringCase(classnames[intA], false) ) then
			call jrp_msg_to_playerid( playerid, "|c00FFCC00" + classnames[intA] + "|r - " + classinfos[intA] )
			return
		endif
	set intA = intA + 1
	endloop
	
	set msgtemp = "Scholar, Scout, Assassin, Priest, Mage, Berserker, Brute, Necromancer, Builder, Ranger"
	
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Heroinfo|r - Valid heroes are: " + msgtemp )
endfunction

function jrp_ce_tips_off takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	set udg_Player_TipsOn[playerid] = false
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Tips Off|r - The tips system is now off." )
endfunction

function jrp_ce_tips_on takes nothing returns nothing
	local integer playerid = GetConvertedPlayerId(GetTriggerPlayer())
	set udg_Player_TipsOn[playerid] = true
	call jrp_msg_to_playerid( playerid, "|c00FFCC00Tips On|r - The tips system is now on." )
endfunction

// Allows you to quickly set up a chat event
function jrp_register_chat_event takes string chatstring, code trigaction, boolean exactmatch returns nothing
	local integer intA = 0
	local integer intAEnd = 11
	local trigger newtrigger = CreateTrigger(  )
	
	loop
	exitwhen intA > intAEnd
		call TriggerRegisterPlayerChatEvent( newtrigger, Player(intA), chatstring, exactmatch )
	set intA = intA + 1
	endloop
	
    call TriggerAddAction( newtrigger, trigaction )
endfunction

////////////////////////////////////////////////
// Miscellaneous
//////////////////////////////////////////////////

function jrp_playerstatusmatcher takes string checkstatus, player checkplayer returns boolean
	// Just a quick way to return status if you want to check if it's in a group plus matches status

	if ( (checkstatus == "not_isplaying") and (GetPlayerSlotState(checkplayer) != PLAYER_SLOT_STATE_PLAYING) ) then
		return true
	endif

	if ( (checkstatus == "isplaying") and (GetPlayerSlotState(checkplayer) == PLAYER_SLOT_STATE_PLAYING) ) then
		return true
	endif

	if ( (checkstatus == "hasleft") and (GetPlayerSlotState(checkplayer) == PLAYER_SLOT_STATE_LEFT) ) then
		return true
	endif

	if ( (checkstatus == "not_hasleft") and (GetPlayerSlotState(checkplayer) != PLAYER_SLOT_STATE_LEFT) ) then
		return true
	endif

	if ( (checkstatus == "unused") and (GetPlayerSlotState(checkplayer) == PLAYER_SLOT_STATE_EMPTY) ) then
		return true
	endif

	if ( (checkstatus == "not_unused") and (GetPlayerSlotState(checkplayer) != PLAYER_SLOT_STATE_EMPTY) ) then
		return true
	endif

	return false

endfunction


// Used in forgroup commands - removes all units
function jrp_forgroup_removeunit takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function jrp_isplayerinarray takes integer startindex, integer endindex, player checkthisplayer, string statuscheck returns boolean
	// This just checks if a player is in a player array, using start and end indexes so you can specify if it matches a certain list of players in an array (like player 1-4 and 5-8 to seperate betweeng good and evil)
	
	loop
		exitwhen(startindex > endindex)
		if ( (udg_Players[startindex] == checkthisplayer) and (jrp_playerstatusmatcher(statuscheck,checkthisplayer)) ) then
			return true
		endif
		set startindex = startindex + 1
	endloop

	return false
endfunction

// Used in forgroup commands - sets unit side
function jrp_forgroup_set_team_red takes nothing returns nothing
	call SetUnitOwner( GetEnumUnit(), Player(0), true )
endfunction

// Used in forgroup commands - sets unit side
function jrp_forgroup_set_team_blue takes nothing returns nothing
	call SetUnitOwner( GetEnumUnit(), Player(6), true )
endfunction

// Used in forgroup commands - sets unit side
function jrp_forgroup_set_team_nhostile takes nothing returns nothing
	call SetUnitOwner( GetEnumUnit(), Player(PLAYER_NEUTRAL_AGGRESSIVE), true )
endfunction

function jrp_make_enum_invulnerable takes nothing returns nothing
	// This bitch just refuses to work
	// call SetUnitInvulnerable( GetEnumUnit(), true )
	call UnitAddAbilityBJ( 'Avul', GetEnumUnit() )
endfunction

////////////////////////////////////////////////
// Functions that give players gold
//////////////////////////////////////////////////

// Incriment player gold
function jrp_GoldGain takes nothing returns nothing
	local integer intA = 1
	local integer intAEnd = 12

	loop
	exitwhen intA > intAEnd
		if ( jrp_playerstatusmatcher("isplaying", udg_Players[intA]) == true) then
			call SetPlayerStateBJ( udg_Players[intA], PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(udg_Players[intA], PLAYER_STATE_RESOURCE_GOLD) + 1 ) )
		endif
	set intA = intA + 1
	endloop
endfunction

// Give an array of players gold
function jrp_give_player_range_gold takes integer startplayer, integer endplayer, integer goldvalue returns nothing

	loop
	exitwhen startplayer > endplayer
		if ( jrp_playerstatusmatcher("isplaying", udg_Players[startplayer]) == true) then
			call SetPlayerStateBJ( udg_Players[startplayer], PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(udg_Players[startplayer], PLAYER_STATE_RESOURCE_GOLD) + goldvalue ) )
		endif
	set startplayer = startplayer + 1
	endloop
endfunction

function jrp_give_player_random_hero takes player thisplayer returns nothing
	local location temploc
	local integer array classtypes
	
	set classtypes[0] = 'Ekee'
	set classtypes[1] = 'Emoo'
	set classtypes[2] = 'Ewar'
	set classtypes[3] = 'Hamg'
	set classtypes[4] = 'Hblm'
	set classtypes[5] = 'Obla'
	set classtypes[6] = 'Otch'
	set classtypes[7] = 'Ulic'
	set classtypes[8] = 'Nalc'
	set classtypes[9] = 'Hvwd'
	
	set temploc = GetRectCenter(gg_rct_Class_Select_Area)
	call jrp_create_units_at_loc( 1, classtypes[GetRandomInt(0, 9)], thisplayer, temploc, bj_UNIT_FACING )
	call RemoveLocation( temploc )
endfunction

function jrp_make_player_choose_class takes player choosingplayer returns nothing
	local location temploc
	
	if ( (jrp_playerstatusmatcher("isplaying",choosingplayer) == true) and (GetPlayerController(choosingplayer) != MAP_CONTROL_COMPUTER) ) then 
	
		set temploc = GetRectCenter(gg_rct_Class_Select_Area)
		call jrp_create_units_at_loc( 1, 'ewsp', choosingplayer, temploc, bj_UNIT_FACING )
		call RemoveLocation( temploc )
		set temploc = GetRectCenter(gg_rct_Class_Select_Area)
		call SetCameraPositionLocForPlayer( choosingplayer, temploc )
		call RemoveLocation( temploc )	
		
		// Let them know it's time to choose
		call DisplayTextToForce( udg_Singleplayer_Groups[GetConvertedPlayerId(choosingplayer)], "Time to |c00FFCC00choose a hero|r.  |c0000FFFFYou can repick|r for 250 gold at the goblin merchant." )

		// Gotta have lumber to choose a hero
		call SetPlayerStateBJ( choosingplayer, PLAYER_STATE_RESOURCE_LUMBER, 1 )
	else
		// Just give the player a hero
		call jrp_give_player_random_hero(choosingplayer)
	endif

endfunction

////////////////////////////////////////////////
// Respawn management
//////////////////////////////////////////////////

function jrp_respawn_counttimers takes nothing returns nothing

	local integer intA
	local integer intAEnd

	set intA = 1
	set intAEnd = 12
	loop
		exitwhen intA > intAEnd
		set udg_PlayerDeathTimers[intA] = ( udg_PlayerDeathTimers[intA] - 1 )
		if ( udg_PlayerDeathTimers[intA] < -1 ) then
			set udg_PlayerDeathTimers[intA] = -1
		endif
		set intA = intA + 1
	endloop
endfunction

// Revive a player hero, placing them at a location
// The camera moves as well so the player can get right back to their hero on revival
function jrp_revive_player_hero_at_loc takes player thisplayer, location thisloc returns nothing 
	local group tempgroup = GetUnitsOfPlayerAndTypeId(thisplayer, 'ndh1')
	call SetCameraPositionLocForPlayer( thisplayer, thisloc )
	call ReviveHeroLoc( udg_PlayerHeroes[GetConvertedPlayerId(thisplayer)], thisloc, true )
	call RemoveUnit( GroupPickRandomUnit(tempgroup) )
	call DestroyGroup( tempgroup )
endfunction

function jrp_respawn_checktimers takes nothing returns nothing

	local integer index_a
	local location temploc

	// Loop through the timer array and decide who's going to respawn
	set index_a = 1
	loop
		exitwhen (index_a > 12)
		if ( (udg_HeroDead[index_a] == true) and (udg_PlayerDeathTimers[index_a] == 0)) then
			set temploc = GetPlayerStartLocationLoc(udg_Players[index_a])
			call jrp_revive_player_hero_at_loc(udg_Players[index_a],temploc)
			call RemoveLocation( temploc )
		endif
		set index_a = index_a + 1
	endloop

endfunction

////////////////////////////////////////////////
// Capture point handlers
//////////////////////////////////////////////////

function jrp_register_cap_tower_groups takes nothing returns nothing

	local location tpoint
	local group tempgroup
	local unit tempunit
	local integer intA = 1
	local integer intAEnd = 7

	loop
		exitwhen intA > intAEnd
			set tpoint = GetRectCenter(udg_CapRects[intA])
			set tempgroup = GetUnitsInRangeOfLocAll(1500, tpoint)
			
			loop
				exitwhen(FirstOfGroup(tempgroup) == null)
				set tempunit = FirstOfGroup(tempgroup)
				if ( (GetOwningPlayer(tempunit) == Player(PLAYER_NEUTRAL_AGGRESSIVE)) and (IsUnitType(tempunit, UNIT_TYPE_STRUCTURE) == true) ) then
					call GroupAddUnitSimple( tempunit, udg_CaptureStructGroups[intA] )
					call GroupRemoveUnit(tempgroup, tempunit)
				else
					call GroupRemoveUnit(tempgroup, tempunit)
				endif
				
			endloop

			call CreateTextTagLocBJ( ("|c00FFCC00" + udg_CapPointNames[intA] + "|r"), tpoint, 300.00, 10, 100, 100, 100, 0 )
			call CreateTextTagLocBJ( "| | | | | | | | | |", tpoint, 200.00, 10, 100, 100, 100, 0 )
			set udg_CapPointTags[intA] = GetLastCreatedTextTag()

			// Cleanup
			call RemoveLocation( tpoint )
			call DestroyGroup( tempgroup )
		set intA = intA + 1
	endloop

endfunction

function jrp_add_capture_progress takes integer cappoint, string capteam returns nothing

	if (capteam == "red") then
		// Add and deduct points
		set udg_CapScoresRed[cappoint] = udg_CapScoresRed[cappoint] + 1
		set udg_CapScoresBlue[cappoint] = udg_CapScoresBlue[cappoint] - 1
		// Set maximum score
		if ( udg_CapScoresRed[cappoint] > udg_ScoreToCap ) then
			set udg_CapScoresRed[cappoint] = udg_ScoreToCap
		endif
		// Set minimum score
		if ( udg_CapScoresBlue[cappoint] < 0 ) then
			set udg_CapScoresBlue[cappoint] = 0
		endif
	endif

	if (capteam == "blue") then
		// Add and deduct points
		set udg_CapScoresBlue[cappoint] = udg_CapScoresBlue[cappoint] + 1
		set udg_CapScoresRed[cappoint] = udg_CapScoresRed[cappoint] - 1
		// Set maximum score
		if ( udg_CapScoresBlue[cappoint] > udg_ScoreToCap ) then
			set udg_CapScoresBlue[cappoint] = udg_ScoreToCap
		endif
		// Set minimum score
		if ( udg_CapScoresRed[cappoint] < 0 ) then
			set udg_CapScoresRed[cappoint] = 0
		endif
	endif	
	
endfunction

function jrp_is_point_locked takes integer cappoint returns boolean
	
	// Going to do this just straight up right now, I'm not going to save too many cycles by looping that I couldn't more easily save elsewhere with more BJ replacement.
	
	if ( cappoint == 1 ) then
		// Red defense locks it
		if ( (udg_CapOwners[2] == 1) or (udg_CapOwners[3] == 1) ) then
			return true
		endif
		return false
	endif

	if ( cappoint == 2 ) then
		// Red defense locks it
		if ( udg_CapOwners[4] != 2 ) then
			return true
		endif
		return false
	endif

	if ( cappoint == 3 ) then
		// Red defense locks it
		if ( udg_CapOwners[4] != 2 ) then
			return true
		endif
		return false
	endif

	if ( cappoint == 4 ) then
		// Red offense locks it
		if ( (udg_CapOwners[5] == 1) or (udg_CapOwners[6] == 1) ) then
			return true
		endif
		// Blue offense locks it
		if ( (udg_CapOwners[2] == 2) or (udg_CapOwners[3] == 2) ) then
			return true
		endif
		return false
	endif	

	if ( cappoint == 5 ) then
		// Blue defense locks it
		if ( udg_CapOwners[4] != 1 ) then
			return true
		endif
		return false
	endif

	if ( cappoint == 6 ) then
		// Blue defense locks it
		if ( udg_CapOwners[4] != 1 ) then
			return true
		endif
		return false
	endif	
	

	if ( cappoint == 7 ) then
		// Blue defense locks it
		if ( (udg_CapOwners[5] == 2) or (udg_CapOwners[6] == 2) ) then
			return true
		endif
		return false
	endif

	// No correct value given? return false
	return false
	
endfunction

function jrp_check_capture_progress takes nothing returns nothing

	local integer intA
	local integer intAEnd
	local integer intB
	local integer intBEnd
	
	set intA = 1
	set intAEnd = 7

	set intB = 7
	set intBEnd = 12
	loop
		exitwhen intA > intAEnd
		// Capture progress for Red Players
		set intB = 1
		set intBEnd = 6		
		loop
		exitwhen intB > intBEnd
			if ( ( RectContainsUnit(udg_CapRects[intA], udg_PlayerHeroes[intB]) == true )  and ( IsUnitAliveBJ(udg_PlayerHeroes[intB]) == true ) ) then
				if (jrp_is_point_locked(intA) != true) then
					call jrp_add_capture_progress( intA, "red")
				endif
			endif
			set intB = intB + 1
		endloop
		// Capture progress for Blue Players
		set intB = 7
		set intBEnd = 12
		loop
		exitwhen intB > intBEnd
			if ( ( RectContainsUnit(udg_CapRects[intA], udg_PlayerHeroes[intB]) == true )  and ( IsUnitAliveBJ(udg_PlayerHeroes[intB]) == true ) ) then
				if (jrp_is_point_locked(intA) != true) then
					call jrp_add_capture_progress( intA, "blue")
				endif
			endif
			set intB = intB + 1
		endloop
		set intA = intA + 1
	endloop
endfunction

function jrp_music_change_from_capture takes nothing returns nothing

	local integer intA = 1
	local integer intAEnd = 7
	local integer caps = 0
	local integer maxcaps = 0
	
	loop
	exitwhen intA > intAEnd
		if (udg_CapOwners[intA] == 1) then
			set caps = caps + 1
		endif
	set intA = intA + 1
	endloop

	set maxcaps = caps

	set intA = 1
	
	loop
	exitwhen intA > intAEnd
		if (udg_CapOwners[intA] == 2) then
			set caps = caps + 1
		endif
	set intA = intA + 1
	endloop
	
	if (caps > maxcaps) then
		set maxcaps = caps
	endif

	if ( (maxcaps == 5) and (udg_PrevMaxCaps != 4) and (udg_PrevMaxCaps != 6) ) then
		call SetMapMusicIndexedBJ( "Sound\\Music\\mp3Music\\Orc2.mp3;", 0 )
		set udg_PrevMaxCaps = maxcaps
		call PlayThematicMusicBJ( "Sound\\Music\\mp3Music\\Orc2.mp3" )
		return
	endif
	
	if ( (maxcaps == 6) and (udg_PrevMaxCaps != 5) and (udg_PrevMaxCaps != 6) ) then
		call SetMapMusicIndexedBJ( "Sound\\Music\\mp3Music\\Orc3.mp3;", 0 )
		call PlayThematicMusicExBJ( "Sound\\Music\\mp3Music\\Orc3.mp3", 49.00 )	
		set udg_PrevMaxCaps = maxcaps
		return
	endif

	if ( (maxcaps == 8) and (udg_PrevMaxCaps != 8) and (udg_PrevMaxCaps != 9) ) then
		call SetMapMusicIndexedBJ( "Sound\\Music\\mp3Music\\OrcX1.mp3;", 0 )
		call PlayThematicMusicExBJ( "Sound\\Music\\mp3Music\\OrcX1.mp3", 92.00 )
		set udg_PrevMaxCaps = maxcaps
		return
	endif
	
endfunction

function jrp_decide_cappoint_ownership takes nothing returns nothing
	local integer intA
	local integer intAEnd
	local boolean cap_made = false
	
	set intA = 1
	set intAEnd = 7
	loop
		exitwhen intA > intAEnd
		
		// Check to seeif Red captured
		if ( (udg_CapOwners[intA] != 1) and (udg_CapScoresRed[intA] == udg_ScoreToCap) ) then
			set udg_CapScoresBlue[intA] = 0
			call DisplayTextToForce( udg_P_Allplayers, ( "|c00FF0303Red Team|r has captured the |c00FFCC00 " + udg_CapPointNames[intA] ) + " |rpoint.  |c0000FFFF100|r gold has been awarded to each Red player." )
			// Play notification sound
			call PlaySoundBJ( gg_snd_ItemReceived )
			// Set owner
			set udg_CapOwners[intA] = 1
			// Set towers owner
			call ForGroupBJ( udg_CaptureStructGroups[intA], function jrp_forgroup_set_team_red )
			set cap_made = true
			call jrp_spawn_territory_defense_squad( Player(0), GetRectCenter(udg_CapRects[intA]))
			call jrp_give_player_range_gold(1, 6, 100)
		endif
		
		// Check to seeif Blue captured
		if ( (udg_CapOwners[intA] != 2) and (udg_CapScoresBlue[intA] == udg_ScoreToCap) ) then
			set udg_CapScoresRed[intA] = 0
			call DisplayTextToForce( udg_P_Allplayers, ( "|c000042FFBlue Team|r has captured the |c00FFCC00 " + udg_CapPointNames[intA] ) + " |rpoint.  |c0000FFFF100|r gold has been awarded to each Blue player." )
			// Play notification sound
			call PlaySoundBJ( gg_snd_ItemReceived )
			// Set owner
			set udg_CapOwners[intA] = 2
			// Set towers owner
			call ForGroupBJ( udg_CaptureStructGroups[intA], function jrp_forgroup_set_team_blue )
			set cap_made = true
			call jrp_spawn_territory_defense_squad( Player(6), GetRectCenter(udg_CapRects[intA]))
			call jrp_give_player_range_gold(7, 12, 100)
		endif		
		
		set intA = intA + 1
	endloop

	if (cap_made == true) then
		call jrp_music_change_from_capture()
	endif

endfunction

function jrp_ping_capture_points takes nothing returns nothing

	local integer intA = 1
	local integer intAEnd = 7
	local location tpoint

	loop
	exitwhen intA > intAEnd
		if (jrp_is_point_locked(intA) != true) then
			set tpoint = GetRectCenter(udg_CapRects[intA])
			if (udg_CapOwners[intA] == 0) then
				call PingMinimapLocForForceEx( udg_P_Allplayers, tpoint, 3.00, bj_MINIMAPPINGSTYLE_FLASHY, 100, 100, 100 )
			endif
			if (udg_CapOwners[intA] == 1) then
				call PingMinimapLocForForceEx( udg_P_Allplayers, tpoint, 3.00, bj_MINIMAPPINGSTYLE_FLASHY, 100, 0.00, 0.00 )
			endif
			if (udg_CapOwners[intA] == 2) then
				call PingMinimapLocForForceEx( udg_P_Allplayers, tpoint, 3.00, bj_MINIMAPPINGSTYLE_FLASHY, 0.00, 0.00, 100 )
			endif
			call RemoveLocation( tpoint )
		endif
	set intA = intA + 1
	endloop

endfunction

// Update Scores

function jrp_update_scores takes nothing returns nothing

	local integer intA = 1
	local integer intAEnd = 7
	local string array round_strings

	set round_strings[1] = "Win 1 round"
	set round_strings[2] = "Win 2 / 3"
	set round_strings[3] = "Win 3 / 5"
	set round_strings[4] = "Win 4 / 6"
	set round_strings[5] = "Win 5 / 8"
	set round_strings[6] = "Win 6 / 10"


	call MultiboardSetItemValueBJ( udg_CapStatusBoard, 1, 11, round_strings[udg_Rounds_ToWin])
	// call MultiboardSetItemWidthBJ( udg_CapStatusBoard, 1, 11, 14 )


endfunction


function jrp_update_scoreboard takes nothing returns nothing

	local integer intA
	local integer intAEnd
	local integer intB
	local integer intBEnd
	local string tempstring
	local string progstring
	local integer redpercent
	local integer bluepercent


	call MultiboardSetItemValueBJ( udg_CapStatusBoard, 2, 9, I2S(udg_Rounds_RedWins) )
	call MultiboardSetItemValueBJ( udg_CapStatusBoard, 2, 10, I2S(udg_Rounds_BlueWins) )
	
	set intA = 1
	set intAEnd = 7
	loop
	exitwhen intA > intAEnd

		set redpercent = R2I( ( I2R(udg_CapScoresRed[intA]) / I2R(udg_ScoreToCap) ) * 100 )
		set bluepercent = R2I( ( I2R(udg_CapScoresBlue[intA]) / I2R(udg_ScoreToCap) ) * 100 )
		set progstring = ""
		
		set intB = 1
		set intBEnd = 10
		loop
		exitwhen intB > intBEnd
			if (jrp_is_point_locked(intA) == true) then
				if (udg_CapOwners[intA] == 0) then
					set progstring = "|c00888888[LOCK]|r"
				endif
				if (udg_CapOwners[intA] == 1) then
					set progstring = "|c00880000[LOCK]|r"
				endif
				if (udg_CapOwners[intA] == 2) then
					set progstring = "|c00000088[LOCK]|r"
				endif				
				
			else
				set tempstring = "I"
				if ( redpercent >= (intB * 10) ) then
					set tempstring = "|c00FF0000I|r"
				endif
				if ( (100 - bluepercent) < (intB * 10) ) then
					set tempstring = "|c000000FFI|r"
				endif
				set progstring = progstring + tempstring
			endif
			
		set intB = intB + 1
		endloop
		
		call MultiboardSetItemValueBJ( udg_CapStatusBoard, 2, intA + 1, progstring )
		call SetTextTagTextBJ( udg_CapPointTags[intA], progstring, 10 )
		
	set intA = intA + 1
	endloop

endfunction



function jrp_do_endgame takes integer winners returns nothing
	local integer WinnerS
	local integer WinnerE
	local integer LoserS
	local integer LoserE
	local group tempgroup
	local rect temprect
	local integer intA

	if (winners == 0) then
		return
	endif

	call ClearTextMessagesBJ( udg_P_Allplayers )

	// Let everyone see everything
	call FogEnableOff(  )

	// Make all units invul and paused
	set temprect = GetPlayableMapRect()
	set tempgroup = GetUnitsInRectAll(temprect)


	call ForGroupBJ( tempgroup, function jrp_make_enum_invulnerable )

	call DestroyGroup(tempgroup)
	call RemoveRect(temprect)

	call PauseAllUnitsBJ( true )



	if (winners == 1) then
		set WinnerS = 1
		set WinnerE = 6
		set LoserS = 7
		set LoserE = 12
		call DisplayTextToForce( udg_P_Allplayers, "|c00FF0303Red Team|r is first to " + I2S(udg_Rounds_ToWin) + " wins!  |c00FFCC00Red Team has prevailed!" )
		call PlayThematicMusicBJ( "Sound\\Music\\mp3Music\\HeroicVictory.mp3" )
	endif

	if (winners == 2) then
		set WinnerS = 7
		set WinnerE = 12
		set LoserS = 1
		set LoserE = 6
		call DisplayTextToForce( udg_P_Allplayers, "|c000042FFBlue Team|r is first to " + I2S(udg_Rounds_ToWin) + " wins!  |c00FFCC00Blue Team has prevailed!" )
		call PlayThematicMusicBJ( "Sound\\Music\\mp3Music\\HeroicVictory.mp3" )
	endif


	// Disable all triggers
	call DisableTrigger( gg_trg_Player_chooses_their_Class )
	call DisableTrigger( gg_trg_Every_15_seconds )
	call DisableTrigger( gg_trg_Every_1_second )
	call DisableTrigger( gg_trg_Weather_Controller )
	call DisableTrigger( gg_trg_A_Hero_Dies )
	call DisableTrigger( gg_trg_Unit_casts_spell )

	call PolledWait( 5.00 )
	
	call DisplayTextToForce( udg_P_Allplayers, "Now that a victor has been decided, the game will end in 60 seconds." )
	call StartTimerBJ( udg_EndGame_Timer, false, 60.00 )
	call CreateTimerDialogBJ( udg_EndGame_Timer, "Game ends in " )
	
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "Map by : |c00FFC000JRPereira|r@Azeroth ([email protected])" )
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "Thanks to the following people for various kinds of help..." )
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "|c00FFC000Lead Tester: |r UberMasterII" )
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "|c00FFC000Additional Official Testers: |r Kite253, Neobezo, GhostWitTheMost, Pure-THC, Genso, Giga, L33tCurry" )
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "|c00FFC000Additional Help: |r Phyrax" )
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "|c00FFC000Blizzard: |r For making this map possible." )
	call PolledWait( 5.00 )
	call DisplayTextToForce( udg_P_Allplayers, "|c00FFC000Thanks for playing! |r" )

	call PolledWait( 25.00 )
	
	set intA = WinnerS
	loop
		exitwhen(intA > WinnerE)
		call CustomVictoryBJ( ConvertedPlayer(intA), true, true )
		set intA = intA + 1
	endloop

	set intA = LoserS
	loop
		exitwhen(intA > LoserE)
		call CustomDefeatBJ( ConvertedPlayer(intA), "You have been Defeated" )
		set intA = intA + 1
	endloop
	
endfunction

function jrp_do_win_for_team takes integer winners returns nothing
	local integer WinnerS
	local integer WinnerE
	local integer LoserS
	local integer LoserE
	local group tempgroup
	local rect temprect
	local integer intA

	if (winners == 0) then
		return
	endif

	// Round over
	set udg_Round_InProgress = false

	// Get rid of text messages
	call ClearTextMessagesBJ( udg_P_Allplayers )

	// Let everyone see everything
	call FogEnableOff(  )

	call PauseAllUnitsBJ( true )

	if (winners == 1) then
		set udg_Rounds_RedWins = udg_Rounds_RedWins + 1
	endif

	if (winners == 2) then
		set udg_Rounds_BlueWins = udg_Rounds_BlueWins + 1
	endif

	// One last update of the scoreboard for this round
	call jrp_update_scoreboard()

	if (udg_Rounds_RedWins == udg_Rounds_ToWin) then
		// Do endgame (winning team)
		call jrp_do_endgame(1)
		return
	endif
	
	if (udg_Rounds_BlueWins == udg_Rounds_ToWin) then
		// Do endgame (winning team)
		call jrp_do_endgame(2)
		return
	endif
	
	if (winners == 1) then
		set WinnerS = 1
		set WinnerE = 6
		set LoserS = 7
		set LoserE = 12
		call DisplayTextToForce( udg_P_Allplayers, "|c00FF0303Red Team|r has captured Blue Team's base!  |c00FFCC00Red Team has won the round!" )
		call PlayThematicMusicBJ( "Sound\\Music\\mp3Music\\OrcVictory.mp3" )
	endif

	if (winners == 2) then
		set WinnerS = 7
		set WinnerE = 12
		set LoserS = 1
		set LoserE = 6
		call DisplayTextToForce( udg_P_Allplayers, "|c000042FFBlue Team|r has captured Red Team's base!  |c00FFCC00Blue Team has won the round!" )
		call PlayThematicMusicBJ( "Sound\\Music\\mp3Music\\OrcVictory.mp3" )
	endif

	// Disable triggers - they'll get enabled at the start of the next round
	call DisableTrigger( gg_trg_Player_chooses_their_Class )
	call DisableTrigger( gg_trg_Every_15_seconds )
	call DisableTrigger( gg_trg_Every_1_second )
	call DisableTrigger( gg_trg_A_Hero_Dies )
	call DisableTrigger( gg_trg_Unit_casts_spell )

	call PolledWait( 5 )

	// Get rid of text messages
	call ClearTextMessagesBJ( udg_P_Allplayers )
	
	call DisplayTextToForce( udg_P_Allplayers, "|c00FFCC00Map will be reset:|r in 10 seconds." )
	
	call PolledWait( 10 )

	// Unpause everything
	call PauseAllUnitsBJ( false )
	
	////////////////////////////////////////////////
	// Start round
	//////////////////////////////////////////////////
	
	// Start round
	call TriggerExecute( gg_trg_Start_Round )
	
endfunction
 

Attachments

  • team_rush_v094.w3x
    309.7 KB · Views: 79
Status
Not open for further replies.
Top