Help: Trackables

jnZ

I
Reaction score
64
no it works fine. i think ill keep it like that. but anyway how to make it "mpi" now because the tutorial says:

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.

this is the "mpi" code mentioned in the turtorial:

JASS:
    // 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...


JASS:
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


so are you still able to do it? :D

EDIT: i need it for up to 5 players, so best would be running a playing players detection at start and only create as much trackables as needed
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
JASS:
function private__Trackable_Cache takes nothing returns gamecache
    return InitGameCache("trackablizer.gc")
endfunction
function private__Trackable_H2I takes handle h returns integer
    return h
    return 0
endfunction

function NewTrackable takes string path, real x, real y, real f returns nothing
    local integer i=0
    local trackable t
    local string s
    loop
        exitwhen i>11
        set s=""
        if(GetLocalPlayer()==Player(i))then
            set s=path
        endif
        set t=CreateTrackable(s,x,y,f)
        
        call StoreString(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"path",path)
        call StoreInteger(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"owner",i)
        call StoreReal(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"x",x)
        call StoreReal(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"y",y)
        call StoreReal(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"f",f)
        set i=i+1
    endloop
    set t=null
endfunction

function GetTrackingPlayer takes nothing returns player
    return Player(GetStoredInteger(private__Trackable_Cache(),I2S(private__Trackable_H2I(GetTriggeringTrackable())),"owner"))
endfunction

function GetTrackablePath takes trackable t returns string
    return GetStoredString(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"path")
endfunction
function GetTrackableX takes trackable t returns real
    return GetStoredReal(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"x")
endfunction
function GetTrackableY takes trackable t returns real
    return GetStoredReal(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"y")
endfunction
function GetTrackableFacing takes trackable t returns real
    return GetStoredReal(private__Trackable_Cache(),I2S(private__Trackable_H2I(t)),"f")
endfunction


Should work even on a mac.

EDIT: Forgot to explain. Just replace 'CreateTrackable()' with 'NewTrackable()', and then you can use all the functions.

Code:
GetTrackingPlayer(nothing) - returns the player that activated the trackable.
GetTrackablePath(trackable) - returns the file path of the trackable
GetTrackableX(trackable) - returns the x of the trackable
GetTrackableY(trackable) - returns the y of the trackable
GetTrackableFacing(trackable) - returns the facing angle of the trackable
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Oh. Here I thought you wanted help with an easy way to use trackables. In fact, you are coming to the Jass Help forum asking for someone to do your Jass for you. BTW: when Vex finishes wrappers, trackables are totally going to pwn and be valid again.
 

jnZ

I
Reaction score
64
jup i ask ppl to do jass editing for me giving them some pieces to put togeter. where is the problem about that? wrappers :confused: -.-
 
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