ID:271490
 
Code:


Problem description:

My current system creats massive bugs whenever a bullet is shot into the water, I pretty much know why but cnat seem to make one of my own
Well first off you need to make an obj for the bullet, and when it's created have it walk in the shooters direction. Inside of the object you need a Bump() which will check to see if the thing it hit is a mob or whatever and then do damage or whatever you want it to do. Also you will want to set a spawn() in New() so the object is deleted after a certain amount of steps, of even better yet make it delete after a certain amount of steps.

To make it go in your direction do:
var/obj/O = new/obj/bullet(src.loc)//Creates a bullet where src is standing
O.dir = src.dir
walk(O,src.dir)


Also for future reference... This should go in Developer How-To not Code Problems.
In response to Dession
Thanks for the trouble but I got that down, what i really need is a way for it to auto-delete when it hits a turf with an Etner proc
In response to Lt. Pain
Have the Enter() see what is entering and if it's a bullet then delete it. =P
In response to Dession
yea i did that to (again im not stupid) but it still seems not to work XD i think it is becaause the bullets info about what happens when it hits something is in a proc and not he obj itself
In response to Lt. Pain
You COULD do something like this...
obj
bullet
Move()
for(var/turf/T in src.loc)
if(istype(T,/turf/water))
del(src)
else
..()
I think that is what it should be. I haven't coded in about a month, so I am abit rusty.
There are quite a few things you could do here.
But since this isn't just a shooting system in general, I'll just narrow down the possibilities down to a few.

1. You could do what the other people in the thread told you to do. You have bullets that can only travel orthogonally, meaning that you'll have to line yourself up to shoot at your target. These bullets are usually pretty slow, meaning players might be able dodge them, and are usually pretty ugly.

2. You could use bullets with pixel based movement. This potentially lets you make bullets much faster and allows bullets to travel in any angle, meaning that you don't have to be lined up with your target to hit them with a bullet. This is much more realistic, but it's known to create quite a bit of lag if the bullets are too slow and/or the bullets are done inefficiently. Shadowdarke has a good pixel projectiles library for this. IIRC, JtGibson has a vectors library that could be used for this. This typically requires trigonometry to code yourself, but if you're good with geometry, you might be able to do it.

3. You could use line based projectiles. This is pretty much the same thing as #2, but it's much much faster and usually doesn't have any graphics. In this case, bullets are invisible and are near instantaneous. Some simple geometry with line-intercept form can do this. I know that DarkCampainger has made a thread about this in the past... I'll post a link to the thread later.
Here is an example of what im uing

obj/Guns/Duel_Pistols
name="Duel_Pistols"
no_pack=1
icon = 'guns.dmi'
icon_state = "Duel pistols"
var/ammo=0
var/equiped=0
verb
Get()
set src in oview(1)
src.loc=usr
Drop()
if(src.equiped==0)
src.loc=usr.loc
else
return
HUB_UP()
new/obj/hudMeters/Pistol_Hub(usr.client)

mob
proc
shoot() //name of proc
var/obj/H = new/obj/bullet //set the bullet to H (H is the bullet)
if(src.fired == 0) //if the usred fired is 0 (keeps the usr from holding down 5 for lots of shots)
src.fired = 1 //makes fired equal 1
spawn(5) //waits 1 seconds before going to the code underneath it
src.fired = 0 //makes the player's fired 0 so the player can shoot again
H.dir = src.dir //the bullets(H) direction equals the player's direction
H.loc = src.loc //the bullets(H) location equals the player's location
while(H) //while the bullet is still "alive"
step(H,H.dir) //H steps towards H's direction
var/turf/T = H.loc //for the turf that is in H's location
if(T.density == 1) //if that turfs density = 1 (ex: a wall)
del(H) //deletes the bullet
break //breaks out of the while loop
for(var/mob/M as mob in T) //for and M in that turf
if(M == src) //if that M is the person who fired, it continues as if nothing was there
continue
src<<"You shot [M]!" //says you shot M
M.health-=25
M.Death()
//Here is where you would want to add damage or such ect..
del(H) //deletes the bullet
sleep(1) //sleeps 1/10th of second before re-doing the loop
else
return
obj/bullet //the bullet
name="bullet"
icon = 'guns.dmi'
icon_state = "bullet"
New()
..()
spawn(10)
del(src)


That is the code that I'm useing, so is he problem in the fact that all the bullet info is deffined in the proc? And if anyone has a simpler system please post it, I dont need a state of the art shooting sysem, just something simple that I can adjust to my games needs.

Thanks in advance