Is there a pull lever open gate macro?

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
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Is there a pull lever open gate macro?

Post by winkr7 »

Hello;

Is there a macro where if you pull a lever it opens and closes a gate? I want to be able to toggle terrain from an item (lever). I looked at lots of macros and can't find one.

thanks for your time.
yours
winkr7
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2364
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Is there a pull lever open gate macro?

Post by Lord-Knightmare »

winkr7 wrote: September 1st, 2022, 12:27 pm Hello;

Is there a macro where if you pull a lever it opens and closes a gate? I want to be able to toggle terrain from an item (lever). I looked at lots of macros and can't find one.

thanks for your time.
yours
winkr7
I guess closest you can find to this is in the "Mountain Witch" and related works. A mainline example can be THoT's code in the last scenario (Underlevels). There's also IFTU as well
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Is there a pull lever open gate macro?

Post by beetlenaut »

There is now! Put it in a prestart event. This macro should automatically work with any door or gate terrain facing any direction. It assumes there are two separate lever images. If there aren't, the items don't need formulas, and a dozen lines can be removed. Also, since I don't have your lever images, I just use a spear that flips back and forth.

This is may be the shortest way to do it (with WML). I did try moving all the similar-looking lines into a separate macro, but the overhead made it a bit longer in the end.

Code: Select all

#define LEVER_DOOR LEVER_X LEVER_Y DOOR_X DOOR_Y
    # We need to check the door terrain to see which lever image to start with.
    [store_locations]
        x,y={DOOR_X},{DOOR_Y}
        variable=door
    [/store_locations]
    [item]
        x,y={LEVER_X},{LEVER_Y}
        # See the note in [terrain].
        image="$(if( substring('$door.terrain', -1)='o', 'items/spear-fancy.png', 'items/spear-fancy.png~FL()'))"
    [/item]

    [set_menu_item]
        id=lever-{LEVER_X}-{LEVER_Y}
        [filter_location]
            x,y={LEVER_X},{LEVER_Y}
        [/filter_location]
        [show_if]
            [have_unit]
                side=1
                x,y={LEVER_X},{LEVER_Y}
            [/have_unit]
        [/show_if]
        description= _ "Pull lever"
        [command]
            [store_locations]
                x,y={DOOR_X},{DOOR_Y}
                variable=door
            [/store_locations]
            # We could check to make sure we really did just store a door, but if we end up with
            # an invalid terrain code because we didn't, the game will just ignore it anyway.
            [remove_item]
                x,y={LEVER_X},{LEVER_Y}
                image="$(if( substring('$door.terrain', -1)='o', 'items/spear-fancy.png', 'items/spear-fancy.png~FL()'))"
            [/remove_item]
            [terrain]
                x,y={DOOR_X},{DOOR_Y}
                # Open and closed doors have the same terrain codes, except that open doors
                # end in "o". This formula checks the terrain code to see if its last letter
                # is "o" or not, then either selects the code not including its last letter or
                # adds an "o".
                terrain="$(if( substring('$door.terrain', -1)='o', substring( '$door.terrain', 0, length('$door.terrain')-1), '$door.terrain'..'o' ))"
            [/terrain]
            # The image we need now is the opposite of what it was the last time we stored
            # the terrain code, so we will specify the images in reverse order here.
            [item]
                x,y={LEVER_X},{LEVER_Y}
                image="$(if( substring('$door.terrain', -1)='o', 'items/spear-fancy.png~FL()', 'items/spear-fancy.png'))"
            [/item]
            [clear_variable]
                name=door
            [/clear_variable]
        [/command]
    [/set_menu_item]
    [event]
        name=victory
        [clear_menu_item]
            id=lever-{LEVER_X}-{LEVER_Y}
        [/clear_menu_item]
    [/event]
#enddef
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Is there a pull lever open gate macro?

Post by lhybrideur »

It is not a macro but here is the code I use. There is a lever on 54 15, that allows to open/close a door at 52 14 when you move on it

