Blizzard Modding Network

Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chaos Arena - A Warcraft III mod
Check all that happens in this network through BLIZZARD MODDING.INFO

* Announcements!!

  • We're now at wc3 top 200 lists. Please vote for us.
  • WC3jass.com has a new theme, very similar to the original but lighter to load. If you have any suggestions or comments about it, just post it here.
  • We are getting more social!!! Visit the new social group section and create your own group with your friends

Jass New Gen Pack

Download Jass New Generation Pack (JNGP) to use all the vJASS & Zinc scripts posted in any of the Blizzardmodding sites.

Author Topic: [System] Track  (Read 2065 times)

Offline Purgeandfire

  • Newbie - level 4
  • ****
  • Posts: 35
  • Reputation: 13
  • Referrals: 0
    • View Profile
    • Awards
[System] Track
« on: July 24, 2012, 04:51:41 PM »
This manages trackable objects in such a way that it actually improves functionality and has an interface to make even the toughest projects very readable.

It allows you to:
- Create trackables for specific players. (without desyncs)
- Easily register a trackable click and trackable hover.
- Retrieve which player clicked the trackable.
- Retrieve trackable information - the model, x, y, z,  and facing.

Trackable2 allows for similar functionality, but this one is improved in both speed and handle efficiency. There are some cases where trackable2 has unnecessary lag/freezes, but the Track library fixes it.

This is one of the only systems I haven't completely rewritten time and time again. :) 

This is the same thing as the hive version but I improved the documentation a bit for readability.

