ID:1191244
 
(See the best response by Kitsueki.)
Code:

obj
Gokakyuu
icon = '(Katon) Gokakyu No Jutsu.dmi'
pixel_x = -32
pixel_y = -32
density = 0
Bump(A)

if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)
Move()
for(var/mob/M in src.loc)
if(M.counter)
del(src)
return
if(M.PK==0)
return
var/damage = round(src.nin*3)
if(damage >= 1)
M.health -= damage
view(M) << "[M] was hit by Gokakyu No Jutsu for [damage] damage!!"
var/mob/O = src.Gowner
M.Death(O)
..()


Problem description:
Just having difficulties making it pierce through a mob. On this code I kinda hit myself first before it goes toward the intended direction.

Hence, if anyone is familiar with piercing beams teach me pls :(

Well, what is the first thing that happens when the projectile tries to move?
It hits my character, then goes forward and hit other mobs.
Give it some density. So it can actually "Bump". You have density set to 0 for some reason...
In response to Mitz001
Mitz001 wrote:
It hits my character, then goes forward and hit other mobs.

You are right, but I was looking for a more specific answer. The first thing that happens is for(var/mob/M in src.loc) ... the program loops through all mobs in the projectile's location. So, when it is created on the same square as the player, as soon as Move() gets called the player will be hit.

I'm thinking of two solutions to this:

       Move()

..()

for(var/mob/M in src.loc)
if(M.counter)
del(src)
return
if(M.PK==0)
return
var/damage = round(src.nin*3)
if(damage >= 1)
M.health -= damage
view(M) << "[M] was hit by Gokakyu No Jutsu for [damage] damage!!"
var/mob/O = src.Gowner
M.Death(O)


Above, the parent proc will be called first, and the projectile will move. Then it will check for mobs to hit.

Here's a problem though: Are there any other instances in which the player could be hit by their own projectile? Perhaps you would answer "no" at the moment, but what about the future? If you wanted to give players the ability to teleport, or to reflect projectiles back at someone, or to have bouncing projectiles, then there could be times when the players shoot themselves. Unless you want this behavior, it is a good idea to avoid the possibility by always ignoring the mob who shot the projectile:


obj/Gokakyuu

var/mob/owner

Move()
for(var/mob/M in src.loc)
if(M != owner)

if(M.counter)
del(src)
return
if(M.PK==0)
return
var/damage = round(src.nin*3)
if(damage >= 1)
M.health -= damage
view(M) << "[M] was hit by Gokakyu No Jutsu for [damage] damage!!"
var/mob/O = src.Gowner
M.Death(O)
..()

For this to work you have to set the owner var to the mob who is shooting. You could achieve a similar thing by having a "team" variable - like team = 1 for players and team = 0 for ai enemys. In this case you would also give the projectiles a team variable to compare with.

Davin Naruto?
obj
Gokakyuu
icon = '(Katon) Gokakyu No Jutsu.dmi'
pixel_x = -32
pixel_y = -32
density = 1 //Density needs to be 1 to bump
Bump(A)
if(istype(A,/mob/)) //Checks to see if it is bumping a Mob
loc=A.loc //If it is a mob, then it goes through(peirces) it
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)
Move()
for(var/mob/M in src.loc)
if(GOwner==M) return //This stops it from hitting yourself
if(M.counter)
del(src)
return
if(M.PK==0)
return
var/damage = round(src.nin*3)
if(damage >= 1)
M.health -= damage
view(M) << "[M] was hit by Gokakyu No Jutsu for [damage] damage!!"
var/mob/O = src.Gowner
M.Death(O)
..()


There just add those few lines of code and now your attack will pierce through players and not damage you. Also keep it's Density at 1 as I just did, otherwise it won't be able to bump into dense atoms. If ya need me to explain it more or want more help just reply.
obj
Gokakyuu
icon = '(Katon) Gokakyu No Jutsu.dmi'
pixel_x = -32
pixel_y = -32
density = 1 //Density needs to be 1 to bump
Bump(A)
if(istype(A,/mob/))//Checks to see if it is bumping a Mob
var/mob/M = A
loc=A.loc //If it is a mob, then it goes through(peirces) it
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)
Move()
for(var/mob/M in src.loc)
if(Gowner==M) return //This stops it from hitting yourself
if(M.counter)
del(src)
return
if(M.PK==0)
return
var/damage = round(src.nin*3)
if(damage >= 1)
M.health -= damage
view(M) << "[M] was hit by Gokakyu No Jutsu for [damage] damage!!"
var/mob/O = src.Gowner
M.Death(O)
..()


The code indentation seems fine, but it keeps saying indentation errors. hmm I didnt get a chance to test it yet
Code copied from the forums will not have tabs in it, instead it will have spaces. Try highlighting the emtpy space before lines and you will see what I mean. You can also press ctrl + T to show tabs
Tyvm~
obj
Gokakyuu
icon = '(Katon) Gokakyu No Jutsu.dmi'
pixel_x = -32
pixel_y = -32
density = 1 //Density needs to be 1 to bump
Bump(A)
if(ismob(A)) //Checks to see if it is bumping a Mob
var/mob/M = A
loc=A.loc //If it is a mob, then it goes through(peirces) it
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)

Move()
for(var/mob/M in src.loc)
if(Gowner==M) return //This stops it from hitting yourself
if(M.counter)
del(src)
return
if(M.PK==0)
return
var/damage = round(src.nin*3)
if(damage >= 1)
M.health -= damage
view(M) << "[M] was hit by Gokakyu No Jutsu for [damage] damage!!"
var/mob/O = src.Gowner
M.Death(O)
..()


Problem Description
03 - Katon Style.dm:197:error: A.loc: undefined var
03 - Katon Style.dm:196:warning: M: variable defined but not used


Almost... I cant figure a way to define the A.loc.. I've tried var/mob/M = A . Hmm~
You are on the right track...but re-read the second compiler notice that you got. M is defined but not used...
Oh sorry I did a quick help, before the line, "if(Gowner..." put
if(!M) return
That way it stops if there isn't a mob to check for. And you defined the mob as M not A, so replace A.loc with M.loc. actually do be more precise add the locate() proc to that line. So it'd look like:
src.loc=locate(M.loc)
Though if that causes an error go back to loc=M.loc so you can atleast get it running and test it. And your welcome for the help man!
Yup that might work as well.. then I figured to use loc=A:loc
and replaced loc=A.loc and it worked~
thank you vm~
Best response
That's because A is not defined as the type of object that has a loc variable.

Bump(atom/A)


only atoms have loc, and the compiler isn't expecting A to be an atom by default, you have to define it that way, otherwise it's going to assume you're accessing a non-existant variable.