Script Doesnt Work

Blackrage

Ultra Cool Member
Reaction score
25
JASS:
library Tag
    globals
        private group Tagged
        
        private trigger TagT
        
        private constant integer TaggerId = 'Udre'
        private constant integer ShadowId = 'u000'
        
        private constant string Message = "The Tagger has won! All the shadows have been tagged."
        private constant string TaggedMessage = "Tagged!"
        private constant string ReleaseMessage = "Released!"
        private constant string ReleaseMessage2 = "The Tagger has been attacked! He is paused for five seconds."
        private constant string ReleaseTaggerMessage = "The Tagger has been unpaused."
    endglobals

    private function ShadowCheck takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) == ShadowId
    endfunction
    
    private function Actions takes nothing returns nothing
        local integer i
        local integer i2
        local unit PickedUnit
        local unit Attacker = GetEventDamageSource()
        local unit Attacked = GetTriggerUnit()
        local integer AttackerId = GetUnitTypeId(Attacker)
        local integer AttackedId = GetUnitTypeId(Attacked)
        local group Check = CreateGroup()
        
        local texttag tag
        
        if AttackerId == TaggerId then
            if AttackedId == ShadowId then
                call PauseUnit(Attacked, true)
                call SetUnitInvulnerable(Attacked, true)
                call GroupAddUnit(Tagged, Attacked)
                call GroupEnumUnitsInRect(Check, bj_mapInitialPlayableArea, Condition(function ShadowCheck))
                set tag = CreateTextTagUnitBJ(TaggedMessage, Attacked, 0, 8., 255, 0, 0, 0)
                call SetTextTagVelocityBJ(tag, 15, 90)
                call SetTextTagPermanent(tag, false)
                call SetTextTagLifespan(tag, 3)
                loop
                    set PickedUnit = FirstOfGroup(Check)
                    if IsUnitInGroup(PickedUnit, Tagged) then
                        set i = i + 1
                    endif
                    set i2 = i2 + 1
                endloop
                if i == i2 then
                    set i = 0
                    loop
                        call DisplayTextToPlayer(Player(i), 0, 0, Message)
                        set i = i + 1
                    endloop
                endif
            endif
        elseif AttackerId == ShadowId then
            if AttackedId == TaggerId then
                call DisplayTextToPlayer(Player(i), 0, 0, ReleaseMessage2)
                loop
                    call SetPlayerState(GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD) + 100)
                    set PickedUnit = FirstOfGroup(Tagged)
                    set tag = CreateTextTagUnitBJ(ReleaseMessage, Attacked, 0, 8., 255, 0, 0, 0)
                    call SetTextTagVelocityBJ(tag, 15, 90)
                    call SetTextTagPermanent(tag, false)
                    call SetTextTagLifespan(tag, 3)
                    call PauseUnit(PickedUnit, false)
                    call SetUnitInvulnerable(PickedUnit, false)
                    exitwhen PickedUnit == null
                endloop
                call PauseUnit(Attacked, true)
                call SetUnitInvulnerable(Attacked, true)
                call PolledWait(5.)
                call DisplayTextToPlayer(Player(i), 0, 0, ReleaseTaggerMessage)
                call PauseUnit(Attacked, false)
                call SetUnitInvulnerable(Attacked, false)
            endif
        endif
    endfunction

    //===========================================================================
    function RegisterUnit takes unit u returns nothing
        call TriggerRegisterUnitEvent(TagT, u, EVENT_UNIT_DAMAGED)
        call TriggerAddAction(TagT, function Actions)
    endfunction
endlibrary



Yes, the map I'm using this code for is a tag map. I register the Shadows in their creation trigger and on the tagger's trigger, but this code isnt working at all. Not at all.

This code pauses and makes the tagged runner invulnerable. When another runner attacks the Tagger, every tagged runner will be unpaused and will lose invulnerability and the tagger will be paused and invulnerable for 5 seconds.

I'm working on my friends map, btw. +rep when helped.
 

Viikuna

No Marlo no game.
Reaction score
265
First of all: you need to learn debug your code. Use BJDebugMsg.

Secondly: PolledWait leaks 1 handle, so you might wanna use PolledWait2 ( its a custom function, try to search it. )

JASS:
                loop
                    call SetPlayerState(GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD) + 100)
                    set PickedUnit = FirstOfGroup(Tagged) // this unit is allways the same
                    set tag = CreateTextTagUnitBJ(ReleaseMessage, Attacked, 0, 8., 255, 0, 0, 0)
                    call SetTextTagVelocityBJ(tag, 15, 90)
                    call SetTextTagPermanent(tag, false)
                    call SetTextTagLifespan(tag, 3)
                    call PauseUnit(PickedUnit, false)
                    call SetUnitInvulnerable(PickedUnit, false)
                    exitwhen PickedUnit == null // this is never true
                endloop

You need to remove your unit from group, if you want that loop to work.
 

Blackrage

