ID:144411
 
Code:
obj/bullet//    the bullet
icon = 'bullet.dmi'
var/owner = null
var/delay = 1 // Delay, bigger slower MUSTBE above 0
var/dmg = 1// I like realism so look below
New()
src.dmg = rand(1,5)
..()
spawn(rand(10,20))// Making sure its realistic =D
if(src)
del src
Bump(atom/A)
..()
if(ismob(A))
var/mob/Mobhit = A
var/mob/Owner = src.owner
if(Mobhit == Owner)
return// No shooting ya self!
else
Mobhit.health -= src.dmg
if(Mobhit.health <= 0)
Mobhit.deathcheck()
else if(istype(A,/obj/bullet/))// if it hits amother bullet
src.loc = A.loc// Keeps it going :D
else if(A.density == 1)// otherwise
del src


mob/verb/shoot()
shoot1()

mob/proc/shoot1()
var/obj/bullet/O = new/obj/bullet(src.loc)
O.owner = src.ckey
walk(O,src.dir,O.delay)// make it move


Problem description:
I am attempting shooting right? ANd this code makes the bullet and everything but it flys over walls (dense turfs)

Anyone know hoe to make it work Because Its very annoying. especisally since I had made this for the combat part of the game =/
spawn requires an indent.
In response to Xx Dark Wizard xX
No it doesnt....

if it did it wouldn come up and say
shooting me.dm:9:error: proc definition not allowed inside another proc
In response to Lyndonarmitage1
Yes it does! If you fail to believe me search for spawn in the refrence or the guide.
In response to Xx Dark Wizard xX
AH yes, but it did work without, still that didnt help the main problem of the bullet going through my walls!
In response to Lyndonarmitage1
Lyndonarmitage1 wrote:
AH yes, but it did work without, still that didnt help the main problem of the bullet going through my walls!

There are quite a few problems or incorrectly-styled coding in your code. I'll try to get my lazy ass off and detail them all:

---Not really a problem, but apparently you have the bullet icon in it's own .dmi file. You usually shouldn't do this; .dmi files can hold multiple icons each for a reason, use multiple icons in a single .dmi file with the icon_state variable - your game directory would get cluttered with tons of .dmi's otherwise. Of course, I can't know - maybe you only have the bullet icon in a separate file.
Also, for some weird reason, all your comments begin with a tab or some whitespace... you obviously don't need to, text preceding the // in the same line is ignored by the compiler...

---var/owner = null 1) You don't need to initialize variables to null; by default they're already null, so removing the "= null" will still have the same effect.
2) Since the var is supposed to hold a reference to a mob, typecast it as of type /mob. This also saves you the really weird unneeded act of copying owner to a new [typecasted] var.
So, correctly doing it would be: var/mob/owner

---If you reset a variable in New(), don't initialize it (I'm talking about 'dmg' var), as it is useless.

---Like Dark Wizard said, spawn() needs an idented block attached to it. It don't think it should even compile without it. Look it up in the DM Reference (press F1 in DreamMaker), it isn't used to "spawn"/create objects, it's used to delay execution of code in a separate call stack, similarly to sleep() (that delays the existing call).

---Calling ..() in a proc calls the parent/default action - it won't even always have an effect. Anyway, you generally probably want to call it either in the start or the end of the overridation, not somewhere in the middle like you have, even tho it works (though there are uses for that, but I cant see any in your case).

---You're using if(src) del src. Checking if src is true is useless; if it wasn't, the proc would have stopped anyway, so reduce that to del src. Now, you're deleting the created object (src) in New(), right after it's created...not very useful, huh?

---Check if Mobhit == src.owner before you type cast A, so that won't be done for waste if the condition is true.

---There is no need to use an else statement if in the respective if() you used calls return. Returning stops the current proc anyway; so an else is obsolete.

---This block of code is one of the weirdests I've encountered so far:
                Mobhit.health -= src.dmg
if(Mobhit.health <= 0)
Mobhit.deathcheck()

Right, so you only call deathcheck() after you check if the health is gone. Then what exactly are you checking in deathcheck()? You should call deathcheck() regardless of the health, and in that proc itself, check if its <= 0.
Also, when setting the health, you would probably prefer using Mobhit.health = max(0,Mobhit.health-dmg) instead - look up the max() proc. This way will ensure the health won't drop below 0 (though to make robust code, when checking the health, you should still use health <= 0 and not the ! or = operators.

---
else if(istype(A,/obj/bullet/))//   if it hits amother bullet
src.loc = A.loc// Keeps it going :D (**force is to keep going)

This will work, but it's not a good method. You see, setting the 'loc' var manually shouldn't ever be done - it's like forcing a teleportation/movement - it isn't using the movement system. Sure, you may think, ("but the movement system was run - it failed because the other bullet was there, so just imagine it wasn't there and it would continued anyway, it doesn't matter"), but if the bullet wasn't there, something ELSE could've stopped the movement; it may also of been a movement-system-proc (Move(),Enter()...) override - you never know. So to make the code more robust, you should use the movement system there.
But wait, if we use Move(), it would just fail again and call Bump() again, right? Yep. You need to override the Enter() proc for turfs - the movement system uses it to determine whether to allow movement. It's default behaviour is to stop movement if there is already a dense (density=1) object in the location. Here is a code sample:
turf/Enter(atom/movable/O) //'O' is an /atom/movable attempting to enter the turf, which is 'src'
if(!O.density || !istype(O,/obj/bullet)) return ..() //if the object attempting to enter ISN'T a bullet OR it isn't dense, do the default behaviour
if(src.density) return 0 //if the turf itself is dense, disallow movement
for(var/atom/movable/A in src) //mimic some of the default behaviour of Enter(), but ignore bullets
if(A.density && !istype(A,/obj/bullet)) return 0 //if there is a dense object on the turf BUT it isn't a bullet, return 0 to disallow movement
return 1 //allow movement

That should do it. Maybe there is a better way to do this, though I'll that for the others, I'm too tired|lazy now and this should work.

---
        else if(A.density == 1)//    otherwise
del src

Rather, just use a boolean check and use if(A.density) instead. Read here: http://bwicki.byond.com/ByondBwicki.dmb?TrueFalse
Also, doing the check at all is useless; if Bump() was called, it obviously means the argument, the obstacle, is dense...otherwise it wouldn't exatcly be an obstacle huh? (and Bump() wouldn't get called).

---You're calling the parent proc/default behaviour in obj/bullet/Bump(). You probably don't want this (even if it currently does nothing bad), so remove it.

---You didn't define the /obj/bullet prototype's density=1 up top, so it just goes threw everything and never calls Bump(). :P

---
var/obj/bullet/O = new/obj/bullet(src.loc)

A handy DM shortcut: if the assigned variable is typecasted, you don't need to type the type twice and can omit it, like this:
var/obj/bullet/O = new(src.loc)


---You will probably want to set the 'bullet.owner' var to an actual reference of the mob owner; not just the ckey. That way you can access and manipulate the owner from that var; for example, to add to the mob's 'kills' var, use: bullet.owner.kills++. You can still access the 'ckey' var if you want to, of course, by accessing bullet.owner.ckey.




...phew...[no offense] so many problems in a small code block....keh...make sure to learn from those mistakes...*crawls on ground*...water! water!