GetLocalPlayer() used correctly?

wellwish3r

wishes wells.
Reaction score
52
Since i don't really have a way to test it:

Did i use GetLocalPlayer() correctly here (no desyncs and not displayed to other people). From single player testing i know that it is displayed to me.

JASS:
if D<i>.owner == GetLocalPlayer() then
                set D<i>.txt = CreateTextTag()
            endif
            call SetTextTagText(D<i>.txt,s,TextTagSize2Height(8.00))
            call SetTextTagPos(D<i>.txt,GetLocationX(D<i>.txtloc),GetLocationY(D<i>.txtloc),150)
            call SetTextTagColor(D<i>.txt,255,255,255,255)
            call SetTextTagPermanent(D<i>.txt,false)
            call SetTextTagLifespan(D<i>.txt, 0.06)
            call SetTextTagFadepoint(D<i>.txt, 0.05)
            call RemoveLocation(D<i>.txtloc)</i></i></i></i></i></i></i></i></i></i></i>


And if necessary here is the whole thing:

JASS:
scope MeleeCS initializer Init

    struct MeleeFighter //The struct, dont alter this
        unit attacker
        boolean attk
        real stamina
        real damage
        integer agi
        integer str
        integer int
        location uloc
        location oloc
        real facing
        boolean end
        texttag txt
        location txtloc
        player owner
    endstruct
        
    globals //Globals, don&#039;t touch these
        private integer Total = 0
        private MeleeFighter array D
        private timer T = CreateTimer()
        private integer index
        private integer aindex
    endglobals
        
    private function GetDamage takes integer j returns real // Here Is the function that gives you the dmg
        local real dmg
        local integer i = j
        set D<i>.agi = GetHeroAgi(D<i>.attacker,true)
        set D<i>.str = GetHeroStr(D<i>.attacker,true)
        set D<i>.int = GetHeroInt(D<i>.attacker,true)
        set dmg = (D<i>.agi + D<i>.str + D<i>.int)*(D<i>.stamina)
        return dmg
    endfunction
        
    private function GetStamTick takes nothing returns real //determines the amount of stamina regenerated every 0.025 seconds (40 times per second)
        return 100.00/120.00                                //currently simply set to an amount that results in a 3 second cooldown
    endfunction
        
    private function IsHero takes nothing returns boolean //Is just temporary, as it picks all Heroes on the map, and adds gives them a slot in the struct array
        local unit u = GetFilterUnit()
        if IsUnitType(u,UNIT_TYPE_HERO) then
            set u = null
            return true
        endif
        set u = null
        return false
    endfunction
        
    private function MatchUnits takes nothing returns boolean //Picks the Units for the Unitgroup that is damaged
        local unit u = GetFilterUnit()
        if IsPlayerEnemy(GetOwningPlayer(D[aindex].attacker),GetOwningPlayer(u)) then
            if IsUnitType(u,UNIT_TYPE_FLYING) == false then
                if GetUnitAbilityLevel(u,&#039;Aloc&#039;) &lt; 1 then
                    set u = null
                    return true
                endif
            endif
        endif
        set u = null
        return false
    endfunction
        
    private function DamageGroup takes nothing returns nothing //Damages the picked units
        local unit u = GetEnumUnit()
        local real dmg = GetDamage(aindex)
        call UnitDamageTarget(D[aindex].attacker,u,dmg,true,false,ATTACK_TYPE_HERO,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
        set u = null
    endfunction
        
    private function AddToStruct takes nothing returns nothing //Adds a new Unit to the struct array
        local MeleeFighter LF = MeleeFighter.create()
        local unit u = GetEnumUnit()
        set LF.attacker = u
        set LF.stamina = 100
        set LF.attk = false
        set LF.end = false
        set LF.owner = GetOwningPlayer(u)
        set D[Total] = LF
        set Total = Total + 1
    endfunction
        
    private function TimerLoop takes nothing returns nothing //This creates the floating text and regenerates the stamina
        local integer i = 0
        local integer j = 1
        local string s = &quot;&quot;
        local integer cstam = 0
        loop
            exitwhen i&gt;=Total
            set index = i
            if D<i>.stamina &gt;= 100 then
                set D<i>.stamina = 100
            else
                set D<i>.stamina = D<i>.stamina + GetStamTick()
            endif
            set cstam = R2I(D<i>.stamina)
            loop
                exitwhen j &gt; 50
                if (cstam/2) &gt;= j then
                    set s = s + &quot;|cff660066&#039;|r&quot;
                else
                    set s = s + &quot;&#039;&quot;
                endif
                set j = j+1
            endloop
            //call BJDebugMsg(R2S(D<i>.stamina)+&quot;   &quot;+s)
            set D<i>.uloc = GetUnitLoc(D<i>.attacker)
            set D<i>.txtloc = Location(GetLocationX(D<i>.uloc) - 65.00,GetLocationY(D<i>.uloc))
            call RemoveLocation(D<i>.uloc)
            set D<i>.uloc = null
            if D<i>.owner == GetLocalPlayer() then
                set D<i>.txt = CreateTextTag()
            endif
            call SetTextTagText(D<i>.txt,s,TextTagSize2Height(8.00))
            call SetTextTagPos(D<i>.txt,GetLocationX(D<i>.txtloc),GetLocationY(D<i>.txtloc),150)
            call SetTextTagColor(D<i>.txt,255,255,255,255)
            call SetTextTagPermanent(D<i>.txt,false)
            call SetTextTagLifespan(D<i>.txt, 0.06)
            call SetTextTagFadepoint(D<i>.txt, 0.05)
            call RemoveLocation(D<i>.txtloc)
            set D<i>.txtloc = null
            set i = i+1
        endloop
    endfunction
        
    private function Init takes nothing returns nothing //Initializer function Starts timer etc
        local group grp = CreateGroup()
        call GroupEnumUnitsInRect(grp,GetPlayableMapRect(),Condition(function IsHero))
        call ForGroup(grp,function AddToStruct)
        call TimerStart(T,0.025,true,function TimerLoop)
        call DestroyGroup(grp)
        set grp = null
    endfunction
    
    function AddUnit takes unit u returns nothing //you can call this function to add HEROES (!) to the system, for example after a player loads one, or obtains one from a tavern
        local MeleeFighter LF = MeleeFighter.create()
        set LF.attacker = u
        set LF.stamina = 100
        set LF.attk = false
        set LF.end = false
        set LF.owner = GetOwningPlayer(u)
        set D[Total] = LF
        set Total = Total + 1
    endfunction
    
    function MeleeAttack takes unit u returns nothing // This function is the one that does the damage stuff. Call it via custom script to initialize the attack
        local integer i = 0
        local integer ai
        local boolean found = false
        local group grp = CreateGroup()
        local real facing
        loop
            exitwhen found == true
            if D<i>.attacker == u then
                set found = true
                set ai = i
            endif
            set i = i+1
        endloop
        set aindex = ai
        set D[ai].uloc = GetUnitLoc(D[ai].attacker)
        set facing  = GetUnitFacing(D[ai].attacker)
        set D[ai].oloc = PolarProjectionBJ(D[ai].uloc,100.00,facing)
        call RemoveLocation(D[ai].uloc)
        set D[ai].uloc = null
        call GroupEnumUnitsInRangeOfLoc(grp,D[ai].oloc,125,Condition(function MatchUnits))
        call ForGroup(grp,function DamageGroup)
        if CountUnitsInGroup(grp) &gt; 0 then
            set D[aindex].stamina = 0
        endif
        call DestroyGroup(grp)
        set grp = null
    endfunction
endscope</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Tom Jones

N/A
Reaction score
437
When you create a handle for the local player/client only, it'll cause desyncs. However I'm not certain that texttags will cause desyncs, as they are a special handle type. Most likely they will.

You should only display/hide things for the local player/client. Texttags has a function that will display or hide them, put that function inside an if statement that compares some player to the local player/client.
 

wellwish3r

wishes wells.
Reaction score
52
When you create a handle for the local player/client only, it'll cause desyncs. However I'm not certain that texttags will cause desyncs, as they are a special handle type. Most likely they will.

You should only display/hide things for the local player/client. Texttags has a function that will display or hide them, put that function inside an if statement that compares some player to the local player/client.

Okay, so you mean like this:

JASS:
            if D<i>.owner == GetLocalPlayer() then
                call SetTextTagVisibility(D<i>.txt,true)
            else
                call SetTextTagVisibility(D<i>.txt,false)
            endif</i></i></i>
 

Viikuna

No Marlo no game.
Reaction score
265
Actually, you can create texttags locally without desyncs.
 
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