- Joined
- Jul 18, 2010
- Messages
- 2,377
This is an idea I recently had, it allows to show/Access the ability Card of units one selects without shared control nor ownership.
1. By giving Units a clone of 'Ane2' ("select unit" unit seller have that skill without range) any player can see and use the abilities also move and use the inventory of the unit regardless of shared control or ownership.
2. Mouse clicks: outside of the playable map / on the User Interface result into x=0, y = 0.
If one combines both with some additional restrictions in design one can display the interface of units without any way to control the unit for other players.
Restrictions:
No Hotkeys
No Instant spells
No toogle able spells (auto cast, arrow skills) (okay that somehow could be catched, but the idea is to avoid any control, only allow to inspect)
That are quite heavy restrictions. Making it only really usefull for "NPC"/"Monsters"/"Minions" etc.
1. By giving Units a clone of 'Ane2' ("select unit" unit seller have that skill without range) any player can see and use the abilities also move and use the inventory of the unit regardless of shared control or ownership.
2. Mouse clicks: outside of the playable map / on the User Interface result into x=0, y = 0.
If one combines both with some additional restrictions in design one can display the interface of units without any way to control the unit for other players.
Restrictions:
No Hotkeys
No Instant spells
No toogle able spells (auto cast, arrow skills) (okay that somehow could be catched, but the idea is to avoid any control, only allow to inspect)
That are quite heavy restrictions. Making it only really usefull for "NPC"/"Monsters"/"Minions" etc.
JASS:
library CheckOutAll initializer Init
globals
private force checksOut = CreateForce()
private trigger MouseClick = CreateTrigger()
private trigger Select = CreateTrigger()
private trigger DeSelect = CreateTrigger()
private integer checkOutAbility = 'A000' //Clone of 'Ane2' "Select Unit", with 0.01 range/DataA1, that skill is added to inspecting units.
private unit array checkOutUnit
endglobals
private function SelectAction takes nothing returns nothing
local player p = GetTriggerPlayer()
if not GetPlayerAlliance(GetOwningPlayer(GetTriggerUnit()), p, ALLIANCE_SHARED_CONTROL) then
call ForceAddPlayer(checksOut, p)
call UnitAddAbility(GetTriggerUnit(), checkOutAbility)
set checkOutUnit[GetPlayerId(p)] = GetTriggerUnit()
call EnableTrigger(MouseClick)
endif
set p = null
endfunction
private function DeSelectAction takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer index
if IsPlayerInForce(p, checksOut) and GetUnitAbilityLevel(GetTriggerUnit(), checkOutAbility) != 0 then
call ForceRemovePlayer(checksOut, p)
set checkOutUnit[GetPlayerId(p)] = null
set p = null
set index = 0
loop //Do other players checkOut this unit?
if checkOutUnit[index] == GetTriggerUnit() then
return //Yes, stop now
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call UnitRemoveAbility(GetTriggerUnit(), checkOutAbility)
if CountPlayersInForceBJ(checksOut) == 0 then
call DisableTrigger(MouseClick)
endif
endif
set p = null
endfunction
private function MouseClickAction takes nothing returns nothing
//Not allowed to Press on UI, while selecting an Checkout Unit.
if BlzGetTriggerPlayerMouseX() == 0 and BlzGetTriggerPlayerMouseY() == 0 and IsPlayerInForce(GetTriggerPlayer(), checksOut) then
call ClearSelectionForPlayer(GetTriggerPlayer())
endif
endfunction
private function TriggerRegisterAnyPlayerEventBJ takes trigger trig, playerevent whichEvent returns nothing
local integer index
set index = 0
loop
call TriggerRegisterPlayerEvent(trig, Player(index), whichEvent)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
endfunction
private function Init takes nothing returns nothing
call TriggerRegisterAnyPlayerEventBJ(MouseClick, EVENT_PLAYER_MOUSE_DOWN)
call TriggerRegisterAnyUnitEventBJ(Select, EVENT_PLAYER_UNIT_SELECTED)
call TriggerRegisterAnyUnitEventBJ(DeSelect, EVENT_PLAYER_UNIT_DESELECTED)
call TriggerAddAction(Select, function SelectAction)
call TriggerAddAction(DeSelect, function DeSelectAction)
call TriggerAddAction(MouseClick, function MouseClickAction)
call DisableTrigger(MouseClick)
endfunction
endlibrary