ID:175331
 
I'm trying to make a laser beam in my game...which is 15 turfs long, it's going to stay for about .3 sec. The beam should be facing in the usr's direction. I tried making 15 obj's but that dosnt work. Does anyone have an idea on how I could do this? Thank you.
What doesnt work about making 15 object's?
In response to DarkView
Well here is my code...It definetly dosnt work. So, does anyone have any suggestions?


if(usr.rightarm == "Rail Gun")
if(usr.currentammo <= 0)
usr<<"You have to reload!"
else
var/obj/pistol1 = new/obj/shot/Rail_Gun(src.dir+1)
var/obj/pistol2= new/obj/shot/Rail_Gun(src.dir+2)
var/obj/pistol3 = new/obj/shot/Rail_Gun(src.dir+3)
var/obj/pistol4 = new/obj/shot/Rail_Gun(src.dir+4)
var/obj/pistol5 = new/obj/shot/Rail_Gun(src.dir+5)
var/obj/pistol6 = new/obj/shot/Rail_Gun(src.dir+6)
var/obj/pistol7 = new/obj/shot/Rail_Gun(src.dir+7)
var/obj/pistol8 = new/obj/shot/Rail_Gun(src.dir+8)
var/obj/pistol9 = new/obj/shot/Rail_Gun(src.dir+9)
var/obj/pistol10 = new/obj/shot/Rail_Gun(src.dir+10)
var/obj/pistol11 = new/obj/shot/Rail_Gun(src.dir+11)
var/obj/pistol12 = new/obj/shot/Rail_Gun(src.dir+12)
var/obj/pistol13 = new/obj/shot/Rail_Gun(src.dir+13)
var/obj/pistol14 = new/obj/shot/Rail_Gun(src.dir+14)
var/obj/pistol15 = new/obj/shot/Rail_Gun(src.dir+15)
sleep(15)
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
del pistol
usr.currentammo -= 1


In response to SSChicken
Try this out:
obj
shot
Rail_Gun
Move()
var/obj/O=new/obj/shot/Rail_Gun
O.loc=src.loc
New()
..()
walk(src,src.dir)

Hope that helps ya out.
In response to SSChicken
Ok. The basic problem is that your src.dir+'s arent valid locations. Just off the top of my head too fix it you could do something like this.
var/pistol1 = new /Rail_Gun (get_step(src.loc, src.dir))var/pistol2 = new /Rail_Gun (get_step(pistol1, src.dir))var/pistol3 = new /Rail_Gun (get_step(pistol2, src.dir))

That code wont work since Ive wrote a shortened version. Basically what you need to pay attention too is the () at the end of the new.
src.dir+number isnt a location, its a number. get_step(val1, val2) will return the location one step over in val2 direction from val1.
In response to DarkView
Ok, what you told me to do works, thank you very much. Now my only problem is when the player is facing East or West the graphics come out wrong. Instead of coming out in a straight line ------------- they come out like this ||||||.
What can I do to change that?
In response to SSChicken
By making pistolX.dir = src.dir. That will make it so that it faces the same direction the player is.
In response to DarkView
How would I insert that into

var/obj/pistol1 = new/obj/shot/Rail_Gun(get_step(src.loc, src.dir))

I tried many different ways, but they all give me errors.
Do I have to make a seperate line for that?

By the way, thank you for all the help you have given me.

In response to DarkView
Ok. The way your doing it now works, but its not too great, and since Im bored (And a nice guy too boot ;P) Im going to walk you through a much better way of making it work.
First, we need to do something about having so many variables. When your dealing with that many variables its best to replace them all with a handy list.
var/list/bullets[0]
Now too show you how too use the list. We are going too need too figure out an easier way too create them and add them to the list.
Just quickly, lists are variables that store multiple variables. You can access the variables simply by knowing what position they hold in the list.
For example, if I wanted to put something in the 3rd spot in the list, I would just put listname[3] = something.
A while will work rather well for this. However first we have to declare a variable so the while can keep track of how many loops its done, and what position in the list we need to place the object.
var/i = 0
while(i < 15)
i += 1
bullets[i] = new /obj/shot/Rail_Gun ()

