A Learning Struct

TheOverWhelm

Member
Reaction score
16
So I've been learning structs, getting them to work, just messing with them!
Made one for heroes and I'm guessing it's highly inefficient (I'm guessing)
It basically does everything a normal hero is, the per level, the st@ stats (health, mana, agi, str, int, not one for damage or armor yet)
However, I wanted to make it so a player can choose the model of the unit (sticking with Paladins for now!) and so I made a trigger that allows players to do that from a list I've created
But an issue occurs when I want to change the unit, it requires the player to edit an attribute of the hero and THEN to change the model. A player can go straight for changing the model and it says it'll work, but it wont. This shouldn't be happening. I half-think it's something about the Struct but I dunno what, I've tried stuff and it not be working!
Here are the related things. Tell me if you want me to past the entire Struct (has some useless stuff in it!)
And I know.. I'm mixing GUI and JASS :nuts:

This JASS one changes the -C values within the struct. The GUI after this one calls this.
JASS:
   method PlayerModifyStuff takes unit n, string s returns nothing.
    local player p = GetOwningPlayer(this.u)
    local string input = SubString(s,6-1,StringLength(s)) //Inputted Value
    local string modding = SubString(s,4-1,4)
    local real realinput = S2R(input)
    local real array r
    call PingMinimap(GetUnitX(this.u),GetUnitY(this.u),2)
    if realinput < 0 then
        return
    endif
    if this.CanModifyHero == false then
        call DisplayTextToPlayer(p,0,0,"You can't modify your hero at this time.")
        return
    endif
    set r[0]=this.healthInit+this.manaInit+this.speedInit //1 and 2
    set r[1]=150+150+350
    set r[2]=r[1]-r[0]
    set r[4]= this.strength+this.agility+this.intelligence
    set r[5]= 40
    set r[6]= r[5]-r[4]
    set r[7]= this.strengthLvl+this.agilityLvl+this.intelligenceLvl
    set r[8]= 6
    set r[9]=r[8]-r[7]
    if modding=="1" and r[0]-this.healthInit+realinput<=r[1] and realinput>= 1 then
        set this.healthInit = realinput
    endif
    if modding=="2" and r[0]-this.manaInit+realinput<=r[1] then
        set this.manaInit = realinput
    endif
    if modding=="3" and r[0]-this.speedInit+realinput<=r[1] then
        set this.speedInit = realinput
    endif
    if modding=="4" and r[4]-this.strength+realinput<=r[5] then
        set this.strength = realinput
    endif
    if modding=="5" and r[4]-this.agility+realinput<=r[5] then
        set this.agility = realinput
    endif
    if modding=="6" and r[4]-this.intelligence+realinput<=r[5] then
        set this.intelligence=realinput
    endif
    if modding=="7" and r[7]-this.strengthLvl+realinput <= r[8] then
        set this.strengthLvl = realinput
    endif
    if modding=="8" and r[7]-this.agilityLvl+realinput <= r[8] then
        set this.agilityLvl = realinput
    endif
    if modding=="9" and r[7]-this.intelligenceLvl+realinput <= r[8] then
        set this.intelligenceLvl = realinput
    endif
    call ClearTextMessages()
    
    set r[0]=this.healthInit+this.manaInit+this.speedInit //1 and 2
    set r[1]=150+150+350
    set r[2]=r[1]-r[0]
    set r[4]= this.strength+this.agility+this.intelligence
    set r[5]= 40
    set r[6]= r[5]-r[4]
    set r[7]= this.strengthLvl+this.agilityLvl+this.intelligenceLvl
    set r[8]= 6
    set r[9]=r[8]-r[7]
    
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 1 "+R2S(this.healthInit)+" - Default HP")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 2 "+R2S(this.manaInit)+" - Default MP")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 3 "+R2S(this.speedInit)+" - Default Speed")
    call DisplayTimedTextToPlayer(p,0,0,170,"You have "+I2S(R2I(r[2]))+" points left in this category.")
    call DisplayTimedTextToPlayer(p,0,0,170," ")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 4 "+R2S(this.strength)+ " strength.")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 5 "+R2S(this.agility)+ " agility.")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 6 "+R2S(this.intelligence)+ " intelligence.")
    call DisplayTimedTextToPlayer(p,0,0,170,"You have "+I2S(R2I(r[6]))+ " points left in this category.")
    call DisplayTimedTextToPlayer(p,0,0,170," ")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 7 "+R2S(this.strengthLvl)+" strength per level.")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 8 "+R2S(this.agilityLvl)+" agility per level.")
    call DisplayTimedTextToPlayer(p,0,0,170,"-C 9 "+R2S(this.intelligenceLvl)+" intelligence per level.")
    call DisplayTimedTextToPlayer(p,0,0,170,"You have "+I2S(R2I(r[9]))+" points left in this category.")
    call DisplayTimedTextToPlayer(p,0,0,170," ")
    call DisplayTimedTextToPlayer(p,0,0,170,"When done type 'Go!'")
    call this.FixHero() //Sets the attributes, etc
    if s == "Go!" then
        set this.CanModifyHero = false
        call ClearTextMessages()
    endif
    endmethod


