ID:140060
 
Code:
obj/projectile
var/amount = 4
var/damage = 14
var/length = 20
var/delay = 2
var/mob/owner
var/list/group = new

proc/ChangeState()
if(src.amount <= 9)
icon_state = "less than 10"
else if(src.amount >= 10 && src.amount <= 25)
icon_state = "10-25"
else if(src.amount <= 0)
del(src)
else
icon_state = "25-50"

Bump(atom/A)
var/mob/O = src.owner
if(istype(A,/mob))
var/mob/M = A
src.explode()
if(M != O)
M.Hp -= src.damage
world << "[src] hits [M] for [src.damage] damage!"
M.DeathCheck(O)
src.explode()
else if(istype(A,/obj/breakable))
var/obj/breakable/B = A
B.durability -= src.damage
world << "[src] hits [B] for [src.damage] damage!"
B.ChangeState()
world << "Dura: [B.durability]/[B.max_durability]"
src.explode()
else if(istype(A,/obj/dense))
src.explode()
else
return

New(_loc,mob/_owner,_list)
if(_owner)
if(_list)
src.group = _list
src.dir = _owner.dir
if(!src.loc) src.loc = get_step(_owner,_owner.dir)
src.owner = _owner
walk(src, src.dir, src.delay)
Move()
src.length--
if(!src.length) del(src)
.=..()
return

proc/explode()
for(var/obj/projectile/xx in src.group)
del(xx)

Fire1
icon = 'target.dmi'
density = 1

Fire2
icon = 'target.dmi'
density = 1

proc/Fire(mob/_loc)
var/list/flist = new

flist+= new/obj/projectile/Fire1(locate(_loc.x-1,_loc.y-1,_loc.z),_loc,flist)
flist+= new/obj/projectile/Fire1(locate(_loc.x+1,_loc.y-1,_loc.z),_loc,flist)
flist+= new/obj/projectile/Fire1(locate(_loc.x-1,_loc.y+1,_loc.z),_loc,flist)
flist+= new/obj/projectile/Fire1(locate(_loc.x+1,_loc.y+1,_loc.z),_loc,flist)


Problem description:I can't seem to get the projectile to delete all it's little pieces all at once so it looks like one big attack.

What you might wanna try doing is adding all the seperate objects to a list - and then using a single proc to del all obj's in that list.
In response to Kaamos (#1)
Is the explode proc I have the wrong way of doing that?
In response to Onolt (#2)
Almost: because the list contains the object itself, and when you delete the object all of its procs stop. You'll need to skip over src when looping through the group list, and delete it after every other object.

Also: you shouldn't have the =new in the declaration of the group variable, because you are never ever actually using that default setting and so it either does nothing or is a waste of resources.
In response to Garthor (#3)
I got rid of the new declaration and changed the explode proc to try and destroy the src of the group last but it only works when I use the attack facing east or west.

This is the change I made to try and exclude the src
    proc/explode()
for(var/obj/projectile/xx in src.group)
if(src.group.len <= 1)
del(src)
del(xx)
In response to Onolt (#4)
No. You need to ONLY delete xx if it's not src. Then, AFTER the for() loop, you can delete src.

The moment you delete src, the proc (and all procs belonging to src) will end.
In response to Garthor (#5)
Use something like this:
for(var/variable in list)
if(variable == src) continue //If variable is src, skip to the next one.
del variable
del src


Or, just leave src out of group.
In response to I-Aryn-I (#6)
I-Aryn-I wrote:
Or, just leave src out of group.

Not possible here... all objects are sharing the same list, and really there's no reason to have to construct a separate list for each one.
In response to Garthor (#7)
I can't believe I didn't think of that. It works now so thanks for all your help all of you! Before I leave with this is there anything I should do to improve my code in the snippet?

Edit: I thought it would be a waste to create another topic for a problem that is in someway related to this so I thought I'd post it here.

When the icons are moving it unison they sometimes split apart, how can I fix this?

I have a feeling it has something to do with this New proc and possibly the Move proc.

Code Snippet:
obj/projectile
New(_loc,mob/_owner,_list)
if(_owner)
if(_list)
src.group = _list
src.dir = _owner.dir
if(!src.loc) src.loc = get_step(_owner,_owner.dir)
src.owner = _owner
walk(src, src.dir, src.delay)
Move()
src.length--
if(!src.length) del(src)
.=..()
return