Snippet Trackable2

wraithseeker

Tired.
Reaction score
122
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.
 

Azlier

Old World Ghost
Reaction score
461
While Jesus works, I announce that the Table version is up. Safer, but slower.
 

Azlier

Old World Ghost
Reaction score
461
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.
 

Sim

Forum Administrator
Staff member
Reaction score
534
Nice Table X Jesus, but please guys discuss the trackables system in this thread, thanks. :)
 

Azlier

Old World Ghost
Reaction score
461
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).
 

Jesus4Lyf

Good Idea™
Reaction score
397
>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?
 

Azlier

Old World Ghost
Reaction score
461
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.
 

Azlier

Old World Ghost
Reaction score
461
Bump, and documented the functions (I knew I forgot something!)
 

Azlier

Old World Ghost
Reaction score
461
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.
 

Sevion

The DIY Ninja
Reaction score
413
Oh, sure. When I'm in the process of making changes for EGUI with the "new" versions, you update it again... -_-'
 

Azlier

Old World Ghost
Reaction score
461
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.
 

Sevion

The DIY Ninja
Reaction score
413
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.
 

Azlier

Old World Ghost
Reaction score
461
Why would you want to use raw trackables over the structs themselves? Those functions I have essentially are EGUI wrappers.
 

Sevion

The DIY Ninja
Reaction score
413
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.
 

Azlier

Old World Ghost
Reaction score
461
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.
 

Sevion

The DIY Ninja
Reaction score
413
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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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