Skip to content

Commit d509569

Browse files
committed
arrows.js w/ lava arrows
This is a modified version of the arrows.js script that is included with the ScriptCraft plugin. It adds a sixth arrow type, lava arrows, which does exactly what the name says. The bits that were modified for this are line 40 (adding 'lava' to the list of arrow types), and lines 121-125, which implements the drone function at the location where the arrow lands in order to place a block of lava (10 is the block type id number for lava).
1 parent d6f9500 commit d509569

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

arrows.js

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*************************************************************************
2+
## Arrows Plugin
3+
4+
The arrows mod adds fancy arrows to the game. Arrows which...
5+
6+
* Launch fireworks.
7+
* Explode on impact.
8+
* Force Lightning to strike where they land.
9+
* Teleport the player to the landing spot.
10+
* Spawn Trees at the landing spot.
11+
12+
### Usage:
13+
14+
* `/js arrows.firework(self)` - A firework launches where the the arrow lands.
15+
* `/js arrows.lightning(self)` - lightning strikes where the arrow lands.
16+
* `/js arrows.teleport(self)` - makes player teleport to where arrow has landed.
17+
* `/js arrows.flourish(self)` - makes a tree grow where the arrow lands.
18+
* `/js arrows.explosive(self)` - makes arrows explode.
19+
* `/js arrows.normal(self)` sets arrow type to normal.
20+
* `/js arrows.sign(self)` turns a targeted sign into a Arrows menu
21+
22+
All of the above functions can take an optional player object or name
23+
as a parameter. For example: `/js arrows.explosive('player23')` makes
24+
player23's arrows explosive.
25+
26+
***/
27+
28+
var signs = require('signs'),
29+
fireworks = require('fireworks'),
30+
utils = require('utils'),
31+
bkTeleportCause = org.bukkit.event.player.PlayerTeleportEvent.TeleportCause,
32+
bkArrow = org.bukkit.entity.Arrow,
33+
bkPlayer = org.bukkit.entity.Player,
34+
bkTreeType = org.bukkit.TreeType,
35+
EXPLOSIVE_YIELD = 2.5,
36+
_store = { players: { } },
37+
arrows = plugin( 'arrows', { store: _store }, true ),
38+
i,
39+
type,
40+
_types = [ 'Normal', 'Explosive', 'Teleport', 'Flourish', 'Lightning', 'Firework', 'Lava' ];
41+
42+
exports.arrows = arrows;
43+
44+
45+
for ( i = 0; i < _types.length; i++ ) {
46+
type = _types[i].toLowerCase();
47+
// iife (immediately-invoked function expression)
48+
arrows[ type ] = ( function( n ) {
49+
return function( player ) {
50+
player = utils.player( player );
51+
if ( player ) {
52+
arrows.store.players[ player.name ] = n;
53+
} else {
54+
console.warn('arrows.' + n + ' No player ' + player);
55+
}
56+
};
57+
} )( i );
58+
}
59+
60+
/*
61+
called when the player chooses an arrow option from a menu sign
62+
*/
63+
var _onMenuChoice = function( event ) {
64+
arrows.store.players[ event.player.name ] = event.number;
65+
};
66+
var convertToArrowSign = signs.menu( 'Arrow', _types, _onMenuChoice );
67+
68+
/*
69+
turn a sign into a menu of arrow choices
70+
*/
71+
arrows.sign = function( cmdSender ) {
72+
var sign = signs.getTargetedBy( cmdSender );
73+
if ( !sign ) {
74+
throw new Error( 'You must first look at a sign!' );
75+
}
76+
return convertToArrowSign( sign, true );
77+
};
78+
79+
/*
80+
event handler called when a projectile hits something
81+
*/
82+
var _onArrowHit = function( event ) {
83+
var projectile = event.entity,
84+
world = projectile.world,
85+
shooter = projectile.shooter,
86+
fireworkCount = 5,
87+
arrowType,
88+
launch = function( ) {
89+
fireworks.firework( projectile.location );
90+
if ( --fireworkCount ) {
91+
setTimeout( launch, 2000 );
92+
}
93+
};
94+
95+
if (projectile instanceof bkArrow
96+
&& shooter instanceof bkPlayer) {
97+
98+
arrowType = arrows.store.players[ shooter.name ];
99+
100+
switch ( arrowType ) {
101+
case 1:
102+
projectile.remove();
103+
world.createExplosion( projectile.location, EXPLOSIVE_YIELD );
104+
break;
105+
case 2:
106+
projectile.remove();
107+
shooter.teleport( projectile.location, bkTeleportCause.PLUGIN );
108+
break;
109+
case 3:
110+
projectile.remove();
111+
world.generateTree( projectile.location, bkTreeType.BIG_TREE );
112+
break;
113+
case 4:
114+
projectile.remove();
115+
world.strikeLightning( projectile.location );
116+
break;
117+
case 5:
118+
projectile.remove();
119+
launch();
120+
break;
121+
case 6:
122+
projectile.remove();
123+
d = new Drone(projectile.location)
124+
d.box(10)
125+
break;
126+
}
127+
}
128+
};
129+
events.projectileHit( _onArrowHit );
130+

0 commit comments

Comments
 (0)