obj/Towers
icon = 'Towers.dmi'
Arrow
Range = 5
Speed = 10
Top
icon_state = "top"
layer = MOB_LAYER + 1
pixel_y = 32
Bottom
icon_state = "bottom"
New()
..()
spawn()
Search()
proc/Search()
while(src)
for(var/mob/Grundies/G in world)
if(G)
if(G in view(src.Range,src))
var/obj/Projectiles/Arrow/A = new /obj/Projectiles/Arrow(src)
walk_to(A,G)
else
break()
sleep(src.Speed)
Any suggestions?
var/obj/Projectiles/Arrow/A = new /obj/Projectiles/Arrow(src) is also redundant. You've already told the compiler you wish to create a new instance of obj/Projectiles/Arrow stored as the instance A. var/obj/Projectiles/Arrow/A = new(src). Also did you mean to spawn the projectile inside of the turret? If not you'd want to place it at src.loc.
-----------------------------
Hrm. I gave your code a test and I can spot a huge problem with it. The projectiles never delete themselves and just follow the player around instead of doing any sort of collision magic. I can understand it getting laggy if you have a ton of towers shooting at the player and projectiles building up under them.
I just wrote this up pretty quickly, and it could stand to be more robust but it's a rudimentary idea of how to handle projectiles and towers: