• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] GetLocalPlayer() & Texttags

Status
Not open for further replies.
Level 11
Joined
Sep 30, 2009
Messages
698
Because I haven't found any vJass Texttag libraries and I wanted to create one.

I think I heard somewhere that texttags could be created for a single player only without desyncs but I can't test it right now so I am asking here.

Also I am wondering if this line would work, or if I need 2 ifs there:

if GetLocalPlayer() == .owner or .owner == null then

(if you create a texttag for a null player it should be created for all instead)


JASS:
library Texttag

struct Texttag
    private     texttag    tag
    private     real       Size
    private     real       X
    private     real       Y
    private     real       Height
    private     boolean    Visible
    readonly    player     owner
    readonly    real       xvel
    readonly    real       yvel
    
    method operator size takes nothing returns real
        return .Size
    endmethod
    
    method operator size= takes real size returns nothing
        set .Size = size * 0.023 / 10
        set .text = .Text
    endmethod
    
    method operator x takes nothing returns real
        return .X
    endmethod
    
    method operator x= takes real x returns nothing
        call .setPosition(x, .y)
    endmethod
    
    method operator y takes nothing returns real
        return .Y
    endmethod
    
    method operator y= takes real y returns nothing
        call .setPosition(.x, y)
    endmethod
    
    method operator height takes nothing returns real
        return .Height
    endmethod
    
    method operator height= takes real h returns nothing
        set .Height = h
        call .setPosition(.x, y)
    endmethod
    
    method operator visible takes nothing returns boolean
        return .Visible 
    endmethod
    
    method operator visible= takes boolean visible returns nothing
        set .Visible = visible
        if GetLocalPlayer() == .owner or .owner == null then
            call SetTextTagVisibility(.tag, .Visible)
        endif
    endmethod
    
    method setPosition takes real x, real y returns nothing
        set .x = x
        set .y = y
        if GetLocalPlayer() == .owner or .owner == null then
            call SetTextTagPos(.tag, .x, .y, .Height)
        endif
    endmethod
    
    method setVelocity takes real speed, real angle returns nothing
        set .xvel = speed * 0.071 / 128 * Cos(angle * bj_DEGTORAD)
        set .yvel = speed * 0.071 / 128 * Sin(angle * bj_DEGTORAD)
        if GetLocalPlayer() == .owner or .owner == null then
            call SetTextTagVelocity(.tag, .xvel, .yvel)
        endif
    endmethod
    
    //! runtextmacro TEXTTAG_OPERATER("age", "Age", "real", "")
    //! runtextmacro TEXTTAG_OPERATER("lifespan", "Lifespan", "real", "")
    //! runtextmacro TEXTTAG_OPERATER("permanent", "Permanent", "boolean", "")
    //! runtextmacro TEXTTAG_OPERATER("suspended", "Suspended", "boolean", "")
    //! runtextmacro TEXTTAG_OPERATER("text", "Text", "string", ", .Size")
    
    method destroy takes nothing returns nothing
        call DestroyTextTag(.tag)
        call .deallocate()
    endmethod
    
    static method create takes player p returns thistype
        local thistype this = thistype.allocate() 
        set .owner = p
        if GetLocalPlayer() == .owner or .owner == null then
            set .tag = CreateTextTag()
        endif
        return this
    endmethod
    
endstruct

//! textmacro TEXTTAG_OPERATER takes name, Func, type, special
    private $type$ $Func$
    
    method operator $name$ takes nothing returns $type$
        return $Func$
    endmethod
    
    method operator $name$= takes $type$ var returns nothing
        set .$Func$ = var
        if GetLocalPlayer() == .owner or .owner == null then
            call SetTextTag$Func$(.tag, var $special$)
        endif
    endmethod
//! endtextmacro

endlibrary
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
There's no need to sync texttag data as they are only for graphical purposes, they also have their own id stack from 99 to 0. So yes, they can be created for individual players but you should then pay attention that you put a local block everywhere as the code is normally executed for all players, else you would affect the false texttags on other clients.

The if also works, why not?

I do not really know yet, why you need to store the owner as you do not use anything yet that needs to be synced. Then you could as well have the struct desynced.
 
Level 11
Joined
Sep 30, 2009
Messages
698
There's no need to sync texttag data as they are only for graphical purposes, they also have their own id stack from 99 to 0. So yes, they can be created for individual players but you should then pay attention that you put a local block everywhere as the code is normally executed for all players, else you would affect the false texttags on other clients.

The if also works, why not?

I do not really know yet, why you need to store the owner as you do not use anything yet that needs to be synced. Then you could as well have the struct desynced.

Hmm do you mean I should put the

if GetLocalPlayer() == .owner or .owner == null then

before all texttag actions then or did you mean something else?

EDIT: Updated vJass code with the changes I made
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Hmm do you mean I should put the

if GetLocalPlayer() == .owner or .owner == null then

before all texttag actions then or did you mean something else?

Either you know in the special case if the local player uses the specified texttag and can put an own condition/need none or you pass the player to your functions or you make the struct synchronous as you have at the moment.
 
Status
Not open for further replies.
Top