Ultra Cool Member
Reaction score
25
Forgot to remove that unit and I never spotted it =/

And The message when you get tagged never shows up.

Edit: Just noticed that I never created the trigger TagT. Testing now.
 

Blackrage

Ultra Cool Member
Reaction score
25
A New Problem:

Code:

JASS:
library Tag requires HandyFuncs
    globals
        private group Tagged = CreateGroup()     
        private trigger TagT = CreateTrigger()
        
        private constant integer TaggerId = 'Udre'
        private constant integer ShadowId = 'u000'
        
        private constant string Message = "The Tagger has won! All the shadows have been tagged."
        private constant string TaggedMessage = "Tagged!"
        private constant string ReleaseMessage = "Released!"
        private constant string ReleaseMessage2 = "The Tagger has been attacked! He is paused for five seconds."
        private constant string ReleasePudgeMessage = "The Tagger has been unpaused."
    endglobals

    private function ShadowCheck takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) == ShadowId
    endfunction
    
    private function Actions takes nothing returns nothing
        local integer i
        local integer i2
        local unit PickedUnit
        local unit Attacker = GetEventDamageSource()
        local unit Attacked = GetTriggerUnit()
        local unit NewUnit
        local integer AttackerId = GetUnitTypeId(Attacker)
        local integer AttackedId = GetUnitTypeId(Attacked)
        local real TaggerX = GetUnitX(Attacked)
        local real TaggerY = GetUnitY(Attacked)
        local group Check = CreateGroup()
        
        local texttag tag
        
        call BJDebugMsg("Debug 1")
        if AttackerId == PudgeId then
            if AttackedId == ShadowId then
                call BJDebugMsg("Debug 10")
                set NewUnit = CreateUnit(GetOwningPlayer(Attacked), ShadowId, GetUnitX(Attacked), GetUnitY(Attacked), 270)
                call ShowUnit(NewUnit, false)
                call PauseUnit(NewUnit, true)
                call GroupAddUnit(Tagged, NewUnit)
                call GroupEnumUnitsInRect(Check, bj_mapInitialPlayableArea, Condition(function ShadowCheck))
                set tag = CreateTextTagUnitBJ(TaggedMessage, NewUnit, 0, 8., 255, 0, 0, 0)
                call SetTextTagVelocityBJ(tag, 15, 90)
                call SetTextTagPermanent(tag, false)
                call SetTextTagLifespan(tag, 3)
                loop
                    call BJDebugMsg("Debug 2")
                    set PickedUnit = FirstOfGroup(Check)
                    if IsUnitInGroup(PickedUnit, Tagged) then
                        set i = i + 1
                    endif
                    set i2 = i2 + 1
                endloop
                if i == i2 then
                    call BJDebugMsg("Debug 3")
                    set i = 0
                    loop
                        call BJDebugMsg("Debug 4")
                        call DisplayTextToPlayer(Player(i), 0, 0, Message)
                        set i = i + 1
                    endloop
                endif
            endif
        elseif AttackerId == ShadowId then
            if AttackedId == TaggerId then
                call BJDebugMsg("Debug 5")
                call DisplayTextToPlayer(Player(i), 0, 0, ReleaseMessage2)
                loop
                    call BJDebugMsg("Debug 6")
                    call SetPlayerState(GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD) + 100)
                    set PickedUnit = FirstOfGroup(Tagged)
                    call SetUnitX(PickedUnit, TaggerX)
                    call SetUnitY(PickedUnit, TaggerY)
                    set tag = CreateTextTagUnitBJ(ReleaseMessage, Attacked, 0, 8., 255, 0, 0, 0)
                    call SetTextTagVelocityBJ(tag, 15, 90)
                    call SetTextTagPermanent(tag, false)
                    call SetTextTagLifespan(tag, 3)
                    call ShowUnit(PickedUnit, true)
                    call PauseUnit(Attacked, false)
                    call GroupRemoveUnit(Tagged, PickedUnit)
                    exitwhen PickedUnit == null
                endloop
                call BJDebugMsg("Debug 7")
                call PauseUnit(Attacked, true)
                call SetUnitInvulnerable(Attacked, true)
                call PolledWait2(5.)
                call DisplayTextToPlayer(Player(i), 0, 0, ReleaseTaggerMessage)
                call PauseUnit(Attacked, false)
                call SetUnitInvulnerable(Attacked, false)
            endif
        endif
        call BJDebugMsg("Debug 8")
        set Attacked = null
        set Attacker = null
        call DestroyGroup(Check)
    endfunction

    //===========================================================================
    function RegisterUnit takes unit u returns nothing
        call TriggerRegisterUnitEvent(TagT, u, EVENT_UNIT_DAMAGED)
        call TriggerAddAction(TagT, function Actions)
        call BJDebugMsg("Debug 9")
    endfunction
endlibrary


For Some Reason, the tagger turns into the runner whenever the tagger attacks (it also 1 hit ko's the runners) the runner. Why is that?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top