• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

GMSI - Script for Hotkey/Buttonpos

Status
Not open for further replies.
Level 8
Joined
Oct 1, 2010
Messages
408
Hi,

I'm using this GMSI script that someone already made (Priwin) and I need to modify it so that if a unit has a certain hotkey then the x and y button position will be changed to a certain value.

Example: I want all units with Q as a hotkey to have their X and Y button position set to 0,0.

These are the hotkeys I plan to use and the corresponding button positons:
Q: 0,0
W: 1, 0
E: 2, 0
R: 3, 0
A: 0, 1
S: 1, 1
D: 2, 1
Z: 0, 2
X: 1, 2
C: 2, 2

This thing is just really confusing the heck out of me, and I'd really appreciate any help.

This is the script I'm currently using (I had to save it in a notepad because hive won't let me upload GSI files):
 

Attachments

  • WoW_balancing_hiveworkshop.txt
    7 KB · Views: 153
Can you explain your problem a bit more? Do you mean for them to have an ability button position of 0,0 if they have a hotkey Q? Or is that just for when they are being trained or whatever?

One thing to consider about button position is that it shares raw names. The x button position has the raw name of "Buttonpos" and the y button position also has the raw name of "Buttonpos":

http://www.eeve.org/doc/c10.html#3 said:
As said in the last chapter object attributes are accessed using the raw names. However, there are some attributes in the Object Editor, that appear twice. The most prominent Example is the Buttonposition. If you check the raw values for x and y Buttonposition, you will see that they re both named "Buttonpos". GMSI, has to know which one you mean if you access "Buttonpos", so it was made like this: The first value is just called as it is called in the Editor, so "Buttonpos" will refer to the X button position. All other appearances are numerated starting with 1, so "Buttonpos1" would be the Y buttonposition. Example:

Code:
Map map = loadMap(...);
map.objects.hpea.Buttonpos = 1;  		//alter the x buttonpos of the peasant
map.objects.hpea.Buttonpos1 = 1;		//alter the y buttonpos of the peasant
I know that this syntax is very dissatisfying. Maybe I will code something new some day. However, if you are very familiar with the file format of these files, this notation is consistent. See this example, that you know what I mean: Check a three level upgrade in your Object Editor. As you can see the field "Requires" is enumerated like explained above. However, "Art" isn't enumerated like that. Instead, it is just three times the word "Art". So GMSI enumerates "Art" just like "Requires". This adds some consistency, where Blizzard has none.
 
Level 8
Joined
Oct 1, 2010
Messages
408
Sorry yeah I meant the position of the units when that are being trained. Priwin already set up some conditions so only units in the map that are going to be used will have the script run over them, so it shouldn't effect abilities. So, to clarify, I'm referring to the Art - Button Position (X) and Art - Button Position (Y). That's how it appears in JNGP at least. I think that is what gexx is talking about in the online manual you quotted.

See this script is going to be used on the units in WoW Risk, which has like 17 different races and each race has 10 unique units that all spawn from the same building and I want to make the hotkey setup uniform for each race's building. So, if this all works out, I want to be able to change the hotkey for a unit and then have the unit's button position change to its corresponding X,Y (ex. Q is 0,0) in the script. I hope this makes sense, sorry for any confusion.
 
Last edited:
You can try this:
PHP:
string mapFile = (@args[0] == null?fileDialog("Choose a map",@inputPath,".w3x"):@args[0]);

//Load the map
Map map = loadMap(mapFile,false,false);

array x = array();

x["Q"] = 0;
x["W"] = 1;
x["E"] = 2;
x["R"] = 3;

x["A"] = 0;
x["S"] = 1;
x["D"] = 2;

x["Z"] = 0;
x["X"] = 1;
x["C"] = 2;

for(string s: map.objects) {
	Wc3obj obj = map.objects[s];
	if (!(obj instance of Unit)) continue;
	if (obj.Hotkey == "Q") or
       (obj.Hotkey == "W") or
	   (obj.Hotkey == "E") or
       (obj.Hotkey == "R") {
		obj.Buttonpos  = x[obj.Hotkey];
		obj.Buttonpos1 = 0; 
	} else if (obj.Hotkey == "A") or
	   (obj.Hotkey == "S") or
	   (obj.Hotkey == "D") {
		obj.Buttonpos  = x[obj.Hotkey];
		obj.Buttonpos1 = 1;
	} else if (obj.Hotkey == "Z") or
	   (obj.Hotkey == "X") or
	   (obj.Hotkey == "C") {
		obj.Buttonpos  = x[obj.Hotkey];
		obj.Buttonpos1 = 2;
	}
}

It is untested, but it should work. Obviously I can reduce the complexity by optimizing it but my GMSI scripting memory is a bit foggy so I'd rather not run the risk.
 
Level 8
Joined
Oct 1, 2010
Messages
408
I just tried running the code and got this error message:

