Moderator
M
// Trackables System [GUI Friendly] v1.10
// by Flux
// http://www.hiveworkshop.com/forums/members/flux/
// A trackables system which is easy to use for GUI users.
// It allows users to detect when a certain player hovers
// or clicks (using the mouse) on an area within a Region
// (which is actually a rect in JASS).
// NOTE:
// - This system cost 1 hashtable.
// - TRK_Players (force) is automatically destroyed so it is
// highly advised to not set TRK_Players to an existing Player
// group, but instead, create a new one (as shown in the demo).
// - TRK_Point (location) must not be removed or overwritten.
// HOW TO IMPORT:
// 1. Copy the Trackables System Variable Creator in your map.
// Make sure you set the "Automatically create unknown variables
// while pasting trigger data" in Files -> Preferences.
// After copying, delete Trackables System Variable Creator
// 2. Copy Trackables System to your map.
// HOW TO USE:
// 1. Set 'TRK_Players'. The Players in this PlayerGroup are the ones
// who can interact with the trackables about to be created.
// The Player Group is automatically destroyed so you don't need
// to manually destroy 'TRK_Players'
// 2. Set 'TRK_Rect' which refers to the rect where the trackables
// will be created. Rects are called Regions in GUI.
// 3. Set 'TRK_HoverTrigger' which refers to the trigger that will run when
// a player in TRK_Players hovers a trackable in the 'TRK_Region'.
// 4. Set 'TRK_ClickTrigger' which refers to the trigger that will run when
// a player in TRK_Players clicks a trackable in the 'TRK_Region'.
// 5. Set 'TRK_Spacing' which refers to the spacing between trackables.
// 6. Set 'TRK_ModelPath' which determines how the trackables will look
// in game.
// 7. Run the system using:
// 'Trigger - Run Trackables System <gen> (checking conditions)'
// 8. In your trackables event triggers, TRK_Point refers to the location
// of the trackables that was clicked/hovered and TRK_TriggeringPlayer
// is the player that interacted with the trackable. Note that you cannot
// use TRK_Point and TRK_TriggeringPlayer in the Conditions so you have
// to create a big IF-THEN-ELSE if your condition involves TRK_Point
// or TRK_TriggeringPlayer
// 9. Do your actions
function Trig_Trackables_System_InitVariables takes nothing returns boolean
local integer id = LoadInteger(udg_TRK_Hashtable, GetHandleId(GetTriggeringTrackable()), 0)
call MoveLocation(udg_TRK_Point, udg_TRK_TrackableX[id], udg_TRK_TrackableY[id])
set udg_TRK_TriggeringPlayer = udg_TRK_TrackableOwner[id]
return true
endfunction
function Trig_Trackables_System_PickPlayers takes nothing returns nothing
local string s = ""
local trackable t
set udg_TRK_TrackableOwner[udg_TRK_Index] = GetEnumPlayer()
if GetPlayerSlotState(udg_TRK_TrackableOwner[udg_TRK_Index]) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(udg_TRK_TrackableOwner[udg_TRK_Index]) == MAP_CONTROL_USER then
//Trackable Properties
set udg_TRK_TrackableX[udg_TRK_Index] = udg_TRK_x
set udg_TRK_TrackableY[udg_TRK_Index] = udg_TRK_y
if GetLocalPlayer() == udg_TRK_TrackableOwner[udg_TRK_Index] then
set s = udg_TRK_ModelPath
endif
set t = CreateTrackable(s, udg_TRK_x, udg_TRK_y, 0)
//Save index
call SaveInteger(udg_TRK_Hashtable, GetHandleId(t), 0, udg_TRK_Index)
//Register the trackable
if udg_TRK_HoverTrigger != null then
call TriggerRegisterTrackableTrackEvent(udg_TRK_HoverTrigger, t)
endif
if udg_TRK_ClickTrigger != null then
call TriggerRegisterTrackableHitEvent(udg_TRK_ClickTrigger, t)
endif
set udg_TRK_Index = udg_TRK_Index + 1
endif
endfunction
function Trig_Trackables_System_Main takes nothing returns boolean
local real xmax = GetRectMaxX(udg_TRK_Rect)
local real xmin = GetRectMinX(udg_TRK_Rect)
local real ymax = GetRectMaxY(udg_TRK_Rect)
set udg_TRK_y = GetRectMinY(udg_TRK_Rect)
if udg_TRK_HoverTrigger != null then
call TriggerAddCondition(udg_TRK_HoverTrigger , Condition(function Trig_Trackables_System_InitVariables))
endif
if udg_TRK_ClickTrigger != null then
call TriggerAddCondition(udg_TRK_ClickTrigger , Condition(function Trig_Trackables_System_InitVariables))
endif
loop
exitwhen udg_TRK_y >= ymax
set udg_TRK_x = xmin
loop
exitwhen udg_TRK_x >= xmax
//Create Trackable for each player
call ForForce(udg_TRK_Players, function Trig_Trackables_System_PickPlayers)
set udg_TRK_x = udg_TRK_x + udg_TRK_Spacing
endloop
set udg_TRK_y = udg_TRK_y + udg_TRK_Spacing
endloop
if udg_TRK_Players != bj_FORCE_ALL_PLAYERS then
call DestroyForce(udg_TRK_Players)
endif
set udg_TRK_HoverTrigger = null
set udg_TRK_ClickTrigger = null
return false
endfunction
//===========================================================================
function InitTrig_Trackables_System takes nothing returns nothing
set gg_trg_Trackables_System = CreateTrigger()
set udg_TRK_Hashtable = InitHashtable()
set udg_TRK_Point = Location(0, 0)
set udg_TRK_Index = 0
call TriggerAddCondition(gg_trg_Trackables_System, Condition(function Trig_Trackables_System_Main))
endfunction