Code: jass
  1. library Track /* v3.0.0.0
  2. *******************************************************************
  3. *
  4. *   Manages trackable objects, allowing for easy event
  5. *   registrations, data retrieval, and adds the capability of
  6. *   retrieving which player interacted with the trackable.
  7. *
  8. *******************************************************************
  9. *
  10. *   */uses/*
  11. *  
  12. *       */ Table /*       hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
  13. *
  14. *******************************************************************
  15. *
  16. *   SETTINGS
  17. */
  18. globals
  19.     private constant integer PLATFORM = 'Otip'
  20. endglobals
  21. /*
  22. *******************************************************************
  23. *
  24. *    FUNCTIONS
  25. *
  26. *        function CreateTrack takes string modelPath, real x, real y, real z, real facing returns Track
  27. *
  28. *            - Creates a trackable of "modelPath" at the coordinates
  29. *              (x, y, z) with "facing" in degrees.
  30. *
  31. *        function CreateTrackForPlayer takes string modelPath, real x, real y, real z, real facing returns Track
  32. *
  33. *            - Same as above, but for only one player to interact with.
  34. *
  35. *        function RegisterAnyClickEvent takes code c returns nothing
  36. *
  37. *            - The function input will be called whenever a trackable
  38. *              is clicked.
  39. *
  40. *        function RegisterAnyHoverEvent takes code c returns nothing
  41. *
  42. *            - The function input will be called whenever a player
  43. *              hovers over a trackable.
  44. *
  45. *        function RegisterClickEvent takes Track obj, code c returns nothing
  46. *
  47. *            - The code will be executed every time a trackable of the
  48. *              instance 'obj' is clicked.
  49. *
  50. *        function RegisterHoverEvent takes Track obj, code c returns nothing
  51. *
  52. *            - The code will be executed every time a trackable of the
  53. *              instance 'obj' is hovered over.
  54. *
  55. *        function EnableTrackInstance takes Track obj, boolean flag returns nothing
  56. *
  57. *            - Enables trackable events for the instance.
  58. *            - All instances are enabled by default.
  59. *
  60. *        function IsTrackInstanceEnabled takes Track obj returns boolean
  61. *
  62. *            - Returns whether or not an instance has its events enabled.
  63. *
  64. *    EVENT RESPONSES
  65. *
  66. *        function GetTriggerTrackInstance takes nothing returns Track
  67. *
  68. *            - Returns the Track instance that had a player interaction.
  69. *
  70. *        function GetTriggerTrackable takes nothing returns trackable
  71. *
  72. *            - Returns the trackable object that had a player interaction.
  73. *
  74. *        function GetTriggerTrackablePlayer takes nothing returns player
  75. *
  76. *            - Returns the player that had interacted with the trackable object.
  77. *
  78. *******************************************************************
  79. *
  80. *   struct Track
  81. *
  82. *        static Track instance
  83. *
  84. *           - The triggering instance of the event.
  85. *
  86. *        static trackable object
  87. *
  88. *           - The triggering trackable object of the event.
  89. *
  90. *        static player tracker
  91. *
  92. *           - The player who interacted with the trackable object of the event.
  93. *
  94. *        readonly real x
  95. *        readonly real y
  96. *        readonly real z
  97. *
  98. *           - The coordinates (x, y, z) of the trackable object.
  99. *
  100. *        readonly real facing
  101. *
  102. *           - The facing angle of the trackable object.
  103. *
  104. *        readonly string model
  105. *
  106. *           - The string path of the trackable object.
  107. *
  108. *        method operator enabled takes nothing returns boolean
  109. *        
  110. *        static method create takes string modelPath, real x, real y, real z, real facing returns Track
  111. *
  112. *        static method createForPlayer takes string modelPath, real x, real y, real z, real facing, player p returns Track
  113. *
  114. *
  115. *        static method registerAnyClick takes code c returns nothing
  116. *
  117. *        static method registerAnyHover takes code c returns nothing
  118. *
  119. *        method registerOnClick takes code c returns nothing
  120. *
  121. *        method registerOnHover takes code c returns nothing
  122. *
  123. *        method enable takes nothing returns nothing
  124. *
  125. *        method disable takes nothing returns nothing
  126. *
  127. *            - All of the above are the struct interface equivalents of the functions.
  128. *
  129. ********************************************************************
  130. *    
  131. *    Credits
  132. *       - Azlier for Trackable2
  133. *
  134. ********************************************************************/
  135.    
  136.     private module Init
  137.         private static method onInit takes nothing returns nothing
  138.             set thistype.TrackTable     = Table.create()
  139.         endmethod
  140.     endmodule
  141.  
  142.     struct Track extends array
  143.         private static trigger anyClick = CreateTrigger()
  144.         private static trigger anyHover = CreateTrigger()
  145.         private static Table TrackTable = 0
  146.        
  147.         static thistype  instance = 0
  148.         static trackable object   = null
  149.         static player    tracker  = null
  150.        
  151.         private static integer ic = 0
  152.         private static integer ir = 0
  153.         private thistype rn
  154.        
  155.         readonly real    x
  156.         readonly real    y
  157.         readonly real    z
  158.         readonly real    facing
  159.         readonly string  model
  160.        
  161.         private boolean  flag
  162.         private trigger  reg
  163.         private trigger  onClick
  164.         private trigger  onHover
  165.        
  166.         static method registerAnyClick takes code c returns nothing
  167.             call TriggerAddCondition(.anyClick, Filter(c))
  168.         endmethod
  169.  
  170.         static method registerAnyHover takes code c returns nothing
  171.             call TriggerAddCondition(.anyHover, Filter(c))
  172.         endmethod
  173.        
  174.         method registerClick takes code c returns nothing
  175.             if .onClick == null then
  176.                 set .onClick = CreateTrigger()
  177.             endif
  178.             call TriggerAddCondition(.onClick, Filter(c))
  179.         endmethod
  180.  
  181.         method registerHover takes code c returns nothing
  182.             if .onHover == null then
  183.                 set .onHover = CreateTrigger()
  184.             endif
  185.             call TriggerAddCondition(.onHover, Filter(c))
  186.         endmethod
  187.        
  188.         method destroy takes nothing returns nothing
  189.             call TrackTable.remove(GetHandleId(.reg))
  190.             call TrackTable.remove(GetHandleId(.object))
  191.             call DestroyTrigger(.reg)
  192.             call DestroyTrigger(.onClick)
  193.             call DestroyTrigger(.onHover)
  194.             set .rn = ir
  195.             set ir  = this
  196.         endmethod
  197.        
  198.         method enable takes nothing returns nothing
  199.             set this.flag = true
  200.         endmethod
  201.  
  202.         method disable takes nothing returns nothing
  203.             set this.flag = false
  204.         endmethod
  205.  
  206.         method operator enabled takes nothing returns boolean
  207.             return this.flag
  208.         endmethod
  209.        
  210.         private static method onInteract takes nothing returns boolean
  211.             local thistype  temp = instance
  212.             local trackable tr   = object
  213.             local player    p    = tracker
  214.            
  215.             set instance = TrackTable[GetHandleId(GetTriggeringTrigger())]
  216.             set object   = GetTriggeringTrackable()
  217.             set tracker  = Player(TrackTable[GetHandleId(object)])
  218.            
  219.             if instance.flag then
  220.                 if GetTriggerEventId() == EVENT_GAME_TRACKABLE_TRACK then
  221.                     call TriggerEvaluate(instance.onHover)
  222.                     call TriggerEvaluate(anyHover)
  223.                 else
  224.                     call TriggerEvaluate(instance.onClick)
  225.                     call TriggerEvaluate(anyClick)
  226.                 endif
  227.             endif
  228.            
  229.             set instance = temp
  230.             set tracker  = p
  231.             set object   = tr
  232.             set tr = null
  233.             set p  = null
  234.             return false
  235.         endmethod
  236.        
  237.         private static method createTrack takes string modelPath, real x, real y, real z, real facing, player j returns thistype
  238.             local destructable dest = null
  239.             local thistype     this = ir
  240.             local integer      i    = 11
  241.             local trackable tr
  242.             local player p
  243.             local string s
  244.             if this == 0 then
  245.                 set ic   = ic + 1
  246.                 set this = ic
  247.             else
  248.                 set ir   = .rn
  249.             endif
  250.             if z != 0 then
  251.                 set dest = CreateDestructableZ(PLATFORM, x, y, z, 0, 1, 0)
  252.             endif
  253.             if j != null then
  254.                 set i    = GetPlayerId(j)
  255.             endif
  256.             set .x = x
  257.             set .y = y
  258.             set .z = z
  259.             set .flag    = true
  260.             set .facing  = facing
  261.             set .model   = modelPath
  262.             set .reg     = CreateTrigger()
  263.             set .onClick = null
  264.             set .onHover = null
  265.             set TrackTable[GetHandleId(.reg)] = this
  266.             call TriggerAddCondition(.reg, Condition(function thistype.onInteract))
  267.             loop
  268.                 set p = Player(i)
  269.                 if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
  270.                     if GetLocalPlayer() == p then
  271.                         set s = modelPath
  272.                     else
  273.                         set s = ""
  274.                     endif
  275.                     set tr = CreateTrackable(.model, .x, .y, .facing)
  276.                     call TriggerRegisterTrackableHitEvent(.reg, tr)
  277.                     call TriggerRegisterTrackableTrackEvent(.reg, tr)
  278.                     set TrackTable[GetHandleId(tr)] = i
  279.                     if j != null then
  280.                         exitwhen true
  281.                     endif
  282.                 endif
  283.                 exitwhen i == 0
  284.                 set i = i - 1
  285.             endloop
  286.             if dest != null then
  287.                 call RemoveDestructable(dest)
  288.                 set dest = null
  289.             endif
  290.             set p  = null
  291.             set tr = null
  292.             return this
  293.         endmethod
  294.        
  295.         static method create takes string modelPath, real x, real y, real z, real facing returns thistype
  296.             return thistype.createTrack(modelPath, x, y, z, facing, null)
  297.         endmethod
  298.        
  299.         static method createForPlayer takes string modelPath, real x, real y, real z, real facing, player p returns thistype
  300.             if not (GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER) then
  301.                 return 0
  302.             endif
  303.             return thistype.createTrack(modelPath, x, y, z, facing, p)
  304.         endmethod
  305.        
  306.         implement Init
  307.     endstruct
  308.    
  309.     function CreateTrack takes string modelPath, real x, real y, real z, real facing returns Track
  310.         return Track.create(modelPath, x, y, z, facing)
  311.     endfunction
  312.    
  313.     function CreateTrackForPlayer takes string modelPath, real x, real y, real z, real facing, player who returns Track
  314.         return Track.createForPlayer(modelPath, x, y, z, facing, who)
  315.     endfunction
  316.    
  317.     function EnableTrackInstance takes Track instance, boolean flag returns nothing
  318.         if flag then
  319.             call instance.enable()
  320.         else
  321.             call instance.disable()
  322.         endif
  323.     endfunction
  324.    
  325.     function IsTrackInstanceEnabled takes Track instance returns boolean
  326.         return instance.enabled
  327.     endfunction
  328.    
  329.     function RegisterAnyClickEvent takes code c returns nothing
  330.         call Track.registerAnyClick(c)
  331.     endfunction
  332.    
  333.     function RegisterAnyHoverEvent takes code c returns nothing
  334.         call Track.registerAnyHover(c)
  335.     endfunction
  336.    
  337.     function RegisterClickEvent takes Track obj, code c returns nothing
  338.         call obj.registerClick(c)
  339.     endfunction
  340.    
  341.     function RegisterHoverEvent takes Track obj, code c returns nothing
  342.         call obj.registerHover(c)
  343.     endfunction
  344.    
  345.     function GetTriggerTrackInstance takes nothing returns Track
  346.         return Track.instance
  347.     endfunction
  348.    
  349.     function GetTriggerTrackable takes nothing returns trackable
  350.         return Track.object
  351.     endfunction
  352.    
  353.     function GetTriggerTrackablePlayer takes nothing returns player
  354.         return Track.tracker
  355.     endfunction
  356.  
  357. endlibrary

