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>
 
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.
 
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>
 
Actually, you can create texttags locally without desyncs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • 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 Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top