How do I build a trap that activates when a player walks over it?

Edited

Use redstone blocks — and the pressure plate!

Place redstone and pressure plates using mods with Tynkerbot commands like these:

You don't need code to achieve this effect, if you'd like to place the blocks by hand. You can read about redstone circuits online:

https://minecraft.fandom.com/wiki/Category:Redstone_mechanics