• 🏆 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!

[General] How do you detect player selected races?

Status
Not open for further replies.
Level 13
Joined
Oct 12, 2016
Messages
769
I actually have 2 problems, but this one is the most important.

Problem 1:
Is there a way in triggers or custom scripting to detect which race a player selected on the game menu?
I have 5 races in my map, and want to assign starting units based on the race selected.
This includes when someone selects "random."

Problem 2:
I want to put a special effect into this custom script here:

  • call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_CreepPoint[ii]),GetLocationY(udg_CreepPoint[ii]),270),ii)
So that when the called unit "respawns,"
it plays the "Abilities\Spells\Human\Heal\HealTarget.mdl" special effect at that location.

Does anyone know what to put in there?
 
Level 11
Joined
Jun 2, 2004
Messages
849
1:
Yes, with the Race condition. It's right below Player Slot Status and right above Real condition in the GUI dropdown menu.
You can't know when they selected Random though; the game only supports 4 races. Any workaround for 5+ races will probably have the player selecting the race in-game rather than in the game room.

2:
Special Effect - Create Special Effect on Unit (or on Point). Last Created Unit (or position of it) should work fine.
The GUI actions are alphabetized and it's under S.


Any reason you're using the GUI custom script feature if you're just using things exposed to the GUI? If you really hate dropdown menus and recursive dialog menus you can go fully into the JASS editor by converting a trigger to custom script (Edit -> Convert to Custom Text). The GUI custom script is mostly for using code not represented with the GUI interface, and just makes things harder if you're coding fully in JASS with it.
EDIT: Wait, I saw those local variables (i, ii). Okie-dokie.



This might be a bit beyond your current level (or maybe not and you already know this, in which case ignore) but someone else is going to mention it if I don't: Any time you use a point (like a location of a unit), the map will leak memory unless you explicitly destroy that point. I don't remember if the CreateUnit native does, but any method to create a special effect will certainly leak. I suggest creating a Point variable in the trigger editor (name it TempPoint or something), whenever you create a point you set it to that variable, and use "call RemoveLocation(udg_TempPoint)" when you're done with it.
 
Last edited:
Level 13
Joined
Oct 12, 2016
Messages
769
Yes, I know all about making a "TempPoint" then removing it using the custom script: "call RemoveLocation(udg_TempPoint)".
I also know about the same for special effects.
EDIT:
The custom script's function is to respawn a specific indexed unit at a specific location when it dies.
The thing I need is a custom script to make the special effect at the location where the unit respawns.
Or, a custom script to set "TempPoint" the the local variable co-ordinates. I don't know much of anything in JASS, and prefer using GUI. So, I just don't know a lot of custom script functions, or where I can reference them.


As for the random variable not registering, that is a shame. Is there any other way to detect someone picking random?
 
Last edited:
After i read you thread i checked the common.j. And Lucky i found something than can be used to check if a player selects random.
Code:
native IsPlayerRacePrefSet    takes player whichPlayer, racepreference pref returns boolean
In GuI usage: Is Player Random?
  • set udg_Player = Player 1 (Red)
  • Custom script: set udg_Boolean = IsPlayerRacePrefSet(udg_Player, RACE_PREF_RANDOM)

A Long Trigger showing which Race Player 1 picked:
  • Unbezeichneter Auslöser 001
    • Ereignisse
      • Map initialization
    • Bedingungen
    • Aktionen
      • Set Player = Spieler 1 (Rot)
      • Custom script: set udg_Boolean = IsPlayerRacePrefSet(udg_Player, RACE_PREF_RANDOM)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditios
          • Boolean Gleich True
        • Then - Actions
          • Spiel - Display to (All players) the text: Random
        • Else - Actions
      • Custom script: set udg_Boolean = IsPlayerRacePrefSet(udg_Player, RACE_PREF_HUMAN)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditios
          • Boolean Gleich True
        • Then - Actions
          • Spiel - Display to (All players) the text: Human
        • Else - Actions
      • Custom script: set udg_Boolean = IsPlayerRacePrefSet(udg_Player, RACE_PREF_ORC)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditios
          • Boolean Gleich True
        • Then - Actions
          • Spiel - Display to (All players) the text: Orc
        • Else - Actions
      • Custom script: set udg_Boolean = IsPlayerRacePrefSet(udg_Player, RACE_PREF_NIGHTELF)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditios
          • Boolean Gleich True
        • Then - Actions
          • Spiel - Display to (All players) the text: NIGHTELF
        • Else - Actions
      • Custom script: set udg_Boolean = IsPlayerRacePrefSet(udg_Player, RACE_PREF_UNDEAD )
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditios
          • Boolean Gleich True
        • Then - Actions
          • Spiel - Display to (All players) the text: UNDEAD
        • Else - Actions
 

