Hi guys , how can I check if entire map no player 2 unit , player 1 and other play that same allied with player 1 win too.
Hey guy I need your help here
Thank you !
Just like you said.
And of course remove win/loose conditions from melee initialization.
- Win
- Events
- Unit - A Unit owned by player(2) died.
- Conditions
- Actions
- Unit Group - Pick evry unit that belongs to player(2) at Playable map area and do (acctions)
- If picked unit is alive = true then
- Actions
- Skip remaining acctions.
- else (actions)
- Do Nothing
- Game - Set Player 1 victory
- Game - Set Player 2 deffeat
function Trig_Win_Conditions takes nothing returns boolean
if ( not ( GetOwningPlayer(GetTriggerUnit()) == Player(1) ) ) then
return false
endif
return true
endfunction
function Trig_Win_Func003Func001C takes nothing returns boolean
if ( not ( IsUnitAliveBJ(GetEnumUnit()) == true ) ) then
return false
endif
return true
endfunction
function Trig_Win_Func003A takes nothing returns nothing
if ( Trig_Win_Func003Func001C() ) then
return
else
call DoNothing( )
endif
call CustomVictoryBJ( Player(0), true, true )
call CustomDefeatBJ( Player(1), "TRIGSTR_001" )
endfunction
function Trig_Win_Actions takes nothing returns nothing
call ForGroupBJ( GetUnitsInRectOfPlayer(GetPlayableMapRect(), Player(1)), function Trig_Win_Func003A )
endfunction
//===========================================================================
function InitTrig_Win takes nothing returns nothing
set gg_trg_Win = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Win, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Win, Condition( function Trig_Win_Conditions ) )
call TriggerAddAction( gg_trg_Win, function Trig_Win_Actions )
endfunction
function Trig_Win_Actions takes nothing returns nothing
local unit u
local group g
local integer i
set i = 0
call GroupEnumUnitsOfPlayer(g, Player(1), null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (GetUnitState(u, UNIT_STATE_LIFE) > 0) then
set i = i + 1
endif
call GroupRemoveUnit(g, u)
endloop
if i == 0 then
call CustomVictoryBJ( Player(0), true, true )
call CustomDefeatBJ( Player(1), "Defeat!" )
endif
call DestroyGroup(g)
set g = null
set u = null
endfunction
//===========================================================================
function InitTrig_Win takes nothing returns nothing
local trigger T = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(T, Player(1), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddAction( T, function Trig_Win_Actions )
set T = null
endfunction
function CustomVictoryBJ takes player whichPlayer, boolean showDialog, boolean showScores returns nothing
if AllowVictoryDefeat( PLAYER_GAME_RESULT_VICTORY ) then
call RemovePlayer( whichPlayer, PLAYER_GAME_RESULT_VICTORY )
if not bj_isSinglePlayer then
call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, GetLocalizedString( "PLAYER_VICTORIOUS" ) )
endif
// UI only needs to be displayed to users.
if (GetPlayerController(whichPlayer) == MAP_CONTROL_USER) then
set bj_changeLevelShowScores = showScores
if showDialog then
call CustomVictoryDialogBJ( whichPlayer )
else
call CustomVictorySkipBJ( whichPlayer )
endif
endif
endif
endfunction
function AllowVictoryDefeat takes playergameresult gameResult returns boolean
if (gameResult == PLAYER_GAME_RESULT_VICTORY) then
return not IsNoVictoryCheat()
endif
if (gameResult == PLAYER_GAME_RESULT_DEFEAT) then
return not IsNoDefeatCheat()
endif
if (gameResult == PLAYER_GAME_RESULT_NEUTRAL) then
return (not IsNoVictoryCheat()) and (not IsNoDefeatCheat())
endif
return true
endfunction
function CustomVictoryDialogBJ takes player whichPlayer returns nothing
local trigger t = CreateTrigger()
local dialog d = DialogCreate()
call DialogSetMessage( d, GetLocalizedString( "GAMEOVER_VICTORY_MSG" ) )
set t = CreateTrigger()
call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_CONTINUE" ), GetLocalizedHotkey("GAMEOVER_CONTINUE") ) )
call TriggerAddAction( t, function CustomVictoryOkBJ )
set t = CreateTrigger()
call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_QUIT_MISSION" ), GetLocalizedHotkey("GAMEOVER_QUIT_MISSION") ) )
call TriggerAddAction( t, function CustomVictoryQuitBJ )
if (GetLocalPlayer() == whichPlayer) then
call EnableUserControl( true )
if bj_isSinglePlayer then
call PauseGame( true )
endif
call EnableUserUI(false)
endif
call DialogDisplay( whichPlayer, d, true )
call VolumeGroupSetVolumeForPlayerBJ( whichPlayer, SOUND_VOLUMEGROUP_UI, 1.0 )
call StartSoundForPlayerBJ( whichPlayer, bj_victoryDialogSound )
endfunction
function CustomVictoryOkBJ takes nothing returns nothing
if bj_isSinglePlayer then
call PauseGame( false )
// Bump the difficulty back up to the default.
call SetGameDifficulty(GetDefaultDifficulty())
endif
if (bj_changeLevelMapName == null) then
call EndGame( bj_changeLevelShowScores )
else
call ChangeLevel( bj_changeLevelMapName, bj_changeLevelShowScores )
endif
endfunction
function CustomVictoryQuitBJ takes nothing returns nothing
if bj_isSinglePlayer then
call PauseGame( false )
// Bump the difficulty back up to the default.
call SetGameDifficulty(GetDefaultDifficulty())
endif
call EndGame( bj_changeLevelShowScores )
endfunction
function VolumeGroupSetVolumeForPlayerBJ takes player whichPlayer, volumegroup vgroup, real scale returns nothing
if (GetLocalPlayer() == whichPlayer) then
call VolumeGroupSetVolume(vgroup, scale)
endif
endfunction
function StartSoundForPlayerBJ takes player whichPlayer, sound soundHandle returns nothing
if (whichPlayer == GetLocalPlayer()) then
call StartSound(soundHandle)
endif
endfunction
function CustomVictorySkipBJ takes player whichPlayer returns nothing
if (GetLocalPlayer() == whichPlayer) then
if bj_isSinglePlayer then
// Bump the difficulty back up to the default.
call SetGameDifficulty(GetDefaultDifficulty())
endif
if (bj_changeLevelMapName == null) then
call EndGame( bj_changeLevelShowScores )
else
call ChangeLevel( bj_changeLevelMapName, bj_changeLevelShowScores )
endif
endif
endfunction
function CustomVictoryBJ takes player whichPlayer, boolean showDialog, boolean showScores returns nothing
if AllowVictoryDefeat( PLAYER_GAME_RESULT_VICTORY ) then
call RemovePlayer( whichPlayer, PLAYER_GAME_RESULT_VICTORY )
if not bj_isSinglePlayer then
call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, GetLocalizedString( "PLAYER_VICTORIOUS" ) )
endif
// UI only needs to be displayed to users.
if (GetPlayerController(whichPlayer) == MAP_CONTROL_USER) then
set bj_changeLevelShowScores = showScores
if showDialog then
call CustomVictoryDialogBJ( whichPlayer )
else
call CustomVictorySkipBJ( whichPlayer )
endif
endif
endif
endfunction
function AllowVictoryDefeat takes playergameresult gameResult returns boolean
if (gameResult == PLAYER_GAME_RESULT_VICTORY) then
return not IsNoVictoryCheat()
endif
if (gameResult == PLAYER_GAME_RESULT_DEFEAT) then
return not IsNoDefeatCheat()
endif
if (gameResult == PLAYER_GAME_RESULT_NEUTRAL) then
return (not IsNoVictoryCheat()) and (not IsNoDefeatCheat())
endif
return true
endfunction
function CustomVictoryDialogBJ takes player whichPlayer returns nothing
local trigger t = CreateTrigger()
local dialog d = DialogCreate()
call DialogSetMessage( d, GetLocalizedString( "GAMEOVER_VICTORY_MSG" ) )
set t = CreateTrigger()
call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_CONTINUE" ), GetLocalizedHotkey("GAMEOVER_CONTINUE") ) )
call TriggerAddAction( t, function CustomVictoryOkBJ )
set t = CreateTrigger()
call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_QUIT_MISSION" ), GetLocalizedHotkey("GAMEOVER_QUIT_MISSION") ) )
call TriggerAddAction( t, function CustomVictoryQuitBJ )
if (GetLocalPlayer() == whichPlayer) then
call EnableUserControl( true )
if bj_isSinglePlayer then
call PauseGame( true )
endif
call EnableUserUI(false)
endif
call DialogDisplay( whichPlayer, d, true )
call VolumeGroupSetVolumeForPlayerBJ( whichPlayer, SOUND_VOLUMEGROUP_UI, 1.0 )
call StartSoundForPlayerBJ( whichPlayer, bj_victoryDialogSound )
endfunction
function CustomVictoryOkBJ takes nothing returns nothing
if bj_isSinglePlayer then
call PauseGame( false )
// Bump the difficulty back up to the default.
call SetGameDifficulty(GetDefaultDifficulty())
endif
if (bj_changeLevelMapName == null) then
call EndGame( bj_changeLevelShowScores )
else
call ChangeLevel( bj_changeLevelMapName, bj_changeLevelShowScores )
endif
endfunction
function CustomVictoryQuitBJ takes nothing returns nothing
if bj_isSinglePlayer then
call PauseGame( false )
// Bump the difficulty back up to the default.
call SetGameDifficulty(GetDefaultDifficulty())
endif
call EndGame( bj_changeLevelShowScores )
endfunction
function VolumeGroupSetVolumeForPlayerBJ takes player whichPlayer, volumegroup vgroup, real scale returns nothing
if (GetLocalPlayer() == whichPlayer) then
call VolumeGroupSetVolume(vgroup, scale)
endif
endfunction
function StartSoundForPlayerBJ takes player whichPlayer, sound soundHandle returns nothing
if (whichPlayer == GetLocalPlayer()) then
call StartSound(soundHandle)
endif
endfunction
function CustomVictorySkipBJ takes player whichPlayer returns nothing
if (GetLocalPlayer() == whichPlayer) then
if bj_isSinglePlayer then
// Bump the difficulty back up to the default.
call SetGameDifficulty(GetDefaultDifficulty())
endif
if (bj_changeLevelMapName == null) then
call EndGame( bj_changeLevelShowScores )
else
call ChangeLevel( bj_changeLevelMapName, bj_changeLevelShowScores )
endif
endif
endfunction
function Trig_Win_A takes nothing returns boolean
local unit u
call GroupEnumUnitsOfPlayer(udg_tempGroup, Player(1), null)
loop
set u = FirstOfGroup(udg_tempGroup)
exitwhen u == null
if not IsUnitType(u, UNIT_TYPE_DEAD) then
set u = null
return false
endif
call GroupRemoveUnit(udg_tempGroup, u)
endloop
// Good luck inlining these >_>
call CustomVictoryBJ(Player(0), true, true)
call CustomDefeatBJ(Player(1), "Defeat!")
return false
endfunction
function InitTrig_Win takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t, Player(1), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddCondition(t, function Trig_Win_A)
set t = null
endfunction
Here's an optimal version:
JASS:function Trig_Win_A takes nothing returns boolean local unit u call GroupEnumUnitsOfPlayer(udg_tempGroup, Player(1), null) loop set u = FirstOfGroup(udg_tempGroup) exitwhen u == null if not IsUnitType(u, UNIT_TYPE_DEAD) then set u = null return false endif call GroupRemoveUnit(udg_tempGroup, u) endloop // Good luck inlining these >_> call CustomVictoryBJ(Player(0), true, true) call CustomDefeatBJ(Player(1), "Defeat!") return false endfunction function InitTrig_Win takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterPlayerUnitEvent(t, Player(1), EVENT_PLAYER_UNIT_DEATH, null) call TriggerAddCondition(t, function Trig_Win_A) set t = null endfunction
I didn't inline those Victory/Defeat BJs because they're ugly.
To implement it, create a new trigger, convert it to custom text (Edit >> Convert to Custom Text) and paste this.
Then create a unit group variable (tempGroup) and you're done.
Not to mention the fact that the GUI triggers provided did not work... Or atleast should not work as the return is not in the function you want to stop.
Alternativly you can keep track of the number of units the player owns that is alive in an integer. This is far more efficient than enumerating all units he owns every time a unit dies.
1 enumeration for preplaced units.How can you set an integer to the amount of units that are alive and owned by a player without enumerating the units of that player :S?
"Do Nothing" is there becouse I just wanted make him sure that I didn't missed something. Are sure that win/loose should be in loop? Won't be then with 1st picked dead unit win...?
- Win
- Events
- Unit - A unit Dies
- Conditions
- (Owner of (Triggering unit)) Equal to Player 2 (Blue)
- Actions
- Unit Group - Pick every unit in (Units in (Playable map area) owned by Player 2 (Blue)) and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Picked unit) is alive) Equal to True
- Then - Actions
- Skip remaining actions
- Else - Actions
- Do nothing
- Game - Victory Player 1 (Red) (Show dialogs, Show scores)
- Game - Defeat Player 2 (Blue) with the message: Defeat!
Can I change to every second to check if there is no unit left ??
1 enumeration for preplaced units.
Then add the units individually as they come into existance.
Remove the units from the counter when they die.
Be aware of stuff like resurrect which could mess up the count.
That's exactly what I meant withOr are you talking about updating the integer whenever a unit gets created or killed?
Thanks1 enumeration for preplaced units.
Then add the units individually as they come into existance.
Remove the units from the counter when they die.
Be aware of stuff like resurrect which could mess up the count.
This is also an enumeration which has to be checked every ... seconds. As explained by Dr Super Good it's better to use a stored integer instead of enumerating all units of that player every ... seconds. It would really slow down things if every ... seconds all units of a player need to be checked. Checking a variable that contains this amount is way faster.have it check to see if the number of units in player 1's group is = 0 then victory the winning team.