• 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.

How to Lock cameras to units for observers?

Status
Not open for further replies.
How to Lock cameras to units for observers?
I've done something like this:
JASS:
function Trig_Lock_Conditions takes nothing returns boolean
    return SubString(GetEventPlayerChatString(),0,5) == "-lock"
endfunction

function Trig_Lock_Actions takes nothing returns nothing
    local string s = GetEventPlayerChatString()
    local integer length = StringLength(s)
    local player p = GetTriggerPlayer()
    local integer id = S2I(SubString(s,6,length))
    if IsPlayerObserver(p) == true then
        if length < 7 or length > 7 then
            call DisplayTextToPlayer(p,0,0,"Enter the command again. Wrong request.")    
            return
        elseif length == 7 then
            if GetLocalPlayer() == p then
                call SetCameraTargetController(udg_PickedHero[id],0,0,false)
            endif
        endif
    endif
    set p = null    
endfunction

//===========================================================================
function InitTrig_Lock takes nothing returns nothing
    set gg_trg_Lock = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(0),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(1),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(2),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(3),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(4),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(5),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(6),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(7),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(8),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(9),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(10),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(11),"-lock",false)
    call TriggerAddCondition(gg_trg_Lock,Condition(function Trig_Lock_Conditions))
    call TriggerAddAction(gg_trg_Lock,function Trig_Lock_Actions)
endfunction
 
JASS:
function Trig_Lock_Conditions takes nothing returns boolean
    return SubString(GetEventPlayerChatString(),0,5) == "-lock"
endfunction

function Trig_Lock_Actions takes nothing returns nothing
    local string s = GetEventPlayerChatString()
    local integer length = StringLength(s)
    local player p = GetTriggerPlayer()
    local integer id = S2I(SubString(s,6,length))
    if IsPlayerObserver(p) == true then
        if length < 7 or length > 7 then
            call DisplayTextToPlayer(p,0,0,"Enter the command again. Wrong request.")    
            return
        elseif length == 7 then
            call SetCameraTargetControllerNoZForPlayer(p,udg_PickedHero[id],0,0,false)
        endif
    endif
    set p = null    
endfunction

//===========================================================================
function InitTrig_Lock takes nothing returns nothing
    set gg_trg_Lock = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(0),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(1),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(2),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(3),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(4),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(5),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(6),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(7),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(8),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(9),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(10),"-lock",false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Lock,Player(11),"-lock",false)
    call TriggerAddCondition(gg_trg_Lock,Condition(function Trig_Lock_Conditions))
    call TriggerAddAction(gg_trg_Lock,function Trig_Lock_Actions)
endfunction

Will this work only for observers?
 
So wait, your actual question was the code to be applied for observers only? Well, you need to detect what player is an observer. Normally, observers have no units or the map is visible to them. You can make two checks; let's say that you have a time limit of when the players can choose their heroes. After that timer expires, you can check which players don't own units (Number of units owned by (Picked player) [from (All players)] Equal to 0). I presume you already give units to players that haven't picked any units, before the timer expires.
Another check you can do is whether the Fog of War or Black mask is disabled for the (EnumPlayer()). You will need GetLocalPlayer() for that.

Additionally, you can rename a race to be "Observer"; then, you can make a check of what the race of the player is. If it's "Observer", make your stuff, e.g. Enable visibility across the map, etc.

You can also make an additional player force. If the player belongs to the third force, he is an observer (you will use a player indexing to restore the position of the player in the (All players) structure); for player numbers higher than 9 for example (= 10, 11, 12), those players will be considered as observers. There are many ways to do that.
 
Status
Not open for further replies.
Top