|Custom Stuff 1
Information presented below this line is outdated syntax or information used for Custom Stuff 1. It will not work with Custom Stuff 2.
This is a basic, rough and ready example of how to create an item that will cause a lightning strike at the block the player is looking at, i.e. the block directly where the cursor is pointing to rather than a block within range of the player.
My knowledge of how this actually works is limited, as it was mainly acheived through trial and error, but I'll do my best to explain it.
Here is the example code for the actual item:
name = "Lightning Item"; id = 500; iconfile = "example.png"; iconindex = 1; type = "normal"; rightclickair = "customstuff.loadScript('lightningitem.script');";
Other atrributes can be added to the item that suit your own needs such as 'maxuses', 'maxstack', 'damage' etc, especially if this is being used as a magical power for a weapon. See the items page for all the available options.
The important part here is the last line with the trigger 'rightclickair'. Normally you would just use the 'rightclick' trigger and this would affect the block you were currently selecting within range of the player. Using 'rightclickair' doesn't appear to actually let you select 'air', you still have to be looking at a block, but it does appear to let you click outside the normal range of the player. The rest of the line then calls the script which will set the location of the strike and create the actual lightning.
Here is the code for the script:
var x = player.getLookX(1000); var y = player.getLookY(1000); var z = player.getLookZ(1000); world.createThunderbolt(x, y, z);
The first three lines set up the three variables for x, y and z co-ordinates and they define the location of the block where the players cursor is pointing at. The number in brackets (1000) is the range within the world that the item can affect. The range can be decreased for a more localized effect since 1000 is a very large distance. The range can also be increased beyond 1000, though if the range actually extends any farther would be difficult to determine due to your maximum view distance in game.
The final line creates the actual lightning within the world at x, y and z which is defined in the previous lines.
WARNING!!! Repeated, fast right-clicking on the same spot can potentially cause a 'Saving Chunks' crash. You have been warned.
Mobs will burn if they are close enough to the strike (it doesn't need to be a direct hit). If your game is set at Peaceful or Easy I have found that wood, leaves etc do not burn once hit. Set your game to Normal or above to make blocks set alight with fire and continue burning.