API List:
Code: jass
  1. function CreateTrack takes string modelPath, real x, real y, real z, real facing returns Track
  2.  
  3. function CreateTrackForPlayer takes string modelPath, real x, real y, real z, real facing returns Track
  4.  
  5. function RegisterAnyClickEvent takes code c returns nothing
  6.  
  7. function RegisterAnyHoverEvent takes code c returns nothing
  8.  
  9. function RegisterClickEvent takes Track obj, code c returns nothing
  10.  
  11. function RegisterHoverEvent takes Track obj, code c returns nothing
  12.  
  13. function EnableTrackInstance takes Track obj, boolean flag returns nothing
  14.  
  15. function IsTrackInstanceEnabled takes Track obj returns boolean
  16.  
  17. function GetTriggerTrackInstance takes nothing returns Track
  18.  
  19. function GetTriggerTrackable takes nothing returns trackable
  20.  
  21. function GetTriggerTrackablePlayer takes nothing returns player

If you need a sample, then check out the demo map below.
« Last Edit: July 24, 2012, 07:08:27 PM by Purgeandfire »

Online moyack

  • Site Owner
  • Administrator
  • Frequent - level 2
  • *
  • Posts: 1707
  • Reputation: 1144
  • Site Admin - I love fix things
  • Referrals: 0
    • View Profile
    • Blizzard Modding Information Center
    • Awards
