How to: Use Trackables

wonderpriest

New Member
Reaction score
18
Trackables
A trackable is just something like a doodad, let's say. But it is different as it can't be selected, it can't be moved, it can't die, and it can't be eliminated. It doesn't even have to be seen if you don't want it to.
The point of a trackable is to harness the mouse detection for usage in triggers. Mouse detection just means the game registers when your mouse pointer moves over an object, or clicks it.

FAQ
As I get more questions, I will answer them here so you don't have to sift through the posts.
Code:
Q. Do trackables work in multiplayer maps?
A. Yes, they work fine. As for tracking which player triggered the trackable, you would need a handler system for that.

Limitations
Although Blizzard gave us these functions to use mouse detection, it doesn't seem they really cared to finsh the code, because you can not retrieve a triggering player from a trackable event. Nor can a trackable be owned by a player.
The usage of trackables is very limited, because you can not manipulate anything about a trackable once you create it, or before. This means you can not move, scale, color, or make any other kind of modification. You just create it, and that's it.
Also, one of the reasons not many people know of trackables, is because they require JASS to fully use. You can create and manipulate trackables through the Custom Script action, but there is no event in GUI that uses trackables.
Fortunately, the functions are not very hard to understand and require little, if any, JASS knowledge.


Usage
I wanted to bring these trackables to attention, because even many JASSers seem to not know what they are. Trackables are a powerful tool that can be used to make better interactive systems, and even things like mini-games.

To use trackables, first you must create them. They can not be pre-placed in a map, so you must make them through triggers. They are created somewhat like units are created, only you use a model string to determine the model of the trackable, not an id or name.
This is actually very useful, because you can use any valid model path. This includes units, buildings, doodads...anything with a model path. If you use a unit or buildiing model, the trackable will appear looking like a neutral hostile unit, with no team colors.
Trackables do play animations. If you want a trackable to be invisible, you just insert a void string argument (""). Here is the function to create a trackable:

Code:
CreateTrackable(string modelpath, real x, real y, real facing)

modelpath is the path of the model you would like to use. Use "" for an invisable trackable. Remember to use \\ instead of \.
real x and real y are the coordinates of the location to create the trackable
facing is the angle that the trackable faces (remember this cannot be changed after creation)

The events for trackables are as follows:

Code:
TriggerRegisterTrackableHitEvent(trigger whichTrigger, trackable t)
TriggerRegisterTrackableTrackEvent(trigger whichTrigger, trackable t)

trackable is a handle that you use like any other handle (unit, location...).

TriggerRegisterTrackableHitEvent registers when a player clicks on a trackable. TriggerRegisterTrackableTrackEvent registers when a player moves his mouse across a trackable.
You may notice that this same system is in place with normal units in Warcraft III. When you click a unit, you select it. When you pass over a unit with your mouse, a bar shows it's health.
Trackable events work like any other event, but you also need to specify a trackable for the event to register.

A Trigger:
This trigger will create a trackable, and when someone passes over it, a message will be sent.
Code:
function Massage takes nothing returns nothing
    call DisplayTextToForce(GetPlayersAll(),"Peasant: OOh, that feels nice.") //Displays the pleasure of the peasant when we rub him with our mouse
endfunction

//===========================================================================
function InitTrig_zomg takes nothing returns nothing
 local trigger t=CreateTrigger() //Creates the trigger
 local trackable tr=CreateTrackable("units\\human\\Peasant\\Peasant.mdl",0,0,-90) //Creates our trackable, with the peasant model
    call TriggerRegisterTrackableTrackEvent(t,tr) //Registers when someone passes over tr with their mouse
    call TriggerAddAction(t,function Massage) //Calls our actions function
endfunction

You may notice I display the message to all players. This is because there is no 'GetTriggeringPlayer' for a trackable event, which is probably the biggest limitation of trackables. But, there is a 'GetTriggeringTrackable'. Which opens up possibilites to fix the missing TriggeringPlayer problem. (With 'GetTriggeringTrackable', you may be able to stimulate a Triggering Player, maybe by using the Handle Vars or another system)

The Result:
trackablevf2.jpg




ADD: Trackable Workarounds (credits to KaTTana)

Using Handle Vars With Trackables
KaTTana wrote this part better than I can, so here it is.
You can find KaTTana's Trackables tutorial here: Link
You can find KaTTana's Handle Var turorial here: Link