Attachments

  • WorldEditTestMap.w3x
    17 KB · Views: 27
Last edited:
Level 13
Joined
Oct 12, 2016
Messages
769
Alright, that is very helpful. Now I can make "random" start the player off with dwarven units.
Thank you very much Tasyen!

Now, does anyone know a custom script for setting local co-ordinates to a variable point, or to make a special effect at local co-ordinates?
 
How to use functions:

There are 2 ways to exectue functions:
  1. Call
  2. set

Calls are done following

call name(paramter1 , parameter2, parameter3)

or

sets are done this way

set variable = name(paramter1)
World Editor give all by you created variables the prefix udg_ stands for User Defined Global.
Set can only be used if a functions return type is not nothing, but you can call a function which does return not nothing

There are 3 key words: native or function, takes, returns.

returns : defines if you can use set
takes: defines the expected value types in the correct order.
the text after native/function is the name, write it befoof () to use it.

This way the created effect can be called by last Created Special effect.
  • set bj_lastCreatedEffect = AddSpecialEffect ( udg_String, udg_x, udg_y )
 
Level 8
Joined
Jan 28, 2016
Messages
486
Depends. I just read this from your other post:
EDIT:
The custom script's function is to respawn a specific indexed unit at a specific location when it dies.
The thing I need is a custom script to make the special effect at the location where the unit respawns.
Or, a custom script to set "TempPoint" the the local variable co-ordinates. I don't know much of anything in JASS, and prefer using GUI. So, I just don't know a lot of custom script functions, or where I can reference them.

You can use GUI for the special effect like below seeing as you already have CreepPoint[ii] setup.
  • GUI Example
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Thunder Thighs
    • Actions
      • Custom script: call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_CreepPoint[ii]),GetLocationY(udg_CreepPoint[ii]),270),ii)
      • Special Effect - Create a special effect at CreepPoint[ii] using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
      • Special Effect - Destroy (Last created special effect)

Since you're using locations, you could make use of the following Jass native:
native CreateUnitAtLoc takes player id, integer unitid, location whichLocation, real face returns unit

That way you can avoid the extra two function calls needed to get the x and y coordinates of CreepPoint[ii].
 
Level 13
Joined
Oct 12, 2016
Messages
769
Ah, I always wondered what "udg" stood for. That makes more sense now. Thank you Tasyen for the insight.

Dehua, my main problem with this is this part:
  • Special Effect - Create a special effect at CreepPoint[ii] using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
The "ii" is a local variable set earlier in the trigger before a timer.
I couldn't figure out how to set the "ii" to an integer I can then use in GUI.
I got this scripting off a friend who said I could use this to make certain units respawn.
 
Last edited:
Level 11
Joined
Jun 2, 2004
Messages
849
You can easily get JASS equivalents of GUI functions by copy/pasting them into a new trigger and converting that trigger to custom text. Alternatively if you want to stick to GUI for things like this, you can set globals to locals and you use the global in place of the local.
Code:
set udg_TempInt = ii

If you want to preserve your global variable, you can temporarily set it to a local variable at the start of the trigger and restore it at the end.
Code:
local integer LocalInt = udg_TempInt

blah blah blah

set udg_TempInt = LocalInt
 
Level 13
Joined
Oct 12, 2016
Messages
769
Thank you very much, Kaijyuu. Now I know more on how to set and deal with local variables in custom script!
I'm going to try this out. If all else fails, I'll just say "sod this" and find another way to do it in GUI.
 
Status
Not open for further replies.
Top