Using the location of a unit

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
ResExsention
Posts: 97
Joined: March 17th, 2018, 12:00 am
Location: Alberta, Canada

Using the location of a unit

Post by ResExsention »

Hello!

I've been working on a campaign so far (Purger of Evil) and I would like to find a way to call on the location of a specific unit as a variable in a generic event (not one of those moveto events in which $x1$x2 would work fine, but in something like a new turn event, where $x1 and $y1 could refer to anything. I've found out a few ways:

- Store the unit and then somehow call on the coordinates of the stored unit. Don't know how to do that.
- Or use $unitID.x and $unitID.y. It looks like the most promising, but it doesn't seem to be working when spawning units near the leader in a new turn with the [unit] tag going:

Code: Select all

[unit]
	side=2
	type=Lieutenant
	id=unitID1
	name="Lieutenant Lol"
	canrecruit=no
	x=$leaderID.x
	y=$leaderID.y
	
	{IS_LOYAL}
[/unit]
Though nothing happens. Is this how I'm supposed to do it?

I mean, I know you can invoke $unitID.id or maybe type, but I don't really know if calling the preset x y variables of a unit works. Spawning units is failing already. Any ideas? If I've already solved this, please help me out here, and tell me how I figured it out. I haven't found anything in the forums relating to this kind of topic, yet...

Thanks!
I am a ranger and my WML knives will implant themselves in your back.

Creator of the abandoned campaign Royalties Forgotten and the work in progress campaign Purger of Evil.
Maintainer of Fate of a Princess.
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Using the location of a unit

Post by Samonella »

ResExsention wrote: August 2nd, 2018, 4:03 am - Store the unit and then somehow call on the coordinates of the stored unit. Don't know how to do that.
- Or use $unitID.x and $unitID.y. It looks like the most promising, but it doesn't seem to be working when spawning units near the leader in a new turn with the [unit] tag going:
The right thing is actually a combination of these: you store the unit to a variable, then use $variableName.x to access the variable and get the coordinate.

Code: Select all

[store_unit]
    [filter]
        <filter by id or however you want>
    [/filter]
    variable=<some variable name>
[/store_unit]
[unit]
	side=2
	type=Lieutenant
	id=unitID1
	name="Lieutenant Lol"
	canrecruit=no
	x=$<some variable name>.x
	y=$<some variable name>.y
	
	{IS_LOYAL}
[/unit]
Happy coding!
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
ResExsention
Posts: 97
Joined: March 17th, 2018, 12:00 am
Location: Alberta, Canada

Re: Using the location of a unit

Post by ResExsention »

Ahh. I get it. So this is what it should look like?

Code: Select all

[unit]
	side=1
	type=General
	id=leaderID
	name="General Hello"
	canrecruit=yes
	recruit="Royal Guard, Halberdier, Master Bowman"
	x=50
	y=50
[/unit]
And then:

Code: Select all

[store_unit]
	[filter]
		id=leaderID
	[/filter]
	variable=generalHelloVariable
[/store_unit]
And then when I need to spawn a unit on his position:

Code: Select all

[unit]
	side=1
	type=Lieutenant
	id=unitID1
	name="Lieutenant Lol"
	canrecruit=no
	x=$generalHelloVariable.x
	y=$generalHelloVariable.y
	
	{IS_LOYAL}
[/unit]
Is that how it works? I think it is. Thanks, Samonella! ;)

EDIT: And that's how you manipulate a unit's variables if need be, with [set_variable], right? Like maybe:

Code: Select all

[set_variable]
	variable=generalHelloVariable.goto_x
	value=52
[/set_variable]
[set_variable]
	variable=generalHelloVariable.goto_y
	value=52
[/set_variable]
Is that the basic idea?
I am a ranger and my WML knives will implant themselves in your back.

Creator of the abandoned campaign Royalties Forgotten and the work in progress campaign Purger of Evil.
Maintainer of Fate of a Princess.
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Using the location of a unit

Post by Samonella »

ResExsention wrote: August 2nd, 2018, 5:44 pm Is that how it works? I think it is. Thanks, Samonella! ;)
Yup, exactly right!
ResExsention wrote: August 2nd, 2018, 5:44 pm EDIT: And that's how you manipulate a unit's variables if need be, with [set_variable], right? Like maybe:

Code: Select all

[set_variable]
	variable=generalHelloVariable.goto_x
	value=52
[/set_variable]
[set_variable]
	variable=generalHelloVariable.goto_y
	value=52
[/set_variable]
Is that the basic idea?
The basic idea, yes. Two notes:
-That only changes the variable, not the actual unit. To get the changes you made back into the real game you'd have to use [unstore_unit].
-The specific example you used, goto_x/y, doesn't make ai units move anywhere, the ai does whatever it wants with those values. But yeah that's how you use [set_variable].
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
ResExsention
Posts: 97
Joined: March 17th, 2018, 12:00 am
Location: Alberta, Canada

Re: Using the location of a unit

Post by ResExsention »

Well then, nothing more needs to be said about this. Thanks, Samonella!
I am a ranger and my WML knives will implant themselves in your back.

Creator of the abandoned campaign Royalties Forgotten and the work in progress campaign Purger of Evil.
Maintainer of Fate of a Princess.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Using the location of a unit

Post by Celtic_Minstrel »

Side note: The {IS_LOYAL} macro doesn't make a unit loyal. It only makes it look like it's loyal. To actually make it loyal you also need the following code:

Code: Select all

[modifications]
    {TRAIT_LOYAL}
[/modifications]
Or, if you want it to be loyal but not display the loyal trait, you can instead use upkeep=loyal.

You still need {IS_LOYAL} in both cases to add the visual indicator though.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Using the location of a unit

Post by gfgtdf »

Celtic_Minstrel wrote: August 5th, 2018, 7:40 pm Or, if you want it to be loyal but not display the loyal trait, you can instead use upkeep=loyal.
note that we are considering making upkeep=loyal a 'effect-controlled' attribute in 1.15 so it might be later to use a [object] with a apply_to=loyal effect.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
ResExsention
Posts: 97
Joined: March 17th, 2018, 12:00 am
Location: Alberta, Canada

Re: Using the location of a unit

Post by ResExsention »

Yes, I know about that. I just forgot to add

Code: Select all

[modifications]
     {TRAIT_LOYAL}
[/modifications]
I am a ranger and my WML knives will implant themselves in your back.

Creator of the abandoned campaign Royalties Forgotten and the work in progress campaign Purger of Evil.
Maintainer of Fate of a Princess.
Post Reply