Pretty well except it could be cleaned up a bit.
Here's a fancy way of doing if statements:
if(%trigger == 4 && %val == 1)
And for more fun, instead of %val == 1, you can just use %val, and instead of something == 0, you can just use !something.
as in:
if(%trigger == 4 && %val)
That would be the same thing as I said above.