ID:1514406
 
So, Projectiles confuse me.. I've looked at so many different ways to use them and i just dont understand them. So i just want someone to kind of explain what is going on in this projectile code and how i would implement it into a fire ball object.
Code:
projectile
parent_type = /obj
var
trail
damage = 0
owner
New(turf/t,owner,dir)
src.dir = dir
src.owner = owner
. = ..()
if(src.Move(t))
walk(src,dir)
Move()
var/atom/oldloc = src.loc
. = ..()
if(.)
src.Moved(oldloc)

proc/Moved(atom/oldloc)
if(src.trail&&oldloc)
new src.trail(oldloc)

Bump(atom/obstacle)
if(istype(obstacle,/mob/combatant))
var/mob/combatant/c = obstacle
c.TakeDamage(src.damage,src.owner)
del src


Problem description:

It begins by setting the projectiles direction to that direction of the person shooting it and stores a variable to say who that person shooting it is.
At the end it is saying if it hits (bumps) into something and if that something is a combatant then run a TakeDamage() process that is not in the example you give and it just passes the damage of the projectile(which from this code will always be 0) and who caused that damage (I guess so it can credit them with a kill if the damage inflicted results in the person being hit's death).
Okay thanks. So my next question then is how would i add this into the object?
FireBall
var
SAtk = 5
icon_state="blaze"
DblClick()
usr << "You used FireBall!"
In response to Linkin5622
You can either create a child type of /projectile:
projectile/fireball
// give it an icon
icon = 'whatever'
icon_state = "whatever"

// how much damage does it do
damage = 9001

// elsewhere
DblClick()
usr << "You used FireBall!"

// The constructor (New()) for /projectile/fireball
// expects an initial loc, the shooter, and the direction to move.
new /projectile/fireball (get_step(usr, usr.dir), usr, usr.dir)


Or you can just modify an instance of the base /projectile:
DblClick()
usr << "You used FireBall!"
var projectile/fireball = new (get_step(usr, usr.dir), usr, usr.dir)
fireball.icon = 'whatever'
fireball.icon_state = "whatever"
fireball.damage = 9001


I've also noticed that the /projectile type isn't dense. You'll need it to be dense for it to bump into things normally.
projectile
density = TRUE
This looks like one of my snippets.

I wouldn't recommend using projectile anywhere in a statpanel or on the HUD. I'd really recommend the object you doubleclick to use the projectile not being a projectile object itself, and using a generic skill use prototype.