System Trackables (Extended Trackables)

Reaction score
341
Trackables
TriggerHappy187​
Current Version v1.01

This is a little library i made that extends the functions of trackables... and thats about it.
What is a trackable?
A trackable is a model displayed in the game, similiar to a special effect.
It stands out by being able to detect whenever the mouse moves over this model, and when the mouse clicks it.
Problems are that we cannot delete, move or hide a trackable again. - Katana

Credits
  • KaTTaNa - For CreateTrackableZ

Changelog

Version 1.01
  • Inlined Functions
  • New Function ClearTrackableData

Functions - 9 Total
JASS:
function CreateTrackableEx takes string trackableModelPath, real x, real y, real f returns trackable


JASS:
function GetTrackableX takes trackable t returns real


JASS:
function GetTrackableY takes trackable t returns real


JASS:
function GetTrackableZ takes trackable t returns real


JASS:
function GetTrackableFacing takes trackable t returns real


JASS:
function GetTrackableLoc takes trackable t returns location


JASS:
function CreateTrackableZ takes string s, real x, real y, real z, real f returns trackable


JASS:
function CreateTrackablePlayerZ takes player p, string s, real x, real y, real z, real f returns trackable


JASS:
function CreateTrackablePlayer takes player p, string trackableModelPath, real x, real y, real facing returns trackable


JASS:
function ClearTrackableData takes nothing returns nothing

Library

JASS:
library TrackableSystem

globals
    private constant gamecache TRACK_DATA = InitGameCache("TrackableSystem.w3v")
endglobals

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private struct Data
    
    real x
    real y
    real f
    real z
    
    static method create takes real x, real y, real f, real z, trackable t returns Data
        local Data d = Data.allocate()
        set d.x = x
        set d.y = y
        set d.f = f
        set d.x = x
        call StoreInteger(TRACK_DATA, I2S(H2I(t)), "", d)
        return d
    endmethod
    
endstruct

function ClearTrackableData takes nothing returns nothing
    call FlushGameCache(TRACK_DATA)
endfunction

function CreateTrackableEx takes string trackableModelPath, real x, real y, real f returns trackable
    local trackable t = CreateTrackable(trackableModelPath, x, y, f)
    local Data d = Data.create(x,y,f,0,t)
    return t
endfunction

function GetTrackableX takes trackable t returns real
    return Data(GetStoredInteger(TRACK_DATA, "", I2S(H2I(t)))).x
endfunction

function GetTrackableY takes trackable t returns real
    return Data(GetStoredInteger(TRACK_DATA, "", I2S(H2I(t)))).y
endfunction

function GetTrackableZ takes trackable t returns real
    return Data(GetStoredInteger(TRACK_DATA, "", I2S(H2I(t)))).z
endfunction

function GetTrackableFacing takes trackable t returns real
    return Data(GetStoredInteger(TRACK_DATA, "", I2S(H2I(t)))).f
endfunction

function GetTrackableLoc takes trackable t returns location
    local Data d = GetStoredInteger(TRACK_DATA, "", I2S(H2I(t)))
    return Location(d.x, d.y)
endfunction

function CreateTrackableZ takes string s, real x, real y, real z, real f returns trackable
    local destructable d = CreateDestructableZ('OTip',x,y,z,0.00,1,0)
    local trackable tr = CreateTrackableEx(s,x,y,f)
    call RemoveDestructable(d)
    set d = null
    return tr
endfunction

function CreateTrackablePlayerZ takes player p, string s, real x, real y, real z, real f returns trackable
    local destructable d = CreateDestructableZ('OTip',x,y,z,0.00,1,0)
    local string path = ""
    if GetLocalPlayer() == p then
        set path = s
    endif
    call RemoveDestructable(d)
    set d = null
    return CreateTrackable(path,x,y,f)
endfunction

function CreateTrackablePlayer takes player p, string trackableModelPath, real x, real y, real facing returns trackable 
    local string path = ""
    if GetLocalPlayer() == p then
        set path = trackableModelPath
    endif
    return CreateTrackableEx(path, x, y, facing)
endfunction


endlibrary


Enyjoy!
 

Attachments

  • Trackables.w3x
    9.2 KB · Views: 193

Romek

Super Moderator
Reaction score
963
This seems like a bunch of BJs. Not much usability, really.

