Snippet Trackable2

JASS:
//* Table library by Vexorian

library Table initializer init
//***************************************************************
//* Table object
//* ------------
//*
//*   set t=Table.create() - instanceates a new table object
//*   call t.destroy()     - destroys it
//*   t[1234567]           - Get value for key 1234567
//*                          (zero if not assigned previously)
//*   set t[12341]=32      - Assigning it.
//*   call t.flush(12341)  - Flushes the stored value, so it
//*                          doesn't use any more memory
//*   t.exists(32)         - Was key 32 assigned? Notice
//*                          that flush() unassigns values.
//*   call t.reset()       - Flushes the whole contents of the
//*                          Table.
//*
//*   call t.destroy()     - Does reset() and also recycles the id.
//*
//*   If you use HandleTable instead of Table, it is the same
//* but it uses handles as keys, the same with StringTable.
//*
//***************************************************************

//=============================================================
    globals
        private constant integer MAX_INSTANCES=8100 //400000

    //=========================================================
        private gamecache gc
    endglobals

    private struct GTable[MAX_INSTANCES]
        method reset takes nothing returns nothing
            call FlushStoredMission(gc,I2S(this))
        endmethod

        private method onDestroy takes nothing returns nothing
            call FlushStoredMission(gc,I2S(this))
        endmethod
    endstruct

    //Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
    //! textmacro Table__make takes name, type, key
    struct $name$ extends GTable

        method operator [] takes $type$ key returns integer
            return GetStoredInteger(gc,I2S(this),$key$)
        endmethod

        method operator []= takes $type$ key, integer value returns nothing
            call StoreInteger(gc,I2S(this),$key$, value)
        endmethod

        method flush takes $type$ key returns nothing
            call FlushStoredInteger(gc,I2S(this),$key$)
        endmethod

        method exists takes $type$ key returns boolean
            return HaveStoredInteger(gc,I2S(this),$key$)
        endmethod

    endstruct
    //! endtextmacro



    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    //! runtextmacro Table__make("Table","integer","I2S(key)" )
    //! runtextmacro Table__make("StringTable","string","key" )
    //! runtextmacro Table__make("HandleTable","handle","I2S(H2I(key))" )

    //=============================================================
    // initialize it all.
    //
    private function init takes nothing returns nothing
        call FlushGameCache(InitGameCache("libtable.gc"))
        set gc=InitGameCache("libtable.gc")
    endfunction
endlibrary


Here is table and it works cool as it is so I don't get why you want to modify it at all.
 
While Jesus works, I announce that the Table version is up. Safer, but slower.
 
Unless you need MAAAAAXXXX EFFFFIIICCCCIIIENNNCCCYYY, game cache is just fine. Oh, and you probably would like a standardized cache like what Table uses because the limit on game caches is 256. Otherwise, I hear game cache is miserably slow.
 
Nice Table X Jesus, but please guys discuss the trackables system in this thread, thanks. :)
 
I know H2I and only H2I. I do want to use Table X, though. Was a great idea you had that I realized too late :p.

The things you gave me about attaching to triggers limits the amount of events on a trigger. I can't have that. I still don't see the problem with attaching the trackables.

Oh, and very minor update. GetTrackedPlayer() no longer requires an argument (I thought it looked silly).
 
>The things you gave me about attaching to triggers limits the amount of events on a trigger. I can't have that.

Linked-lists gets around that. But you probably don't know how to use those.

Table-X actually already works. You may use it, as long as you don't have to flush a whole table. Besides, you should always be able to just copy the latest version of Table-X in because it's meant to support Table's original interface as if it WAS Table. So by all means, give it a shot! :D

I still reckon GetTrackedPlayer() should be GetTrackingPlayer(). What do you think?
 
I'll try Table X when it's complete. For now, I'll use the wonderful string tactic it uses.

Speaking of which, another minor update. No longer requires MIN_HANDLE_ID setting.

And for Tracking player, I thought about that. The way I see it, trackables track the mouse actions of a player. Thus, the player is being tracked. TrackedPlayer.
 
Bump, and documented the functions (I knew I forgot something!)
 
