• 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] Problem with custom victory triggers

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
I have a custom victory trigger for my map.

It's pretty simple I think. Every 8 seconds it checks all the Heroes for all the Players and then counts them for their force. So if a hero is on the Blood Pack force it counts them.

Now, if a player dies completely, meaning he's wasted all his extra lives, then his hero is removed and he's given a critter to observe the game. This means when the count for his team is made, he will not be counted.

When the count for all teams except 1 is equal to 0, the game ends and victory or defeat is administered.

The problem is it doesn't work like I want, and goes off rather randomly.

JASS:
scope Victory

globals
    private integer BloodPackCount
    private integer FangSquadCount
    private integer HellHordeCount
    private integer CrimsonHuntersCount
    private integer VileLegionCount
    private integer ChosenVampireCount
    private integer The11thCount
endglobals

private function CheckEm takes nothing returns boolean
    if IsUnitInForce(GetFilterUnit(), BloodPack) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set BloodPackCount = BloodPackCount + 1
    elseif IsUnitInForce(GetFilterUnit(), FangSquad) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set FangSquadCount = FangSquadCount + 1
    elseif IsUnitInForce(GetFilterUnit(), HellHorde) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set HellHordeCount = HellHordeCount + 1
    elseif IsUnitInForce(GetFilterUnit(), CrimsonHunters) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set CrimsonHuntersCount = CrimsonHuntersCount + 1
    elseif IsUnitInForce(GetFilterUnit(), VileLegion) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set VileLegionCount = VileLegionCount + 1
    elseif IsUnitInForce(GetFilterUnit(), ChosenVampire) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set ChosenVampireCount = ChosenVampireCount + 1
    elseif IsUnitInForce(GetFilterUnit(), The11th) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
        set The11thCount = The11thCount + 1
    endif
 return false
endfunction

public function CheckForces takes nothing returns nothing

    set BloodPackCount = 0
    set FangSquadCount = 0
    set HellHordeCount = 0
    set CrimsonHuntersCount = 0
    set VileLegionCount = 0
    set ChosenVampireCount = 0
    set The11thCount = 0
    call GroupEnumUnitsOfPlayer(ENUM_GROUP, GetLocalPlayer(), function CheckEm)
