• 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] Custom Victory/Defeat

Status
Not open for further replies.
Level 6
Joined
Jun 30, 2006
Messages
230
JASS:
function AllianceWins takes nothing returns nothing
    call CustomVictoryBJ( GetEnumPlayer(), true, true )
endfunction

function HordeLoses takes nothing returns nothing
    call CustomDefeatBJ( GetEnumPlayer(), "You have failed to achieve victory!" )
endfunction

function AllianceWinsActions takes nothing returns nothing
    call ForForce( udg_Alliance, function AllianceWins )
    call ForForce( udg_Horde, function HordeLoses )
    call DisableTrigger( gg_trg_HordeWins )
endfunction

//===========================================================================
function InitTrig_AllianceWins takes nothing returns nothing
    local unit HeartOfTheHorde = gg_unit_nshr_0042
    set gg_trg_Human_Won = CreateTrigger()
    call TriggerRegisterUnitEvent( gg_trg_AllianceWins, HeartOfTheHorde, EVENT_UNIT_DEATH )
    call TriggerAddAction( gg_trg_AllianceWins, function AllianceWinsActions )
    set HeartOfTheHorde = null
endfunction

I have one problem: udg_Alliance and udg_Horde do not exist. Right now they are merely place-holders for the respective forces they represent, Alliance and Horde. I would think that if you when up to Scenario > Forces Properties and defined those forces it would set them to a variable of some sort to use in a trigger. I cannot find them if they are created. Questions:

1. Are they automatically created?
2. If so, how are they named?
3. If not, how do you correctly assign players to a force?
4. Can these BJ's be replaced or made more efficient? I've never done a custom Victory/Defeat before.
 
Level 6
Joined
Jun 30, 2006
Messages
230
I guess I'm unfamiliar with 'filter' as well. Could you explain that?

Also, the forceEnumAllies(f,Player,filter), if I wanted to ally him with player one, would I stick 'Player0'? or what's the syntax? Can you add people en masse?

I don't understand the last line either. The first two make sense, but the last seems vague. What does it do?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
ForceEnumPlayers just allows for a filter, and doesn't have any other parameters.

A filter is like, in GUI, when you say "Pick every unit matching Matching Unit is Dead Equal to True"

In JASS, they're made by;

JASS:
function myFilterFunc takes nothing returns boolean//MUST RETURN BOOLEAN!!
    return someBool//eg. GetFilterPlayer() == Player( 0 )
    //to reference the player currently being checked, use GetFilterPlayer()
endfunction

//when enumerating
call ForceEnumPlayers( f, Filter( function myFilterFunc ) )

Essentially, ForceEnumPlayers just asks for you to do all the work with your filter.

In other news, "Player" that you're reffering to is a function, so it would be Player( 0 ), or Player( 1 ), etc
 
Level 5
Joined
Feb 16, 2006
Messages
151
Wait, what are you talking about!?
The forces in Scenario > Forces Properties cannot be used in the Trigger Section, by creating those variables in the Variable Editor however, you did create those two forces.
What is left to do is to add up the according players into the according forces by using:
JASS:
call ForceAddPlayer(force,player)
 
Level 6
Joined
Jun 30, 2006
Messages
230
What I'm using:(Clean-up/improvements welcome!)
JASS:
globals
    force udg_Alliance
    force udg_Horde
endglobals
JASS:
//In map header
function Forces takes nothing returns nothing
    local integer c = 0
    set udg_Alliance = CreateForce()
    set udg_Horde = CreateForce()
    loop
        exitwhen c > 4
        if ( GetPlayerSlotState(Player(c)) == PLAYER_SLOT_STATE_PLAYING ) then
            call ForceAddPlayerSimple( Player(c), udg_Alliance )
        endif
        if ( GetPlayerSlotState(Player(c + 5)) == PLAYER_SLOT_STATE_PLAYING ) then
            call ForceAddPlayerSimple( Player(c + 5), udg_Horde )
        endif
        set c = c + 1
    endloop
endfunction
JASS:
function AllianceWins takes nothing returns nothing
    call CustomVictoryBJ( GetEnumPlayer(), true, true )
endfunction

function HordeLoses takes nothing returns nothing
    call CustomDefeatBJ( GetEnumPlayer(), "You have failed to achieve victory!" )
endfunction

function AllianceWinsActions takes nothing returns nothing
    call ForForce( udg_Alliance, function AllianceWins )
    call ForForce( udg_Horde, function HordeLoses )
    call DisableTrigger( gg_trg_HordeWins )
endfunction

//===========================================================================
function InitTrig_AllianceWins takes nothing returns nothing
    local unit HeartOfTheHorde = gg_unit_nshr_0042
    set gg_trg_AllianceWins = CreateTrigger()
    call TriggerRegisterUnitEvent( gg_trg_AllianceWins, HeartOfTheHorde, EVENT_UNIT_DEATH )
    call TriggerAddAction( gg_trg_AllianceWins, function AllianceWinsActions )
    set HeartOfTheHorde = null
endfunction
It doesn't work. Something about udg_Alliance not initialized :/
Also, it's important that I can call use the forces in other functions. I need to have each force research a different upgrade, plus a few other things. I can do the research, but for efficiency I would use forces.
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
1. Yes
2. Yes
3. Is now :) Reposted

I fixed it by creating a trigger on initialization that calls Forces() and my other function for my creep spawns. It didn't work calling it inside of AllianceWinsActions. Is this normal? Anyways, it works now.

However, I'm sure my code is inefficient. This is the first time I've done something like this, so the chances of me doing it to any efficiency are low. Anyone have any improvements?

Also, how resource intensive would this be (curiosity only):
JASS:
loop
   exitwhen c > 9
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 1) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 2) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 3) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 4) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 5) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 6) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 7) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 8) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 9) )
   set c = 0
endloop
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
So, to destroy the wrapper and do it properly would be done how?

Does no one else have questions like this? Is there some resource I haven't found that everyone else seems to have found? Am I just a noob? :)
 
Last edited:
JASS:
loop
   exitwhen c > 9
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 1) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 2) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 3) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 4) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 5) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 6) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 7) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 8) )
   call TriggerRegisterPlayerEventLeave( gg_trg_PlayerLeaves, Player(c + 9) )
   set c = 0
endloop

There is no point in the loop if it isn't used, you are simply just adding a bunch of players to infinity and beyond.

Change it to this to make it useful:
JASS:
    loop
        exitwhen c > 9
        call TriggerRegisterPlayerEventLeave(gg_trg_PlayerLeaves,Player(c))
        set c = c + 1
    endloop

That should work. It takes much less time and lines than those tons of events. :smile:
 
Level 6
Joined
Jun 30, 2006
Messages
230
Lol, you misunderstood me. The point wasn't to make it useful, or to do anything really. The point was how much system resources would it take to run a loop like that. Then the 'to destroy wrapper' part was to help me learn.
 
Status
Not open for further replies.
Top