ID:145179
 

mob
proc
shoot()
var/obj/H = new/obj/bullet
if(src.fired == 0)
src.fired = 1
spawn(15)
src.fired = 0
H.dir = src.dir
H.loc = src.loc
while(H)
step(H,H.dir)
var/turf/T = H.loc
if(T.density == 1)
del(H)
break
for(var/mob/M as mob in T)
if(M == src)
continue
src<< "you shot the enemy"
M.health -= 2
del(H)
sleep(1)
mob

The current code works in shotting the bullet but once fired it doesn't move. It just stays in one spot and doesn't get cut. Can you please help me fix the problem?
Thanks
Instead of using if(src.fired==0), make it if(!src.fired). You can also turn if(src.fired==1) into if(src.fired) if you wanted. Also, you might want to undent sleep(1) one tab.
In response to Aaiko
Aaiko wrote:
Instead of using if(src.fired==0), make it if(!src.fired). You can also turn if(src.fired==1) into if(src.fired) if you wanted. Also, you might want to undent sleep(1) one tab.



Thanks for the help! I changed what you said and I've been looking at demos to try to help me. Still cant figure out the problem. It dont want to move once i fire it. Im mostly new to this so I really appreciate the help
In response to Ryng35
You're not getting past if(src.fired==0) because fired is equal to something other than 0. If you put if(!src.fired) and it still did not work, then you have fired set to something other than 0 or nothing at all. Find where you declared fired, mob/var/fired or something like that, and make sure it is either equal to 0 or nothing at all. If it is equal to 0 or nothing, then somewhere else in your code you have fired being set to something, which is causing your problem.

In response to Aaiko
I set src.fired to nothing. I also went and checked at the mob/var/fired and it is equal to zero. I was thinking that maybe it's not working cuz I set up constant moving on the game to. Will that interfeer?
In response to Ryng35
mob
proc
shoot()
var/obj/H = new/obj/bullet
if(!src.fired)
src.fired = 0
spawn(15)
src.fired = 0
H.dir = src.dir
H.loc = src.loc
while(H)
step(H,H.dir)
var/turf/T = H.loc
if(T.density == 1)
del(H)
break
for(var/mob/M as mob in T)
if(M == src)
continue
src<< "you shot the enemy"
M.health -= 2
del(H)
sleep(1)

I still am not able to get the bullet to move forward. I appreciate all the help I can get. Thanks
In response to Ryng35
Could you all please use the <dm>CODE HERE<dm/> tags please. the code looks ugly otherwise.
In response to A.T.H.K
            if(!src.fired)
src.fired = 0
spawn(15)
src.fired = 0

this isnt your problem but right here your saying if src.fired = 0 make scr.fired = 0 then wait 1.5 seconds then make src.fired = 0.

+ your problem could be your using src.fired try usr.fired
In response to Flame500
No usr in proc....
Well, I will go the easy way and post a handgun example from my game.

obj/items
Handgun
icon='GUNS.dmi' //Change as you wish
icon_state="Handgun" //Change as you wish
var/ammo=30 //Of course ammo, power, and refire can be
var/power=10 //changed to make variations between weapons, like
var/refire=10 //SMGs, Rocket Launchers, etc.
verb
Handgun()
set category="Weps."
if(usr.KO==0 && usr.firing==0)
if(ammo>=1)
usr.firing=1
var/obj/A = new /obj/attack/bullet/
A.loc=locate(usr.x,usr.y,usr.z)
A.icon='Bullets.dmi' //Change as you want
A.icon_state="Bullet" //Change as you want
A.density=1
walk(A,usr.dir)
A.Pow=power
ammo-=1
spawn(refire)
usr.firing=0
else
usr << "<b>Out of ammo, reload."


And here is the projectile itself, which can be used and edited universally.

obj/attack/blast
var/Pow
Bump(mob/M)
if(istype(M,/mob))
var/dmg=Pow
M.HP-=dmg
if(M.HP<=0)
if(M.player==1)
view(6) << "<b><font size=2>[M] has died!"
M.Death()
del(src)

if(istype(M,/obj/attack)) //Deletes projectiles it collides with
del(M)
del(src)

if(istype(M,/turf)) //if its a rocket launcher or something,
//you might want it to destroy walls.
if(M.density==1)
new /turf/Dirt(locate(M.x,M.y,M.z))
del(src)
del(src)
You say the bullet doesnt move? Here is one of your problems: No movement proc to actually send it to the target...