• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

GetTriggerPlayer() not working in Filter functions ???

Status
Not open for further replies.
Level 12
Joined
Jan 30, 2020
Messages
875
Hello guys.

Working on my map again, I was trying to test some host and player controls that are typed in game chat.

I can only test my map on single player at the moment, so I only started checking these recently.

There is a typed command that I made that allows a player to remove units (towers) built by another player on his main building area (a simple rect).

I use an enum to pick all units in the rect of the player typing the command "+clean".
I added the actions in the filter function (returning false) to avoid ForGroup calls (I know performance is irrelevant for such a situation, but I just wanted to see if it would work).

Here is the code :

JASS:
function CleanIntrudingTower takes nothing returns boolean
    local unit theUnit=GetEnumUnit()
    local player intruded=GetTriggerPlayer()
    local player owner=GetOwningPlayer(theUnit)
    local integer theUnitID
    local integer ownerNb
    local integer oldGold
    local integer oldBonus


   //the debug message that displays the player number of the owner of the unit and the trigger player
    call BJDebugMsg("ownerNb="+I2S(GetPlayerId(owner)+1)+" - intrudedNb="+I2S(GetPlayerId(intruded)+1))
    if (owner!=intruded) then
        if IsUnitType(theUnit, UNIT_TYPE_STRUCTURE) then
            set theUnitID=GetUnitTypeId(theUnit)
            set ownerNb=(GetPlayerId(owner)+1)
            set oldGold=GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD)
            set oldBonus=GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER)
            if ((theUnitID==BouncingID) or (theUnitID==FrostmourneID)) then
                 call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, oldBonus+1)
            endif
            if (theUnitID==DivinityID) then
                 call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, oldBonus+2)
            endif
            call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, oldGold+GetUnitPointValue(theUnit))
            call RemoveUnit(theUnit)
        endif
    endif
    set theUnit=null
    set intruded=null
    set owner=null
    return false
endfunction


function PlayerControls_Actions takes nothing returns boolean
    local string typedOrder=GetEventPlayerChatString()
    local player thePlayer=GetTriggerPlayer()
    local integer playerNb=(GetPlayerId(thePlayer)+1)

// some other locals removed for readability

    local group intruders

// some other controls removed for readability

    if (SubString(typedOrder, 0, 6)=="+clean") then
        set intruders=CreateGroup()
        call GroupEnumUnitsInRect(intruders, PlayerArea[playerNb], Filter(function CleanIntrudingTower))
    endif
    call DestroyGroup(intruders)

    set intruders=null
    set thePlayer=null
    set typedOrder=null
    return false
endfunction

(Note that the Player Control action function is itself added to the final trigger conditions rather than actions)

So the issue is here : I placed several towers owned by another player in the player 1 main Rect.

Once the game is started, I type the command "+clean". Then the debug message shows that GetTriggerPlayer() is the owner of all enum units instead of the player typing the command.

Is this normal ?

Do I need to save the player number in my Hashtable and load it in the enum function ?

Or if there is anything else, what did I do that is wrong ?

Thank you guys, your help is always precious,
Take care.

EDIT : don't worry about the actions in the enum, it basically just refunds the total cost of the towers to the "intruding" player.
 
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
Not editing because 30 edits end up looking really unpleasant.

Well I should have guessed I have done something stupid again. Yes it is now obvious that once again I have searched in the wrong direction.

GetTriggerUnit() works perfectly, as does the rest of the filter function except..... you don't use GetEnumUnit() in a Filter function but GetFilterUnit().

Seems so obvious that I am surprised it didn't hit me before.

Anyways sorry for polluting the World Editor Help Zone with useless questions guys, if a moderator wants to remove this thread, please do so, I don't think it would help anyone

EDIT : As for saving the player number, there was no way to save it anyways as you can't access the Filter Unit before starting the enumeration.
 
Status
Not open for further replies.
Top