PHP:
script.SyntaxError: Syntax error in line 65 in file WoW_balancing_without_random - Copy.gsl: if ( ! ( obj ->instance<- of Unit ) ) continue ; (Identifyer)
 49Insert semicolon ";" to finish previous statement

Not sure what it means though because you did put a semicolon at the end of the above statement.
 
Level 8
Joined
Oct 1, 2010
Messages
408
OK just tried it and this is what I got:

PHP:
script.SyntaxError: Syntax error in line 67 in file WoW_balancing_without_random - Copy.gsl: ( obj.Hotkey=="W" ) ->or<- (Identifyer)
 187Insert semicolon ";" to finish previous statement

Same kind of thing, does or not need a space either? Sorry, I'd fix these minor things myself but I've only used VB so I don't know this programs syntax at all.
 
Heh, I think I'm too used to JASS. Logical or's should be || in most lanaguages, so try this:
PHP:
string mapFile = (@args[0] == null?fileDialog("Choose a map",@inputPath,".w3x"):@args[0]);

//Load the map
Map map = loadMap(mapFile,false,false);

array x = array();

x["Q"] = 0;
x["W"] = 1;
x["E"] = 2;
x["R"] = 3;

x["A"] = 0;
x["S"] = 1;
x["D"] = 2;

x["Z"] = 0;
x["X"] = 1;
x["C"] = 2;

for(string s: map.objects) {
    Wc3obj obj = map.objects[s];
    if (!(obj instanceof Unit)) continue;
    if (obj.Hotkey == "Q") ||
       (obj.Hotkey == "W") ||
       (obj.Hotkey == "E") ||
       (obj.Hotkey == "R") {
        obj.Buttonpos  = x[obj.Hotkey];
        obj.Buttonpos1 = 0; 
    } else if (obj.Hotkey == "A") ||
       (obj.Hotkey == "S") ||
       (obj.Hotkey == "D") {
        obj.Buttonpos  = x[obj.Hotkey];
        obj.Buttonpos1 = 1;
    } else if (obj.Hotkey == "Z") ||
       (obj.Hotkey == "X") ||
       (obj.Hotkey == "C") {
        obj.Buttonpos  = x[obj.Hotkey];
        obj.Buttonpos1 = 2;
    }
}
 
Level 8
Joined
Oct 1, 2010
Messages
408
Man thanks for all your help Purge. I really appreciate this.

I just tried it with the new one and got this error:

PHP:
script.SyntaxError: Syntax error in line 66 in file WoW_balancing_without_random - Copy.gsl: if ( obj.Hotkey=="Q" ) ->||<- (BBinOp)
No suggestions available

I looked through his manual briefly and found this as an example for using logical operators in GMSI:

bool b; b = (true || false); //true b = (true && false); //false b = !false; //true


To me it looks like || should have worked, but maybe you can gleam some insight from this?
 
Hmm.. What is the or operator for this? xD

Well, you can try this:
PHP:
string mapFile = (@args[0] == null?fileDialog("Choose a map",@inputPath,".w3x"):@args[0]);

//Load the map
Map map = loadMap(mapFile,false,false);

string key;

for(string s: map.objects) {
	Wc3obj obj = map.objects[s];
	if (!(obj instanceof Unit)) continue;
	key = obj.Hotkey;
	if (key == "Q") {
		obj.Buttonpos  = 0;
		obj.Buttonpos1 = 0;
	} else if (key == "W") {
		obj.Buttonpos  = 1;
		obj.Buttonpos1 = 0;
	} else if (key == "E") {
		obj.Buttonpos  = 2;
		obj.Buttonpos1 = 0;
	} else if (key == "R") {
		obj.Buttonpos  = 3;
		obj.Buttonpos1 = 0;
	} else if (key == "A") {
		obj.Buttonpos  = 0;
		obj.Buttonpos1 = 1;
	} else if (key == "S") {
		obj.Buttonpos  = 1;
		obj.Buttonpos1 = 1;
	} else if (key == "D") {
		obj.Buttonpos  = 2;
		obj.Buttonpos1 = 1;
	} else if (key == "Z") {
		obj.Buttonpos  = 0;
		obj.Buttonpos1 = 2;
	} else if (key == "X") {
		obj.Buttonpos  = 1;
		obj.Buttonpos1 = 2;
	} else if (key == "C") {
		obj.Buttonpos  = 2;
		obj.Buttonpos1 = 2;
	}
}

That is just a raw and nasty version but should get the job done. (albeit slowly)

EDIT: Ah, I might've just forgotten to put it into parentheses. It would probably be ((obj.Hotkey == "Q") || (obj.Hotkey == "W") || ....) If the version I posted in this post doesn't work for whatever reason or is too slow then I can change the other one.
 
Level 8
Joined
Oct 1, 2010
Messages
408
YES!!! It works!!

Sorry for the delayed response, I was just testing it out.

Thank you so much purge!! You've saved me hours here, you rock !!

Seriously appreciate it man, if you need anything from me, within reason ofc ><, please do not hesitate to ask!

:ogre_hurrhurr:
 
Status
Not open for further replies.
Top