Re: [System] Track
« Reply #1 on: July 25, 2012, 10:59:25 PM »
The system has a very nice presentation, I like the implementation and the test map is lovely. Approvezord'ed


We can give you full hosting for your projects. Not only a forum, a complete page!!.

A custom altered melee map where you can play Naga and Demons. Featuring a nice additions in features and game style. Check it out!!

Offline LembidiZ

  • Rookie - level 1
  • *
  • Posts: 67
  • Reputation: 2
  • A FRENGERS
  • Referrals: 0
    • View Profile
    • Awards
Re: [System] Track
« Reply #2 on: August 03, 2012, 05:48:26 AM »
Haha.. Nice, why PnF inactive on Hive??
I think Hive are suck now ( BECAUSE TO ARROGANT!! ) :) :)
PS:
moyack, I added you to my credit list ( Every map i was made ) Without reason..

Online moyack

  • Site Owner
  • Administrator
  • Frequent - level 2
  • *
  • Posts: 1707
  • Reputation: 1144
  • Site Admin - I love fix things
  • Referrals: 0
    • View Profile
    • Blizzard Modding Information Center
    • Awards
Re: Re: [System] Track
« Reply #3 on: August 03, 2012, 04:32:33 PM »
PS:
moyack, I added you to my credit list ( Every map i was made ) Without reason..
All in your lifeshould have a reason, I hope something mine is helping you inn your map :)


We can give you full hosting for your projects. Not only a forum, a complete page!!.

A custom altered melee map where you can play Naga and Demons. Featuring a nice additions in features and game style. Check it out!!

Offline LembidiZ

  • Rookie - level 1
  • *
  • Posts: 67
  • Reputation: 2
  • A FRENGERS
  • Referrals: 0
    • View Profile
    • Awards
Re: [System] Track
« Reply #4 on: August 04, 2012, 12:08:52 AM »
Because you made this helping site  :P  :P

Tags:
 

[System] ElapsedGameTime

Started by Magtheridon96

Replies: 0
Views: 742
Last post January 11, 2012, 01:30:59 PM
by Magtheridon96
[System] Unit Recycler & Simple Damage Detection System

Started by moyack

Replies: 5
Views: 1546
Last post August 20, 2012, 01:02:03 AM
by moyack
[System] ModeManager

Started by Magtheridon96

Replies: 0
Views: 786
Last post July 09, 2012, 01:33:55 PM
by Magtheridon96
[System] Heal

Started by Magtheridon96

Replies: 9
Views: 2905
Last post August 13, 2012, 07:25:13 PM
by LembidiZ
[System] SoundTools

Started by Magtheridon96

Replies: 0
Views: 962
Last post July 09, 2012, 01:43:19 PM
by Magtheridon96
  UDMod Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Vote for Blizzmod at Warcraft 3 Top 200 - Cheats Free Clans and Resources