//    call GroupEnumUnitsInRect(ENUM_GROUP, bj_mapInitialPlayableArea, function CheckEm)
    if The11thCount > 0 and FangSquadCount == 0 and BloodPackCount == 0 and HellHordeCount == 0 and CrimsonHuntersCount == 0 and VileLegionCount == 0 and ChosenVampireCount == 0 then
        if not IsUnitType(Lieutenant, UNIT_TYPE_DEAD) then
            call DisplayTextToForce(The11th, "You are Victorious! Prague is now safe from the Vampire clans.")
        else
            call DisplayTextToForce(The11th, "You are Victorious! Prague is now under the control of a new Vampire.")
        endif
        if IsPlayerInForce(GetLocalPlayer(), The11th) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ( GetLocalPlayer(), " You have met an unfortunate end.")
        endif
    elseif BloodPackCount > 0 and FangSquadCount == 0 and HellHordeCount == 0 and CrimsonHuntersCount == 0 and VileLegionCount == 0 and The11thCount == 0 and ChosenVampireCount == 0 then
        call DisplayTextToForce(BloodPack, "You are Victorious! The Blood Pack reigns supreme.")
        if IsPlayerInForce(GetLocalPlayer(), BloodPack) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ(GetLocalPlayer(), " You have met an unfortunate end, along with your clan.")
        endif
    elseif FangSquadCount > 0 and BloodPackCount == 0 and HellHordeCount == 0 and CrimsonHuntersCount == 0 and VileLegionCount == 0 and ChosenVampireCount == 0 and The11thCount == 0 then
        call DisplayTextToForce(FangSquad, "You are Victorious! The Fang Squad reigns supreme.")
        if IsPlayerInForce(GetLocalPlayer(), FangSquad) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ(GetLocalPlayer(), " You have met an unfortunate end, along with your clan.")
        endif
    elseif HellHordeCount > 0 and BloodPackCount == 0 and FangSquadCount == 0 and CrimsonHuntersCount == 0 and VileLegionCount == 0 and ChosenVampireCount == 0 and The11thCount == 0 then
        call DisplayTextToForce(BloodPack, "You are Victorious! The Hell Horde reigns supreme.")
        if IsPlayerInForce(GetLocalPlayer(), BloodPack) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ(GetLocalPlayer(), " You have met an unfortunate end, along with your clan.")
        endif
    elseif CrimsonHuntersCount > 0 and BloodPackCount == 0 and FangSquadCount == 0 and HellHordeCount == 0 and VileLegionCount == 0 and ChosenVampireCount == 0 and The11thCount == 0 then
        call DisplayTextToForce(BloodPack, "You are Victorious! The Crimson Hunters reigns supreme.")
        if IsPlayerInForce(GetLocalPlayer(), BloodPack) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ(GetLocalPlayer(), " You have met an unfortunate end, along with your clan.")
        endif
    elseif VileLegionCount > 0 and BloodPackCount == 0 and FangSquadCount == 0 and HellHordeCount == 0 and CrimsonHuntersCount == 0 and ChosenVampireCount == 0 and The11thCount == 0 then
        call DisplayTextToForce(BloodPack, "You are Victorious! The Vile Legion reigns supreme.")
        if IsPlayerInForce(GetLocalPlayer(), BloodPack) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ(GetLocalPlayer(), " You have met an unfortunate end, along with your clan.")
        endif
    elseif ChosenVampireCount > 0 and BloodPackCount == 0 and FangSquadCount == 0 and HellHordeCount == 0 and CrimsonHuntersCount == 0 and VileLegionCount == 0 and The11thCount == 0 then
        call DisplayTextToForce(BloodPack, "You are Victorious! The Vile Legion reigns supreme.")
        if IsPlayerInForce(GetLocalPlayer(), BloodPack) then
            call CustomVictoryBJ( GetLocalPlayer(), true, true )
        else
            call CustomDefeatBJ(GetLocalPlayer(), " You have met an unfortunate end, along with your clan.")
        endif
    endif
endfunction

public function init takes nothing returns nothing
    if not bj_isSinglePlayer and Mode != "Haven Control" then
        debug call BJDebugMsg("it goes!")
        call TimerStart(CreateTimer(), 8, true, function CheckForces)
    endif
endfunction

endscope
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
call GroupEnumUnitsOfPlayer(ENUM_GROUP, GetLocalPlayer(), function CheckEm)

This is a terrible, terrible idea. If you don't understand how GetLocalPlayer() works then don't use it. It isn't the same as (local player) in Starcraft.

(Also your other GetLocalPlayer calls will be just as buggy, so enjoy your desyncs)

And I suspect this is your problem, although I'm not experienced with IsUnitInForce so I can't say for sure it isn't related to that instead.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
I'm not experienced with that function either. It just seemed like a much easier shortcut then referncing the owning player of a unit.

I'm not sure if that's such a bad idea though, as it has yet to desync. I understand it to about 85%. (And as of current nothing in my map desyncs. I believe the defeat/victory fires trigger as they should. However I'll double check it.)

The other 15% that I don't understand is how it can be used instead of 1 thu 12 loops to reference all playing players.

This discussion is of course about coming up with a solution after finding the problem. Should this be the problem what would be a solution? Would checking all heroes on the map work even when they're dead? (As I'm not sure if they're removed from playable bounds.)
 
The thing that PurplePoot mentioned might be the problem. When you use GroupEnumUnitsOfPlayer(...,GetLocalPlayer(),...) (or generally anything like TriggerRegisterPlayerEvent(...,GetLocalPlayer(),...)) it will perform the actions locally. So basically, the group will contain different units for each player. Then when it performs CheckEm, it will check different filtered units, and the data retrieved for each player will be different (BloodPackCount, FangSquadCount, etc...). That might be why it fires randomly. Otherwise, I'm not sure what the problem is.
 
Status
Not open for further replies.
Top