ID:148219
 
Hey, me again. I searched through the forums, and found this code that I thought may fix the projectile problem I was having a while back. One question, how do I activate this?

obj/bullet
icon = 'bullet.dmi'
var/mob/owner

Bump(atom/A)
if(ismob(A))
var/mob/M=A
M.die(owner)
del(src)

New(newloc,mob/M)
owner=M
walk(src,owner.dir)
spawn(10)
del(src)

mob
proc/die(mob/killer)
if(killer)
world << "[killer] kills [src]!"
del(src)


Thats the code I found, and I need to know how to actually use this. Here is a gun I have made(I would like a person to be able to click on fire, then activate that above).

obj
Blade
icon = 'weapons.dmi'
icon_state = "blade"
verb
fire()
set desc = "Fire your weapon"
set category = "Commands"
if(usr.paint == 0)
usr << "Your hopper is empty, buy some paint!"
usr << 'handhit.wav'
else if(usr.air == 0)
usr << 'handhit.wav'
usr << "Your out of CO2, buy some more!"
else if(usr.fire == 1)
usr << 'handhit.wav'
usr << "You can't fire your weapon here."
else
view() << 'Clack.wav'
usr.paint -= 1
usr.air -= 0.1
When you want to fire the projectile, just create one. You'll notice that obj/bullet/New() is overidden to give it an extra argument; using that extra argument, the command to create a bullet becomes:

<code>new /obj/bullet(usr.loc, usr)</code>

The overidden New() proc will then set the direction of the bullet and move it.

Remember to replace usr with something more appropriate, if necesssary.
In response to Crispy
Woot, thanks! Now to redo my deathchecks :(
Thanks for the help Crispy, but this should be last few problems. When the I click fire and use that verb, the bullet shows up and even flies in the direction im facing. But when it gets to a solid object it doesn't stop or do anything.. just keeps on going? I am also trying to figure out how to make the bullets shoot from the guns faster/slower, how could I do this? And I am also trying to adjust the distance for different guns. How could I go about that, thanks for any suggestions.
In response to Oblivian
Oblivian wrote:
Thanks for the help Crispy, but this should be last few problems. When the I click fire and use that verb, the bullet shows up and even flies in the direction im facing. But when it gets to a solid object it doesn't stop or do anything.. just keeps on going?

Whoops... the bullet needs to be dense. =D

<code>obj/bullet density=1</code>

I am also trying to figure out how to make the bullets shoot from the guns faster/slower, how could I do this?

You'll need to put a delay on the fire verb. Look for some code that slows down player movement, and adjust that to be used in the fire verb.

And I am also trying to adjust the distance for different guns.

Best way to do this is probably to give New() a third argument, and modify Move()...

obj/bullet
var/range

<code> New(newloc, mob/M, maxdist=5) owner=M range=maxdist walk(src,owner.dir) spawn(10) del(src) Move() .=..() //Do normal movement if (.) //If movement was successful range-- //Reduce range if (range<=0) del src //If bullet has moved maximum number of times, delete it</code>

Then pass in the gun's range to new() as the third argument.
In response to Crispy
Alright thanks for all the help Crispy! I was thinking the bullet might need to be dense, but never got a chance and forgot to try it :). Anyways thanks alot :).