I am trying to make a skript that transforms Dispensers into automatic turrets, using arrows contained inside, when powered by redstone, they automatically shoot arrows towards players. I can't manage to create a proper vector, i made the arrow go from the player to the dispenser but not vice versa and i can't manage to fix. Code (Text): on place of dispenser: add event-block's location to {turrets::*} on break of dispenser: remove event-block's location from {turrets::*} command /removeturrets: trigger: delete {turrets::*} every 1 seconds in world "world": loop {turrets::*}: loop all players in radius 20 around loop-value: set {_loc1} to loop-value-1 set {_loc2} to loop-player's location set {_dir} to vector between {_loc1} and {_loc2} broadcast "%{_loc2}%" shoot a creeper from {_loc1} at speed 3 {_dir} Edit: tried also this but it's not working.. Code (Text): every 1 seconds in world "world": loop {turrets::*}: set {_loc1} to location above loop-value loop all players in radius 20 around loop-value: set {_loc2} to loop-player's location broadcast "Test" shoot an arrow from {_loc1} at speed 1 direction from {_loc1} to {_loc2}
you are looking for homing arrows (either only at the start of shot or constant homing), I have written this code for myself a few years ago, it may not be of the best quality or performance, but it works: Code (Text): function startHoming(projectile: entity, r: number, s: player): loop 50 times: {_projectile} doesn't exist: stop {_projectile} is dead: stop {_projectile} is on ground: stop if cooldown "target%id of {_projectile}%" is finish: loop all entities in radius 4 of block at {_projectile}: max health of loop-entity is higher than 3 loop-entity is not {_s} loop-entity's gamemode is survival or adventure if {_dist} is not set: set {_dist} to distance between loop-entity and {_projectile} set {_uniqueloc} to loop-entity else if distance between {_projectile} and loop-entity is less than {_dist}: set {_dist} to distance between loop-entity and {_projectile} set {_uniqueloc} to loop-entity {_uniqueloc} is set: create cooldown "target%id of {_projectile}%" for a second set {_actionloc} to location of {_uniqueloc} set y-coordinate of {_actionloc} to y-coordinate of {_actionloc}+0.5 set {_disturbings} to 0 {_actionloc} is set: loop blocks from block at {_actionloc} to block at {_projectile}: loop-block is solid loop-block is not any stairs or any slab or any carpet add 1 to {_disturbings} {_disturbings} is higher than 1: exit loop {_disturbings} is less than 2: set {_vector} to new vector 0, 0, 0 set velocity of {_projectile} to {_vector} push {_projectile} (direction from {_projectile} to {_actionloc}) at speed 0.75 delete {_disturbings} wait 2 ticks
Thanks! I used the last part of the code and it worked quite well! Code (Text): set {_loc2} to loop-value-2's location summon an arrow at {_loc1} set {_arrow} to spawned entity set {_vector} to new vector 0, 0, 0 set velocity of {_arrow} to {_vector} push {_arrow} (direction from {_arrow} to {_loc2}) at speed 5