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.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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