---------

JASS:
call StoreInteger(TRACK_DATA, I2S(H2I(t)), I2S(H2I(t)), d)

Any reason why you're using "I2S(H2I(t))" twice there?
Just make the second string "a" or something.

---------

JASS:
local Data d = GetStoredInteger(TRACK_DATA, I2S(H2I(t)), I2S(H2I(t)))
    return d.z

Could be:
JASS:
return Data(GetStoredInteger(TRACK_DATA, I2S(H2I(t)), I2S(H2I(t)))).z


...And that applies to all the other, similar (BJ-ish) functions.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Romek, your optimizing will also get inlined by Jasshelper. (I think it will.)
 

Ghostwind

o________o
Reaction score
172
What the fuck does this do? Explanations for newbies FTW.

This seems like a bunch of BJs. Not much usability, really.

Really? If I could have a bunch of BJs I'd be pretty damn happy ;P
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> In what way?

Well, for example, by looking at post #1... I've no idea what I would do with this. Or what the point of this library would be. Or why I would need it if I were to use trackables.


Btw, the correct way to use a gamecache is init - flush - init, in that order.
 
Reaction score
341
I've no idea what I would do with this

Well, it is useful for full screen things (Inventories, Menus ect..) and also could be useful for some mini-games.

I know i'll be using it so.... Just because you have no use for it doesn't mean others wont.

Btw, the correct way to use a gamecache is init - flush - init, in that order.

Thanks.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> it is useful ...

I hope so.
But, what for? What is this? What is it doing? Why would I want to use your library for it?

You're posting here in "tutorials and resources".
The required minimum is a decent description and explanation!
For now it's just a bunch of functions.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Gamecache is a bit outdated, but that doesn't make it a bad system. :p

This seems like a bunch of BJs. Not much usability, really.

Yes it is an extra function call, but the point of a system is to make something easier. In this case, I don't think someone's going to want to type out

JASS:
local Data d = GetStoredInteger(TRACK_DATA, I2S(H2I(t)), I2S(H2I(t)))
    local location l = Location(d.x, d.y)
    ...
    DoSomething(l)


That I2S(H2I()) stuff is a bit tedious. This will also automatically store all the variables, so you only have to create with one function call, instead of doing a bunch of others.

Anyways, back to the original system:

JASS:
        call StoreInteger(TRACK_DATA, I2S(H2I(t)), I2S(H2I(t)), d)


save a few function calls and just do this:

JASS:
        call StoreInteger(TRACK_DATA, I2S(H2I(t)),"", d)


Each time they want to use the trackable.

BTW, since you're creating a local integer variable, I'm pretty sure functions like this:

JASS:
function GetTrackableX takes trackable t returns real
    local Data d = GetStoredInteger(TRACK_DATA, I2S(H2I(t)), I2S(H2I(t)))
    return d.x
endfunction


won't get inlined.

Inlining Rules:

Code:
How to make a function inlineable? The current algorithm basically follows these rules (which are subject to change to allow more functions to be considered inlineable in the future):

    * The function is a one-liner
    * If the function is called by call the function's contents must begin with set or call or be a return of a single function.
    * If the inlined function is an assigment (set) it should not assign one of its arguments.
    * Every argument must be evaluated once and only once by the function, in the same order as they appear in the arguments list.
    * If the function contains function calls, they should all be evaluated after the arguments UNLESS the function is marked as non-state changing, at the moment some very few native functions and also return bug exploiters are considered as non-state changing.

you might be able to do this for some of them (not sure if this syntax is possible):

JASS:
function GetTrackableX takes trackable t returns real
    return Data(GetStoredInteger(TRACK_DATA, I2S(H2I(t)),"")).x
endfunction


But this would probably make it inline-able if it doesn't give any errors.
 

Romek

Super Moderator
Reaction score
963

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Yep. However there is some problem with Gamecaches, which requires you initialize it, flush it, and initialize it again.

JASS:
...
        call StoreInteger(TRACK_DATA, I2S(H2I(t)), "", d)
...
    return Data(GetStoredInteger(TRACK_DATA, "", I2S(H2I(t)))).x
...

You have to keep the order of the "" and the I2S(H2I(t)) the same throughout. Either put I2S(H2I(t)) first, and then "" or the other way around.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top