A Part of KaTTana's Tutorial:
"We don't have any natives for getting the (x,y) coordinates of a trackable, but we can handle that ourselves with the Local Handle Variables.
Here is a custom API for extended use of trackables.

Code:
// ===========================
//   Trackable API

function GetTrackableX takes trackable tc returns real
    return GetHandleReal(tc, "x")
endfunction
function GetTrackableY takes trackable tc returns real
    return GetHandleReal(tc, "y")
endfunction
function GetTrackableFacing takes trackable tc returns real
    return GetHandleReal(tc, "facing")
endfunction
function GetTrackablePath takes trackable tc returns string
    return GetHandleString(tc, "path")
endfunction

function NewTrackable takes string path, real x, real y, real facing returns trackable
    local trackable tc = CreateTrackable(path, x, y, facing)
    call SetHandleReal(tc, "x", x)
    call SetHandleReal(tc, "y", y)
    call SetHandleReal(tc, "facing", facing)
    call SetHandleString(tc, "path", path)
    return tc
endfunction

Trackables in Multiplayer
Previously, the tutorial stated that trackables didn't work in multiplayer, but that was wrong. They work fine, and they don't desynchronize the game.
However, there is no way to determine which player triggered the event on a trackable. We can work around this by creating a trackable for each player - each can only be triggered by one player.

Code:
    // t1 and t2 are visually the same trackable, but in fact they only work for one player each
    local trackable t1 // Player 1's trackable
    local trackable t2 // Player 2's trackable
    local string peasant = "units\\human\\Peasant\\Peasant.mdl"
    local string invisible = ""
    local string path = invisible

    if ( GetLocalPlayer() == Player(0) ) then
        set path = peasant
    endif
    set t1 = CreateTrackable(path, -500, 0, 0)

    set path = invisible
    if ( GetLocalPlayer() == Player(1) ) then
        set path = peasant
    endif
    set t2 = CreateTrackable(path, -500, 0, 0)

    call SetHandleInt(t1, "player", 0) // Store which player "owns" this trackable
    call SetHandleInt(t2, "player", 1) // Same for player 2

    // Add events to register track/hit on t1 and t2...

After this, you can determine the player triggering a trackable by reading the local integer named "player" on the triggering trackable.

We can extend to NewTrackable if you like:
Code:
function GetTrackableOwner takes trackable t returns player
    return Player(GetHandleInt(t, "player"))
endfunction

function NewTrackable takes string path, real x, real y, real facing, player owner returns trackable
    local trackable tc
    local string invisible = ""
    if GetLocalPlayer() != owner then
        set path = invisible
    endif
    set tc = CreateTrackable(path, x, y, facing)
    call SetHandleReal(tc, "x", x)
    call SetHandleReal(tc, "y", y)
    call SetHandleReal(tc, "facing", facing)
    call SetHandleString(tc, "path", path)
    call SetHandleInt(tc, "player", GetPlayerId(owner))
    return tc
endfunction

Giving height to Trackables

Although the natives do not allow it, a simple workaround enables us to create trackables at a given height above ground.
Code:
function CreateTrackableZ takes string path, real x, real y, real z, real face returns trackable
    local destructable d = CreateDestructableZ( 'OTip', x, y, z, 0.00, 1, 0 )
    local trackable tr = CreateTrackable( path, x, y, face )
    call RemoveDestructable( d )
    set d = null
    return tr
endfunction
It works by creating an Invisible Platform at the given height, and then creating the trackable on top of that. After removing the platform, the trackable stays in place."
_________________________________________________________________

Once again, that was part of KaTTana's trackable tutorial, which you can find here: Link


That's it for the Trackables tutorial, thanks for reading, and hope you have fun using these in your map!

Questions, comments, and suggestions are welcome, and appreciated!

ADD: If anyone finds this confusing, or wants a demo map to look at, just say iit and I will make a demo map using all of the Trackable functions.
 

lllidan

New Member
Reaction score
22
Trackables suck because you can't use them in multiplayer maps. :mad:

But nice tutorial nonetheless, +rep.
 

wonderpriest

New Member
Reaction score
18
bump (from second page)

I would really appreciate any input on this tutorial, whether it be praise or criticism :)
 

dashival

