ID:149076
 
I redifined the missile's range, but it keeps going, even after the range ends.
mob/verb/fire()
if(usr.AmmoCheck()) return
else
fireprojectile(/obj/projectile/arrow,src)
usr.Ammunition -= 1
usr.Experience += 1

mob/verb/LAW()
if(usr.LAWCheck()) return
else
fireprojectile(/obj/projectile/law,src)
usr.LAWs -= 1
usr.Experience += 1

mob/verb/Shotgun()
if(usr.ShellCheck()) return
else
fireprojectile(/obj/projectile/Shotgun,src)
usr.ShotgunShells -= 1
usr.Experience += 1

mob/verb/GrenadeToss()
set desc = "Used to begin duels or fighting retreats."
if(usr.Nade()) return
else
fireprojectile(/obj/projectile/nade,src)
usr.Grenades -= 1
usr.Experience += 1





proc
fireprojectile(Type, mob/Who)
/*
Type = the type of projectile
Who = who fired/threw the projectile
*/
var/obj/projectile/S = new Type(Who.loc) // make a new projectile where the mob is
if(!istype(S,/obj/projectile)) // make sure they are
world.log << "Invalid projectile:[Type]"
return
S.dir = Who.dir // projectile faces same dir as the mob
S.who = Who
S.missileloop()



obj
projectile
density = 1
layer = FLY_LAYER
var
mob/who // the mob that fires the projectile
damage = 1 // how much damage the projectile causes
mrange = 10 // how far the projectile can go
delay = 1 // number of ticks between movements


proc
missileloop()
walk(src,dir, 0) // T = space the
if(--mrange > 0) // decriment range
spawn(delay) missileloop()
else
endmissile()

endmissile()
/* This proc is called when the missile stops moving.
Override it for missiles that have special effects
like explosions or leaving items where they land.
*/
del(src)

Bump(O)
if(ismob(O))
//do your damage routine here
O:HP -= damage
O:DeathCheck()
endmissile() // we hit something, so the missile stops



arrow
icon = 'bullet.dmi'
delay = 0

law
icon = 'law.dmi'
mrange = 5
delay = 2
damage = 100

Shotgun
icon = 'shotgunshell.dmi'
mrange = 6
delay = 2
damage = 50


nade
icon = 'grenade.dmi'
mrange = 3
delay = 5
damage = 100
You are mixing and matching techniques. My projectile snippet, which seems to be the source of most of that, does not use walk(). The walk() method Spuzzum put in the FAQ spawn()s a del() to remove it after a certain number of ticks.
In response to Shadowdarke
Shadowdarke wrote:
You are mixing and matching techniques. My projectile snippet, which seems to be the source of most of that, does not use walk(). The walk() method Spuzzum put in the FAQ spawn()s a del() to remove it after a certain number of ticks.

So, um, how would you make it that some bullets have shorter range than others?
In response to Drafonis
It really depends on how many tiles the object moves in one tick. This snippet might help you out some:

obj
var
tickdelete

bullet
short
tickdelete = 4//now /obj/bullet/short has a small tick delete var

long
tickdelete = 9//and this one has a long one

New()//when an object of this type is created
spawn(tickdelete*10)//4*10 = 40 && 40 = 4 ticks which is why I added *10
del(src)//remove it once its tickdelete var expires


You can probably add a code that allows you to fire the obj in a certain direction but remember you HAVE to use new() to create it or New() will never be called and the delete part will never be reached. I hope this put you on the right path, good luck.