Added UserData for trackables, because someone actually wanted such a crazy thing :nuts:.

Table version is most recommended. The old one is slower than game cache, and much less safe.
 
Oh, sure. When I'm in the process of making changes for EGUI with the "new" versions, you update it again... -_-'
 
No worries. GUI users have no need for trackable UserData.

The real thing I'm trying to fix is a small O(n) search. Tiny, but unacceptable! Must find way to fix without bloating code substantially, yes.
 
Well, after debating much with myself, I decided to port EGUI to using the struct in T2 instead of trying to make a bunch of EGUI wrappers for the Trackables since you have 12 in each set anyways.
 
Why would you want to use raw trackables over the structs themselves? Those functions I have essentially are EGUI wrappers.
 
Because GUI users would think it easier to use Trackables over integers (what structs ultimately parse into) and that Create Trackable, Set T = Last Created Trackable is easier than Set I = Create Trackable.

They wouldn't understand it much unless they knew some kind of programming language in which case they should be using (v)JASS.
 
You want a lastCreatedTrackable variable? Simple. Hold on for a few seconds...

JASS:
library Trackable2 initializer Init requires Table

private keyword Data

globals
    private HandleTable table
    private Data array Trackables
    private trackable TriggerTrackable
    private boolexpr SetLastBool
    private Data TriggerTrackable2
    Data lastCreatedTrackable2
endglobals

private function SetLast takes nothing returns boolean
    set TriggerTrackable = GetTriggeringTrackable()
    set TriggerTrackable2 = table[TriggerTrackable]
    //Make this return false if your trackable triggers are running on conditions only.
    return true
endfunction

private struct Data
    trackable array Trackers [12]
    real X
    real Y
    real Z
    real Facing
    string Model
    player ForPlayer = null
    integer UserData = 0
endstruct

function CreateTrackable2 takes string modelPath, real x, real y, real z, real facing returns Data
    local Data d = Data.create()
    local string s = ""
    local destructable platform = CreateDestructableZ('OTip',x,y,z,0.00,1,0)
    local integer i = 11
    loop
        exitwhen i < 0
        if GetLocalPlayer() == Player(i) then
            set s = modelPath
        else
            set s = ""
        endif
        set d.Trackers<i> = CreateTrackable(s, x, y, facing)
        set table[d.Trackers<i>] = d
        set i = i - 1
    endloop
    set d.X = x
    set d.Y = y
    set d.Z = z
    set d.Facing = facing
    set d.Model = modelPath
    call RemoveDestructable(platform)
    set platform = null
    set lastCreatedTrackable2 = d
    return d
endfunction