This next one has Events, it's done at Map Init [See right below]
Trigger - Add to C Stuff <gen> the event (Player - (Picked player) types a chat message containing Go! as An exact match)
Trigger - Add to C Stuff <gen> the event (Player - (Picked player) types a chat message containing -c as A substring)

As for the trigger itself, another system detects the SelectedUnits and keeps it updated (works like a charm)
Heroes that are being modified are paused at Init and added to the Struct and a unitgroup called ModifyingGroup.
The objective of this trigger is to find how many selected units are heroes.
Trigger:
  • C Stuff
    • Events
    • Conditions
      • Multiple ConditionsOr - Any (Conditions) are true
        • Conditions
          • (Substring((Entered chat string), 1, 3)) Equal to (==) -c
          • (Substring((Entered chat string), 1, 3)) Equal to (==) -C
          • (Entered chat string) Equal to (==) Go!
    • Actions
      • Set TempInteger = 0
      • Set TempUnit = No unit
      • Unit Group - Pick every unit in SelectedUnits[(Player number of (Triggering player))] and do (Actions)
        • Loop - Actions
          • Custom script: call BJDebugMsg(I2S(GetUnitUserData(GetEnumUnit())))
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Custom value of (Picked unit)) Greater than (&gt;) 0
              • Then - Actions
                • Set TempInteger = (TempInteger + 1)
                • Set TempUnit = (Picked unit)
              • Else - Actions
          • Custom script: call BJDebugMsg(&quot;PickingUnits&quot;)
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TempInteger Equal to (==) 0
          • Then - Actions
            • Game - Display to (All players) for 10.00 seconds the text: No hero selected.
          • Else - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • TempInteger Equal to (==) 1
              • Then - Actions
                • Set TempString = (Entered chat string)
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (TempUnit is paused) Equal to (==) True
                      • (TempUnit is in ModifyingGroup) Equal to (==) True
                      • (Entered chat string) Equal to (==) Go!
                    • Then - Actions
                      • Unit - Unpause TempUnit
                      • Unit Group - Remove TempUnit from ModifyingGroup
                    • Else - Actions
                • Custom script: call PassC(udg_TempUnit,udg_TempString)
                • Custom script: call BJDebugMsg(&quot;TalkingToSystem&quot;)
              • Else - Actions
                • Game - Display to (All players) for 10.00 seconds the text: Multiple heroes det...
      • Custom script: call BJDebugMsg(&quot;You typed something!&quot;)


The above ones work all dandy.

This next trigger is to simply set the names and the unittypes.

Trigger:
  • AvailableHeroList
    • Events
      • Time - Elapsed game time is 0.50 seconds
    • Conditions
    • Actions
      • Set TempInteger = 1
      • Set sysChoosableHeroes[TempInteger] = Uther
      • Set sysRecognizedName[TempInteger] = Uther
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Admiral Proudmoore
      • Set sysRecognizedName[TempInteger] = Admiral Proudmoore
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Arthas
      • Set sysRecognizedName[TempInteger] = Arthas
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Dagren the Orcslayer
      • Set sysRecognizedName[TempInteger] = Dagren
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Halahk the Lifebringer
      • Set sysRecognizedName[TempInteger] = Halahk
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Lord Nicholas Buzan
      • Set sysRecognizedName[TempInteger] = Buzan
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Magroth the Defender
      • Set sysRecognizedName[TempInteger] = Magroth
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Sir Gregory Edmunson
      • Set sysRecognizedName[TempInteger] = Gregory
      • -------- --------
      • Set TempInteger = (TempInteger + 1)
      • Set sysChoosableHeroes[TempInteger] = Paladin
      • Set sysRecognizedName[TempInteger] = Paladin



