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 :
(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.
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: