onLoad:
This part of the script is meant to only run once, and thus only meant to run on map load.
pinv = player.getInventory();
onUpdate:
This part of the script is meant to run every tick, and thus must be put into your global onUpdate script.
var pvel = player.getVelocity();
var ppos = player.getPosition();
if (pvel.y > 0 && !player.isOnLadder() && world.getBlockID(ppos.x, ppos.y - 2, ppos.z) != 8 &&
world.getBlockID(ppos.x, ppos.y - 2, ppos.z) != 9 && world.getBlockID(ppos.x, ppos.y - 1, ppos.z) != 8 &&
world.getBlockID(ppos.x, ppos.y - 1, ppos.z) != 9) {
if ((pinv.getCurrentItem() != null && pinv.getCurrentItem().getItemID() != 470) || pinv.getCurrentItem() == null) {
if ((pinv.getOffhandItem() != null && pinv.getOffhandItem().getItemID() != 470) || pinv.getOffhandItem() == null) {
player.setVelocity(pvel.x, -pvel.y, pvel.z);
} } }