Well this works, but it has a problem. It hasnt added the bullets too the screen. This is where it gets a little tricky because we have two positions to place bullets at. The first one, next too the player, and the others just go next to the last one.
We'll do this the simple way, by making the first one outside the loop, and making the loop make 14 bullets instead of 15.
So now it should look something like this.
var/i = 1
bullets[i] = new /obj/shot/Rail_Gun (get_step(src, src.dir))
while(i < 15)
i += 1
bullets[i] = new /obj/shot/Rail_Gun ()

Now here is another problem, how do we make it so that the bullets being made by the loop show up next too the last bullet made like they used to?
Simple, its almost exactly the same but where you used to put get_step(varname, src.dir), you now put get_step(bullets[i - 1], src.dir)
That will make it so that it places the new object one step in src's direction away from bullets[i - 1] (Aka, the last bullet made).
Now deleting them is simple if you use the for() proc. for() basically goes through every item in a list. All you have too tell it is what type of variables are in the list, and what the list is. And dont forget the in part.
So you want too add a:
for(var/obj/shot/Rail_Gun/O in bullets)
del(O)
That will go through all the obj/shot/Rail_Gun's in the list and delete them.
So by now the code should look much more compact, and hopefully you have a understanding of lists and the while() proc.
if(usr.rightarm == "Rail Gun")
if(usr.currentammo <= 0)
usr<<"You have to reload!"
else
var/list/bullets[0]
var/i = 1
bullets[i] = new /obj/shot/Rail_Gun (get_step(src, src.dir))
while(i < 15)
i += 1
bullets[i] = new /obj/shot/Rail_Gun (get_step(bullets[i - 1]), src.dir)
sleep(15)
for(var/obj/shot/Rail_Gun/O in bullets)
del(O)
usr.currentammo -= 1
In response to SSChicken
Oh sorry. I didnt explain that clearly. You just have to put it underneat every var/obj/pistol1.
In response to Goku72
Also, if you don't want it to be 15 tiles long, just make it 1 tiled and use the walk away() and have it del src when it hits something using the bump()

:-)

~STARWARSPOWER~
In response to DarkView
Doh. I forgot too add one thing. The direction adjuster.
Its a simple thing. What you want too do is add a bullets[i]:dir = src.dir on the line under bullet[i] = new ect...
So it will look like this.
var/i = 1
bullets[i] = new /obj/shot/Rail_Gun (get_step(src, src.dir))
while(i < 15)
i += 1
bullets[i] = new /obj/shot/Rail_Gun (get_step(bullets[i - 1], src.dir))
bullets[i]:dir = src.dir
In response to DarkView
Whow, thank you very much for that detailed explanation! It sure tought me how to make and use lists. Now after examining what you tought me I used it. Almost everything works. Now...I get one run time error:

runtime error: list index out of bounds
proc name: Shoot (/mob/PC/verb/Shoot)
usr: (/mob/PC)
src: (/mob/PC)
call stack:
(/mob/PC): Shoot()

I tried playing around with the list...nothing worked. The actuall beam appears, but I do get that error. Next...The dir controler gives me a compile error.

Weapons.dm:814:error: :: expected end of statemen

I looked in my Blue Book to fix it but the only thing on ":" was the "lax" difference. I also looked through the list chapter and it had nothing on ":"

Once again thank you, I really appreaciate your help.
In response to SSChicken
Doh. I always end up with this error. Just give me a minute.

...


*Minute Later*

Ok, for the direction controller, well go with a simple solution. What we want too do is make a var too hold the object for a second while we create it and set it up (Well call it O). That way we can set it up, then add it too the list.
So what we will do is:
var/obj/O = new /obj/shot/Rail_Gun ()
O.dir = src.dir
bullets[i] = O

That should fix the compile error. Now for the rutime error.
Ahhhh, I see. What I forgot was that we needed too make the list start off with 15 spaces in it. So look where we put bullets[0], and replace that with bullets[15].
Usuaully you dont have to worry about setting the size of the list, but since we are using the index too put values into the list (Rather then Add()) we have too.
In response to DarkView
Ok thank you very much, it worked...I can go to sleep...goodnight.