Code: Select all

	{PLACE_IMAGE scenery/lever_up.png 54 15}
	[event]
		name=prestart
		{VARIABLE lever_pulled 0}
	[/event]
	[event]
		name=moveto
		first_time_only=no
		[filter]
			side=1
			x=54
			y=15
		[/filter]
		
		[message]
			speaker=unit
			message="There is a lever on the wall. Should I pull it?"
			[option]
				message="Yes, do it."
				[command]
					[if]
						[variable]
							name=lever_pulled
							equals=0
						[/variable]
						[then]
							[terrain]
								x=52
								y=14
								terrain=Rr^Pw|o
							[/terrain]  
							{PLACE_IMAGE scenery/lever_down.png 54 15}
							[redraw]
								clear_shroud=yes
							[/redraw]
							{VARIABLE lever_pulled 1}
							[message]
								speaker=unit
								message="It has opened a door."
							[/message]
						[/then]
						[else]
							[if]
								[variable]
									name=lever_pulled
									equals=1
								[/variable]
								[then]  
									[terrain]
										x=52
										y=14
										terrain=Rr^Pw|
									[/terrain] 
									{PLACE_IMAGE scenery/lever_up.png 54 15}
									{VARIABLE lever_pulled 0}
									[message]
										speaker=unit
										message="The door is closed back."
									[/message]
								[/then]
							[/if]
						[/else]
					[/if]
				[/command]
			[/option]
			[option]
				message="No, not now."
			[/option]
		[/message]
	[/event]
It requires a variable per door, so not really macro compatible I would say. Unless you add a macro parameter that would be a door number.
User avatar
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Re: Is there a pull lever open gate macro?

Post by winkr7 »

Hello all,

Lord-Knightmare, thank you for pointing me in a reasonable direction for my macro search.

beetlenaught--Thankyou for the macro, I got it to work. A very clever use of the spear as a lever too. I think you should seriously consider putting
this is the folder of useful macros. It doesn't require any non-standard graphics and I like the way it appears in the menu of the player.

Ihybrideur--thanks for the code, I don't have a lever_up.png in my scenery folder. Where did you get this graphic?

Thankyou all for your time.
yours
winkr7
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Is there a pull lever open gate macro?

Post by beetlenaut »

winkr7 wrote: September 2nd, 2022, 4:51 pm A very clever use of the spear as a lever too.
The spear image was just for demonstration. IMO, it does require non-standard graphics, and I expected you to make or use some other ones. (Maybe lhybrideur will share his lever images.) If I saw a spear in a scenario, I would not expect it to operate like a lever. I thought the clever bit was my use of formulas. ^_^
winkr7 wrote: September 2nd, 2022, 4:51 pm I don't have a lever_up.png in my scenery folder.
That's a personal images/scenery folder. The [binary_path] tag makes the game look there as well as in the core folders.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Re: Is there a pull lever open gate macro?

Post by winkr7 »

What is the proper etiquette if an Era has one or two images I want for my scenario?
I could link to the whole era or just swipe the image I need. I can site the era in my credits and avoid the download.

The upside of just grabbing the image is there is no additional download and I don't have to wait for the Era when 1.17 comes out to make
my scenario 1.17 useable. Is it acceptable to take someone else's resources and credit the source or do I always link the whole Era?

thanks for your time.
yours
winkr7
User avatar
Celtic_Minstrel
Developer
Posts: 2222
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Is there a pull lever open gate macro?

Post by Celtic_Minstrel »

Grabbing images from an era uploaded to the add-ons server is safe, as you need to agree to release your content under either GPL or Creative Commons before you can upload. So just swipe the image you need and add a note in your credits to indicate what era you got it from and who made it (which hopefully will be mentioned in the source era's credits).
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Re: Is there a pull lever open gate macro?

Post by winkr7 »

Thanks Celtic_Minstrel. I will credit the Era source, but, as you point out, it is not always clear who actually drew the image.

yours
winkr7
Post Reply