Skip to content
User Avatar
#3694
Auto-translated
Martha

Specifically, how do you disable the garrison for everyone except the second player from the very beginning?
Good evening. The SetObjectEnabled function does not accept anything as a third parameter, meaning you cannot specify which player to block. An object can either be enabled or disabled. Regarding your script, I can suggest the following:
-- Create a single-cell region, one cell in front of the garrison
Trigger(REGION_ENTER_WITHOUT_STOP_TRIGGER,"GARRISON_REG","GarrisonCheck")
-- Create an array of "Banned" players
GARRISON_BANNED_PLAYERS = {
2,
-- If necessary, add the desired players here.
-- If you need to add to the script, write it in the appropriate place: GARRISON_BANNED_PLAYERS[length(GARRISON_BANNED_PLAYERS)] = "Player number to block"
}
-- If you need to remove a player from the array, write the following function (it already exists in the RedHeavenHero library; it's better not to reinvent the wheel)
-- The function below removes from the array in a rather crude way, but it should work for you.
-- In the place where you need to remove, write: GARRISON_BANNED_PLAYERS = arrayShiftByValue(GARRISON_BANNED_PLAYERS,"Player number to remove")
-- You will receive an array that no longer contains the specified player, or rather, with nil instead of the number
function arrayShiftByValue(array,value)
for index,element in array do
if(element == value) then
array[index] = nil
end
end
return array
end

function GarrisonCheck(heroname)
local player = GetObjectOwner(heroname)
if(contains(GARRISON_BANNED_PLAYERS,player) == not nil) then
SetObjectEnabled("GARRISON_NAME",nil)
else
SetObjectEnabled("GARRISON_NAME",not nil)
end
end

In common parlance, this is called a workaround, but it should work without any problems. When a unit approaches, we simply check the player and block the garrison if it is a player who is banned; otherwise, we remove the block.



Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.