New Member
Reaction score
11
That's pretty awesome! Even though I don't know jass, it seems like it could be very useful =P

A+
 

wonderpriest

New Member
Reaction score
18
Thank you guys.

Dashival, I was fearing that people wouldn't understand or ignore this tutorial because it uses some JASS. It seems even Vexorian's and Daelin's tutorials aren't being understood by alot of people.

How does the idea of an extremely simple JASS guide thing, which lays down some rules of syntax and other things? I mean even more basic than the other 'basic' tutorials, so people can understand a bit more of coding rules and stuff. Please tell me what you think.
 

dashival

New Member
Reaction score
11
That would be pretty cool. I'd like if it there were a tutorial that simply showed you how the very most basic trigger works in jass, like showing how to send a message to all players, and then like explaining each part of the syntax or something.

I'm already skilled in C++ and VB, and various other languages, so JASS shouldn't be that big of a deal to me. :)
 

martix

There is no spoon
Reaction score
49
Well first JASS is a program language, then its WC3 programming language.
That means that first you've got to have some experience in proggraming, knowing basic constructions, syntax and the characteristic term definitions.

P.S. If you know C, then JASS would be really simple for you to learn(you might even find it quite limited) :)
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
This is a great tutorial. Very detailed, and easy to understand. :)

BTW, do you know if this part is even possible?:

>>(With 'GetTriggeringTrackable', you may be able to stimulate a Triggering Player, maybe by using the Handle Vars or another system)

Also, will it create lag if you create many of them?
 

wonderpriest

New Member
Reaction score
18
martix said:
(you might even find it quite limited) :)
Limited indeed.

Darthfett said:
BTW, do you know if this part is even possible?:
>>(With 'GetTriggeringTrackable', you may be able to stimulate a Triggering Player, maybe by using the Handle Vars or another system)
I did some searching, and I found that KaTTana himself already made a Trackable tutorial at wc3jass.com, and he also explains how you can use the handle system to simulate the triggering player. I will be adding how to do this soon.


Darthfett said:
Also, will it create lag if you create many of them?
I made a test map with a trackable 'grid', and I had 84 trackables and experienced no lag. Of course, they weren't all on-screen at the time. So, you would still need to watch out for how many are on screen, but I think you could safely create many of these throughout the map, probably because they don't take as much looking-after as normal units do, with health, mana, custom data, and all that other good stuff.
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Ahhhhh!!! JASS = :confused:

I seriously do not understand JASS or A++ or whatever. The tutorials don't even help, I don't understand a thing. Sorry wonderpriest, I seriously don't understand JASS.

~3TY.Spiky
_______________
Tauren Tag​
A new tag map with Taurens as the taggers! Same gameplay ideas, not the same map as Sheep Tag. Runners have to build a base to survive against the Taurens and must last 30 minutes to win. Taurens must pulverize all the Runners within 30 minutes to win. Download Tauren Tag here. Want to learn how to make a tag map? Go to my Tutorial to learn how!
 

Halo_king116

Working As Intended
Reaction score
153
I am no JASS expert, even though learning JASS would benefit my skills in many ways... But here we go...

I think this will bring "Pleasure Kerrigan" to a Warcraft game. More advanced though... Scary thought.

But anyways, the tutorial is organized, easy to read, and even has a nice picture :)

You also gave refrence to another tutorial, and gave him/her full credits. Good job on that.

It is also detailed and to me it seemed thorough (sp?). Though I wouldn't know as I could only understand bits of the code.

Good job! :)
 

wonderpriest

New Member
Reaction score
18
Pahl said:
I think its great, diden't know you could do that :)
Yep, that's the main reason I wrote the tutorial, so trackables could be brought to attention. Like I said, not even alot of JASSers know about them, and they can be used to make great things.

So, anything I can improve or explain a bit more?
 

wonderpriest

New Member
Reaction score
18
So...should I just let this die :p

I am willing to write an introduction that shows how to use the functions, for non-JASS users. Don't be discouraged because trackables require JASS, it's really very easy, and I can help you :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
  • The Helper The Helper:
    Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs
  • Monovertex Monovertex:
    @The Helper I'm really not seeing the "Signature" link in the sidebar on that page. Here's a screenshot:
  • The Helper The Helper:
    I have reported it - I was wondering why nobody I have given sigs to over the last few years have used them

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top