Auto-close doors

madhon

MadCommands Dev
#1
Use this procedure as a touch even trigger to have door automatically close 1 second after opening.
Should work with all kinds of doors, even trapdoors.



Limitation: the door will close silently as MadCommands currently does not support sounds at the time I am writing this.

To create the command, simply copy and paste this to RCON (in the game you have to add forward slash to the beginning of each line):

Code:
cmd create closedoor
cmd edit closedoor 1 # Close door 1 second after opening (touch event trigger handler)
cmd edit closedoor 2 let %ll% = %args%[3]
cmd edit closedoor 3 let %xx% = %args%[4]
cmd edit closedoor 4 let %yy% = %args%[5]
cmd edit closedoor 5 let %zz% = %args%[6]
cmd edit closedoor 6 let %block% = blockinfo(%ll%, %xx%, %yy%, %zz%)
cmd edit closedoor 7 if \"door\" notin lowercase(%block%[\"name\"]) then exit
cmd edit closedoor 8 if (%block%[\"variant\"] < 8) or (\"trap\" in lowercase(%block%[\"name\"])) then goto 11
cmd edit closedoor 9 let %yy% = %yy% - 1
cmd edit closedoor 10 let %block% = blockinfo(%ll%, %xx%, %yy%, %zz%)
cmd edit closedoor 11 let %variant% = %block%[\"variant\"]
cmd edit closedoor 12 if %variant% > 7 then let %variant% = %variant% - 8
cmd edit closedoor 13 if %variant% > 3 then let %variant% = %variant% - 4
cmd edit closedoor 14 if %block%[\"variant\"] > 7 then let %variant% = %variant% + 8
cmd edit closedoor 15 let %door% = %block%[\"id\"]
cmd edit closedoor 16 sleep 1
cmd edit closedoor 17 block %ll% %xx% %yy% %zz% %door%:%variant%
If you have new commands disabled by default, don't forget to enable it:

Code:
cmd enable closedoor
Do not register the procedure as a new command, unless you want to use it to close door at specified position manually.

Now simply set this to be used as a touch event trigger:

Code:
cmd trigger touch closedoor
If you already have a touch event trigger and don't want to remove it, you can add these lines to it to call closedoor after your own trigger:

Code:
let %params% = join(%args%[1+], \" \")
/cmd run closedoor touch %params%