ID:157546
 
What is a simple way that you can create a trail on a moving object? Here is what I tried... didnt work...

Edited for attempt at trail:
mob
verb
Fireballskill()
var/obj/Fireball/S=new(src.loc)
// S.dir = src.dir


// walk(S,src.dir)
obj
trail
icon = 'blood.dmi'
icon_state = "blood1"
obj
Fireball
icon = 'fireball.dmi'
icon_state = "small"
Move()
S.dir = src.dir
walk(S,src.dir)
new/obj/trail

Bump(mob/M)
if(ismob(M))
S = new(loc)
S.icon = 'fireball_hit.dmi'
src << "Hit"
del S
else
sleep(50)
del S
return
var/obj/Fireball/S

// var/obj/Fireball/S=new(src.loc)


My original:
mob
verb
Fireballskill()
var/obj/Fireball/S=new(src.loc)
S.dir = src.dir
walk(S,src.dir)

obj
Fireball
icon = 'fireball.dmi'
icon_state = "small"
Bump(mob/M)
if(ismob(M))
S = new(loc)
S.icon = 'fireball_hit.dmi'
src << "Hit"
del S
else
sleep(50)
del S
return
var/obj/Fireball/S


Kaioken's demo was frankly too complicated I couldn't figure out how to use it.

[EDIT]
After looking at the code i can see how that can be confusing...

var/tmp/list/trails[0]
//Creates a new list for holding all the trails

Move(l,d)
..()
//Moves the head of the trail

for(var/v in trails)step(v,d)
//Everything that's in the list of trails step in the head's direction

trails+=new/obj/trails(l)
//Add a new trail to the list

Del()
for(var/v in trails)del(v)
//Everything that's in the list of trails delete it

..()
//Delete the head
In response to Tubutas
eh? looks like that is from library but would still need library to use.

EDIT:
mob
verb
Fireballskill()
var/obj/Fireball/S=new(src.loc)
S.dir = src.dir
walk(S,src.dir)
obj
trails
icon = 'blood.dmi'
icon_state = "blood1"
obj
Fireball
icon = 'fireball.dmi'
icon_state = "small"
Bump(mob/M)
if(ismob(M))
S = new(loc)
S.icon = 'fireball_hit.dmi'
src << "Hit"
del S
else
sleep(50)
del S
return
Move(l,d)
..()
for(var/v in trails)step(v,d)
trails+=new/obj/trails(l)
Del()
for(var/v in trails)del(v)
..()
var/obj/Fireball/S


This is cool, but its kinda randomized, and the fireball appears behind everything usually. Im still confused and I would like to just make a trail behind my object with the direction im facing and delete it after a certain period of time. Then hopefully I can build off of it for other attacks.
obj
laser
var/list/trail = list()
Move()
trail += new /obj/lasertrail(loc, dir)
return ..()
Del()
for(var/obj/lasertrail/L in trail)
del(trail)
..()
lasertrail
New(loc, dir)
..()
src.dir = dir


<edit> Oops, was in a rush and forgot the New() for the lasertrail.
In response to Garthor
Ok, here is it for anybody else who wants to use or learn from it:

var/obj/laser/z
obj
laser
var/list/trail = list()
icon = '.dmi'
icon_state = ""
Move()
dir = src.dir
walk(src,src.dir)
trail += new /obj/lasertrail(loc, dir)
return ..()
Del()
for(var/obj/lasertrail/L in trail)
del(trail)
..()
lasertrail
icon = '.dmi'
icon_state = ""
mob
verb
splazor()
var/obj/laser/z=new(src.loc)
z.dir = src.dir
walk(z,src.dir)
In response to Darkjohn66
How do I use a for loop to delete an entire trail at once?
In response to Darkjohn66
for(var/v in trail) del(v)