The issue is beyond this.
Trigger:
  • ChangeHero
    • Events
      • Player - Player 1 (Red) types a chat message containing -change as A substring
      • Player - Player 2 (Blue) types a chat message containing -change as A substring
      • Player - Player 3 (Teal) types a chat message containing -change as A substring
      • Player - Player 4 (Purple) types a chat message containing -change as A substring
      • Player - Player 5 (Yellow) types a chat message containing -change as A substring
      • Player - Player 6 (Orange) types a chat message containing -change as A substring
      • Player - Player 7 (Green) types a chat message containing -change as A substring
      • Player - Player 8 (Pink) types a chat message containing -change as A substring
      • Player - Player 9 (Gray) types a chat message containing -change as A substring
      • Player - Player 10 (Light Blue) types a chat message containing -change as A substring
      • Player - Player 11 (Dark Green) types a chat message containing -change as A substring
      • Player - Player 12 (Brown) types a chat message containing -change as A substring
    • Conditions
      • Multiple ConditionsOr - Any (Conditions) are true
        • Conditions
          • (Entered chat string) Equal to (==) -change list
          • (Substring((Entered chat string), 1, 8)) Equal to (==) -change
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to (==) -change list
        • Then - Actions
          • Set TempString = Currently Available Heroes:
            • Do Multiple ActionsFor each (Integer A) from 1 to 20, do (Actions)
              • Loop - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • sysRecognizedName[(Integer A)] Not equal to (!=) Empty String
                  • Then - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • sysIsHeroUsed[(Integer A)] Equal to (==) True
                      • Then - Actions
                        • Set TempString = (TempString + (|c00FF0000, + (sysRecognizedName[(Integer A)] + |r)))
                      • Else - Actions
                        • Set TempString = (TempString + (|c00FF0000,|r|c0000FF00 + (sysRecognizedName[(Integer A)] + |r)))
                  • Else - Actions
          • Game - Display to (All players) for 60.00 seconds the text: TempString
          • Skip remaining actions
        • Else - Actions
      • Set TempString = (Substring((Entered chat string), 9, (Length of (Entered chat string))))
      • Cinematic - Clear the screen of text messages for (All players)
        • Do Multiple ActionsFor each (Integer A) from 1 to 20, do (Actions)
          • Loop - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • TempString Equal to (==) sysRecognizedName[(Integer A)]
              • Then - Actions
                • Set sysIsHeroUsed[(Integer A)] = True
                • Unit Group - Pick every unit in ModifyingGroup and do (Actions)
                  • Loop - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Owner of (Picked unit)) Equal to (==) (Triggering player)
                      • Then - Actions
                        • Set TempUnit = (Picked unit)
                      • Else - Actions
                  • Do Multiple ActionsFor each (Integer B) from 1 to 20, do (Actions)
                    • Loop - Actions
                      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • sysChoosableHeroes[(Integer B)] Equal to (==) (Unit-type of TempUnit)
                        • Then - Actions
                          • Set sysIsHeroUsed[(Integer B)] = False
                        • Else - Actions
                • Set TempPoint = (Center of (Playable map area))
                • Unit - Create 1 sysChoosableHeroes[(Integer A)] for Neutral Hostile at TempPoint facing TempPoint
                • Custom script: call ReplaceUnitHeroData(udg_TempUnit,bj_lastCreatedUnit)
                • Custom script: call RemoveLocation(udg_TempPoint)
                • Game - Display to (All players) for 35.00 seconds the text: You have changed yo...
              • Else - Actions



This function is here because I couldn't figure out how to do the local heroData part without having it be a local. -Shrug-
JASS:
function ReplaceUnitHeroData takes unit u, unit r returns unit
local heroData data = GetUnitUserData(u)
//call data.RefreshSystemOdd() - Vain attempts to prevent this bug
return data.ReplaceUnit(u,r)
endfunction



JASS:
    //method RefreshSystemOdd takes nothing returns nothing
    //call this.PlayerModifyStuff(this.u,&quot;-c 1 0&quot;)
    //call this.FixHero()
    //endmethod
    
    //First unit is the one that&#039;s being changed, second one will new+be cleaned up within
    method ReplaceUnit takes unit u, unit r returns unit
    local location Loc = GetUnitLoc(u)
    local player p = GetOwningPlayer(u)
    local integer i = GetUnitUserData(u)
    local integer z=GetUnitTypeId(r)
    call RemoveUnit(u)
    set this.u = CreateUnit(p,z,GetLocationX(Loc),GetLocationY(Loc),270)
    call SetUnitUserData(this.u,i)
    call RemoveUnit(r)
    call PauseUnit(this.u,true)
    call this.FixHero()
    //call this.PlayerModifyStuff(this.u,&quot;-c 1 0&quot;)
    return this.u
    endmethod


I'll understand if no one responds. It's big, can be done better, and sloppy in spots.
Thanks to anyone who helps.

Also, attaching map xD
This has been bugging me for hours.

Edit: Figured it out. Some pointers for the future would be nice though!
 

Attachments

  • StructPractice.w3x
    40.2 KB · Views: 192
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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