• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] GUI Custom Script

Status
Not open for further replies.
Level 13
Joined
Jul 16, 2012
Messages
679
Hello felas

This is my code that I written

  • Runner Spawn
    • Events
    • Conditions
    • Actions
      • -------- ------------------------------------------- --------
      • -------- Local Vars --------
      • Custom script: local unit RandomUnit
      • Custom script: local unittype Race
      • Custom script: local location Start
      • Custom script: local location End
      • -------- ------------------------------------------- --------
      • -------- Check Player Race --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Race of Player 1 (Red)) Equal to Human
        • Then - Actions
          • -------- Human Race --------
          • Custom script: set Race = udg_Human[ GetRandomInt( 1, udg_Human_Count)]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Race of Player 1 (Red)) Equal to Orc
            • Then - Actions
              • -------- Orc Race --------
              • Custom script: set Race = udg_Orc[ GetRandomInt( 1, udg_Orc_Count)]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Race of Player 1 (Red)) Equal to Undead
                • Then - Actions
                  • -------- Undead Race --------
                  • Custom script: set Race = udg_Undead[ GetRandomInt( 1, udg_Undead_Count)]
                • Else - Actions
                  • -------- Night Elf Race --------
                  • Custom script: set Race = udg_NightElf[ GetRandomInt( 1, udg_NightElf_Count)]
      • -------- ------------------------------------------- --------
      • -------- Spawn Random Unit in Random Point and move in Random Point --------
      • Custom script: set Start = GetRandomLocInRect( gg_rct_Region_003)
      • Custom script: set End = GetRandomLocInRect( gg_rct_Region_003_Copy)
      • Custom script: call CreateNUnitsAtLoc( 1, Race, Player( 11), Start, 270.00)
      • Custom script: set RandomUnit = GetLastCreatedUnit()
      • Custom script: call IssuePointOrderLocBJ( RandomUnit, "move", End)
      • Custom script: call UnitAddAbilityBJ( 'Aloc', udg_TempUnit )
      • -------- ------------------------------------------- --------
      • -------- Remove memory leaks --------
      • Custom script: call RemoveLocation( udg_TempPoint)
      • Custom script: call RemoveLocation( udg_TempPoint1)
      • -------- ------------------------------------------- --------
      • -------- Looping --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Game_SpawnSpeed Less than or equal to 0.00
        • Then - Actions
          • -------- Avoid 0 speed --------
          • Set Game_SpawnSpeed = 3.00
          • Wait Game_SpawnSpeed seconds
        • Else - Actions
          • Wait Game_SpawnSpeed seconds
      • Trigger - Run (This trigger) (ignoring conditions)
The main problem here are these guys
  • Custom script: set Race = udg_Human[GetRandomInt(1, udg_Human_Count)]
  • Custom script: set Race = udg_Orc[ GetRandomInt( 1, udg_Orc_Count)]
  • Custom script: set Race = udg_Undead[ GetRandomInt( 1, udg_Undead_Count)]
  • Custom script: set Race = udg_NightElf[ GetRandomInt( 1, udg_NightElf_Count)]
The error said Cannot convert integer to unittype

btw, udg_Human, udg_Orc, udg_Undead, udg_NightElf are unittype


How to solve this problem?
 
Last edited:

Deleted member 219079

D

Deleted member 219079

Maybe GUI unit types are integers, referring to raw id's.
 
Level 13
Joined
Jul 16, 2012
Messages
679
Are you certain udg_Human, udg_Orc, udg_Undead, and udg_NightElf are unittypes? I just did this and got no errors:

JASS:
function SomeFunction takes nothing returns nothing
    local unittype Race
    local unittype array Human
 
    set Race = Human[1]
endfunction

Human is not a local variable, try to use global instead. :)
I want the Race get a random unittype in Human. For example:
Human[0] = Footman
Human[1] = Rifleman
Human[2] = Paladin

  • set Race = udg_Human[ GetRandomInt( 1, udg_NightElf_Count)]
Result:
Race = Rifleman
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
The issue is definitely what jondrea mentioned. Unittype in JASS is different from unittype in GUI.

  • Custom script: local unittype Race = udg_Human[GetRandomInt(1,10)]
  • -------- --------
  • Custom script: set udg_Race = udg_Human[GetRandomInt(1,10)]
  • Set Race = Human[(Random integer number between 1 and 10)]
I only get an error for the first line. You will need to use a global variable for Race instead of a local.
 
Status
Not open for further replies.
Top