function CreateTrackable2ForPlayer takes string modelPath, real x, real y, real z, real facing, player forPlayer returns Data
    local Data d = Data.create()
    local string s = modelPath
    local destructable platform = CreateDestructableZ(&#039;OTip&#039;,x,y,z,0.00,1,0)
    if GetLocalPlayer() != forPlayer then
        set s = &quot;&quot;
    endif
    set d.Trackers[1] = CreateTrackable(s, x, y, facing)
    set table[d.Trackers[1]] = d
    set d.ForPlayer = forPlayer
    set d.X = x
    set d.Y = y
    set d.Z = z
    set d.Facing = facing
    set d.Model = modelPath
    call RemoveDestructable(platform)
    set platform = null
    set lastCreatedTrackable2 = d
    return d
endfunction

function TriggerRegisterTrackable2HitEvent takes trigger whichTrigger, Data d returns nothing
    local integer i
    if d.ForPlayer == null then
        set i = 11
        loop
            exitwhen i &lt; 0
            call TriggerRegisterTrackableHitEvent(whichTrigger, d.Trackers<i>)
            set i = i - 1
        endloop
    else
        call TriggerRegisterTrackableHitEvent(whichTrigger, d.Trackers[1])
    endif
    call TriggerAddCondition(whichTrigger, SetLastBool)
endfunction

function TriggerRegisterTrackable2TrackEvent takes trigger whichTrigger, Data d returns nothing
    local integer i
    if d.ForPlayer == null then
        set i = 11
        loop
            exitwhen i &lt; 0
            call TriggerRegisterTrackableTrackEvent(whichTrigger, d.Trackers<i>)
            set i = i - 1
        endloop
    else
        call TriggerRegisterTrackableTrackEvent(whichTrigger, d.Trackers[1])
    endif
    call TriggerAddCondition(whichTrigger, SetLastBool)
endfunction

function GetTriggeringTrackable2 takes nothing returns Data
    return TriggerTrackable2
endfunction

function GetTrackedPlayer takes nothing returns player
    local integer i
    //So very sorry about this O(n) search. Trying to remedy this.
    if TriggerTrackable2.ForPlayer == null then
        set i = 11
        loop
            exitwhen i &lt; 0
            if TriggerTrackable == TriggerTrackable2.Trackers<i> then
                return Player(i)
            endif
            set i = i - 1
        endloop
    else
        return TriggerTrackable2.ForPlayer
    endif
    return null
endfunction

function SetTrackable2Data takes Data whichTrackable, integer whatData returns nothing
    set whichTrackable.UserData = whatData
endfunction

function GetTrackable2Data takes Data whichTrackable returns integer
    return whichTrackable.UserData
endfunction

//! textmacro Trackable2_Macro takes NAME, TYPE
function GetTrackable2$NAME$ takes Data which returns $TYPE$
    return which.$NAME$
endfunction
//! endtextmacro

//! runtextmacro Trackable2_Macro (&quot;X&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Y&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Z&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Facing&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Model&quot;, &quot;string&quot;)
//! runtextmacro Trackable2_Macro (&quot;ForPlayer&quot;, &quot;player&quot;)

private function Init takes nothing returns nothing
    set table = HandleTable.create()
    set SetLastBool = Condition(function SetLast)
endfunction
endlibrary</i></i></i></i></i>


Besides, you never have to let the EGUIers know that Trackable2's are integers. It'sa secret.

EDIT: Could someone change the thread prefix to [System]? Doesn't seem to be a snippet.
 
Hmm. I believe I've finally "finished" implementing T2.

Anyone want to double check?

JASS:
library Trackable2 initializer Init requires Table

private keyword Data

globals
    private HandleTable table
    private Data array Trackables
    private trackable TriggerTrackable
    private boolexpr SetLastBool
    private Data TriggerTrackable2
    Data bj_lastCreatedTrackable2
endglobals

private function SetLast takes nothing returns boolean
    set TriggerTrackable = GetTriggeringTrackable()
    set TriggerTrackable2 = table[TriggerTrackable]
    //Make this return false if your trackable triggers are running on conditions only.
    return true
endfunction

private struct Data
    trackable array Trackers [12]
    real X
    real Y
    real Z
    real Facing
    location Loc
    string Model
    player ForPlayer = null
    integer UserData = 0
endstruct

function CreateTrackable2 takes string modelPath, real x, real y, real z, real facing returns Data
    local Data d = Data.create()
    local string s = &quot;&quot;
    local destructable platform = CreateDestructableZ(&#039;OTip&#039;,x,y,z,0.00,1,0)
    local integer i = 11
    loop
        exitwhen i &lt; 0
        if GetLocalPlayer() == Player(i) then
            set s = modelPath
        else
            set s = &quot;&quot;
        endif
        set d.Trackers<i> = CreateTrackable(s, x, y, facing)
        set table[d.Trackers<i>] = d
        set i = i - 1
    endloop
    set d.X = x
    set d.Y = y
    set d.Z = z
    set d.Loc = Location(x,y)
    set d.Facing = facing
    set d.Model = modelPath
    set bj_lastCreatedTrackable2 = d
    call RemoveDestructable(platform)
    set platform = null
    return d
endfunction

function CreateTrackableEGUI takes string modelPath, location loc, real facing returns Data
    return CreateTrackable2(modelPath, GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc), facing)
endfunction

function CreateTrackable2ForPlayer takes string modelPath, real x, real y, real z, real facing, player forPlayer returns Data
    local Data d = Data.create()
    local string s = modelPath
    local destructable platform = CreateDestructableZ(&#039;OTip&#039;,x,y,z,0.00,1,0)
    if GetLocalPlayer() != forPlayer then
        set s = &quot;&quot;
    endif
    set d.Trackers[1] = CreateTrackable(s, x, y, facing)
    set table[d.Trackers[1]] = d
    set d.ForPlayer = forPlayer
    set d.X = x
    set d.Y = y
    set d.Z = z
    set d.Loc = Location(x,y)
    set d.Facing = facing
    set d.Model = modelPath
    set bj_lastCreatedTrackable2 = d
    call RemoveDestructable(platform)
    set platform = null
    return d
endfunction

function TriggerRegisterTrackable2HitEvent takes trigger whichTrigger, Data d returns nothing
    local integer i
    if d.ForPlayer == null then
        set i = 11
        loop
            exitwhen i &lt; 0
            call TriggerRegisterTrackableHitEvent(whichTrigger, d.Trackers<i>)
            set i = i - 1
        endloop
    else
        call TriggerRegisterTrackableHitEvent(whichTrigger, d.Trackers[1])
    endif
    call TriggerAddCondition(whichTrigger, SetLastBool)
endfunction

function TriggerRegisterTrackable2TrackEvent takes trigger whichTrigger, Data d returns nothing
    local integer i
    if d.ForPlayer == null then
        set i = 11
        loop
            exitwhen i &lt; 0
            call TriggerRegisterTrackableTrackEvent(whichTrigger, d.Trackers<i>)
            set i = i - 1
        endloop
    else
        call TriggerRegisterTrackableTrackEvent(whichTrigger, d.Trackers[1])
    endif
    call TriggerAddCondition(whichTrigger, SetLastBool)
endfunction

function GetTriggeringTrackable2 takes nothing returns Data
    return TriggerTrackable2
endfunction

function IsTriggerTrackable takes Data d returns boolean
    return d == TriggerTrackable2
endfunction

function GetTrackedPlayer takes nothing returns player
    local integer i
    //So very sorry about this O(n) search. Trying to remedy this.
    if TriggerTrackable2.ForPlayer == null then
        set i = 11
        loop
            exitwhen i &lt; 0
            if TriggerTrackable == TriggerTrackable2.Trackers<i> then
                return Player(i)
            endif
            set i = i - 1
        endloop
    else
        return TriggerTrackable2.ForPlayer
    endif
    return null
endfunction

function GetLastCreatedTrackable2 takes nothing returns integer
    return bj_lastCreatedTrackable2
endfunction

function SetTrackable2Data takes Data whichTrackable, integer whatData returns nothing
    set whichTrackable.UserData = whatData
endfunction

function GetTrackable2Data takes Data whichTrackable returns integer
    return whichTrackable.UserData
endfunction

//! textmacro Trackable2_Macro takes NAME, TYPE
function GetTrackable2$NAME$ takes Data which returns $TYPE$
    return which.$NAME$
endfunction
//! endtextmacro

//! runtextmacro Trackable2_Macro (&quot;X&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Y&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Z&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Loc&quot;, &quot;location&quot;)
//! runtextmacro Trackable2_Macro (&quot;Facing&quot;, &quot;real&quot;)
//! runtextmacro Trackable2_Macro (&quot;Model&quot;, &quot;string&quot;)
//! runtextmacro Trackable2_Macro (&quot;ForPlayer&quot;, &quot;player&quot;)

private function Init takes nothing returns nothing
    set table = HandleTable.create()
    set SetLastBool = Condition(function SetLast)
endfunction
endlibrary
</i></i></i></i></i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/
  • The Helper The Helper:
    Happy Thursday!
  • Ghan Ghan:
    I'm not so sure, there's still a lot of Thursday left for it to become unhappy.
    +3
  • The Helper The Helper:
    still a few hours
  • The Helper The Helper:
    Its Friday!!!!
    +1
  • Ghan Ghan:
    Thursday 7/10 would Thursday again
    +3
  • The Helper The Helper:
    New forum coming soon going to be for my friend Saylor who is blind and he is doing motivational speaking and has an internet radio show and podcast. I am going to put a forum to promote him and other inspirational speaker stuff going to have some good stuff in it.

      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