ID:156134
 
Ok I'm not new to coding but this is something I have rarely been asked to, or have done.

How would one go about creating a projectile that hits other mobs if they are close enough not accounting for the mob that created it, then having it not hit a mob Twice? Like a chained spell? It seems pretty complex to do and I have been unable to find a solution by myself.


Please dont post a link to a demo seeing as I am on a phone...
Let's assume the following:

Player A shoots a projectile at Player B. Player C is within 3 tiles of Player B, Player D is within 3 tiles of Player C, and Player E is 10 tiles away from everyone.

Now, you would need to set a maximum amount of times the projectile can bounce - if infinite, you must respect the fact that this can go on for quite some time - if the beam were to diminish, then you might set it at a chain of 3 atoms before going away.

The projectile should therefore have 2 variables - the owner, and a list of hits.

obj
projectile
var mob/owner, list/hits=list()


Next, when the projectile Bump's another player, it must add that player to it's hit list, and see if it should move on to another player.

obj
projectile
Bump(mob/hit)
if(istype(hit,/mob) & M != src.owner) // Check if it's a mob, and check to make sure it is not the owner.
src.hits.Add(hit)
// implement your projectile's effects here.
if(length(src.hits)<=3) // The maximum amount of hits
for(var/mob/new_target in view(src,3)) // Again, can be changed; view will not recognize invisibility.
if(!src.hits.Find(new_target))
walk_towards(src,new_target) // walk to the new target
break


Of course, I'm not at home either so I cannot really come up with a mock system but this should put you on the right track.
In response to CauTi0N
Your example is flawed, for each player, it will walk towards them. you need it to pick a player and continue, get to the new player and do it again.
In response to Pirion
Fixed.
In response to CauTi0N
Thanks, only problem is it doesn't recognize "M" in;

if(istype(hit,/mob)) & M != src.owner
In response to Thelavaking
Excuse me, that M should be "hit". :)
In response to CauTi0N
Ehhh.. not to be a noob or a buggart, but I cannot seem to get a verb to spawn the projectile, it seems to fly through things no matter how I imput it..
In response to Thelavaking
Set density=1.