ID:164280
 
I need a code for an arrow, one tile firing directly from the users icon and continuing until it makes contact with a mob or obj. If it hits the obj then it gets deleted and if it hits a mob the mob losses HP. Also a system that wont allow arrow spamming.

thx for any help

-Medawolf
Let's take these one at a time:

I need a code for an arrow

obj/arrow
density = 1
icon = 'arrow.dmi'


one tile firing directly from the users icon

I'm going to assume that you mean that you want an arrow, when you do whatever it is that triggers the firing of one, to appear one tile in front of whoever fired it. We'll accomplish this using the arrow's New() proc, passing the argument of whoever fired it.

obj/arrow
var/atom/owner //the owner could be a mob, but it could also be a trap (for example)
New(var/atom/A)
//set the owner
owner = A
//place the arrow one step in front of A
loc = get_step(A, A.dir)
//set direction to be the same as A's direction
dir = A.dir


and continuing until it makes contact with a mob or obj.

You're making a mistake, here: the arrow might not ever make contact with a mob or obj. It might hit a turf or, even worse, might fly into the edge of the map. So, instead, let's reword this as "continuing until it can't move." So, we'll write a proc that makes the arrow fly forward continually

obj/arrow
var/speed = 1 //number of ticks between moves
var/damage = 1 //damage this arrow does
proc/fly()
//continually loop a step in our direction
while(step(src,dir))
//the body of the loop is just a sleep() statement, because the stepping has already occurred
sleep(speed)


If it hits the obj then it gets deleted and if it hits a mob the mob losses HP.

You've made another mistake here. First of all, saying "the" instead of "a/an". There is no "the obj" or "the mob," we're talking about a mob or an obj. Or, in fact, anything else. Or, in fact, doesn't actually BUMP into anything at all, but merely fails a movement (like my example of flying into the edge of the map). Anyway, once we fail a movement in the fly() proc, we can check for something we might've hit, and if there's anything there we can damage, we can damage it. Then, we can delete the arrow. So, extending the fly() proc...

  //get the turf in front of us
var/turf/T = get_step(src,dir)
//make sure there is one
if(T)
//find a mob there for us to hurt
var/mob/M = locate(/mob/) in T
//if we found one
if(M)
//hurt the mob, crediting the damage to whoever our owner is
M.hurt(damage, owner)
//and now, with our job done, we'll delete ourselves
del(src)


Also a system that wont allow arrow spamming.

This is done in pretty much the exact same way that you can restrict movement speed. Just search for that.
In response to Garthor
that does not seem to be workin...

what i need is a code that will give the character a verb called "shoot" or w/e and then fires a arrow from directly in front of the user and then if it hits a mob that mob looses 5 HP. I am fairly new to creating byond games so I'm sorry for any incompetence I may be displaying in failing to understand.

dream maker keeps telling me that theres 12 errors in your code but its more likely me screwing it up.

any help would be great.

-Medawolf

Edit: I've managed to fire the arrow, but i cant set it to inflict any dmg, nor can i make them del themselves...
In response to Medawolf
The code you gave me is giving me an error...

error: missing left-hand argument to <.



so... any help plz
In response to Medawolf
He was giving you what you asked for, just not the way you want it (which would be a copy/paste/modify type of code).
In response to Medawolf
obj/Arrow 
icon = 'Weapons.dmi'
icon_state = "Arrow"

mob
verb/Shoot()
shoot()

mob
proc
shoot()
var/obj/H = new/obj/Arrow
if(src.fired == 0)
src.fired = 1
spawn(1)
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 [M]!"
M.attacked = 1
M.Health -= usr.Strength-M.Defense+rand(0,5)
M.Deathcheck()
usr.Levelup()
HP_MP_CHECK()
del(H)
sleep(1)

This is a pretty good shooting code and It works pretty well.Its the shooting demo I gave you but apparently you didnt look at it.....all you really had to do was modify it to fit your own code
In response to Monkeykid0049
That's horrible.

- No boolean usage where appropriate

- If the variable is reset after 1 tick, really no point for having it in

- M.attack is useless because you set it to a value but never used it.

- Using usr in procs.
In response to GhostAnime
Well it still works despite all the things you said but oh well....
In response to Monkeykid0049
It "still works" in the situations which you have tested it in. If you were to use it in a somewhat different way (say, create an arrow trap that shoots arrows), it wouldn't work.
In response to GhostAnime
Actually, that was a small mistake on my part. I forgot the closing tab.

The bigger mistake was the code in my post, because he clearly blindly copy-and-pasted it.
In response to Garthor
Unfortunetly its true T_T
In response to Garthor
And since there's no "Shoot" verb calling the procs, they are completely useless! :)
In response to Monkeykid0049
another nooby question:

how do i go about creating a var for attacked and fired based on the code givin by monkeykid?

i am very new to this(started yesterday) and i'm getting the following errors...

error:src.fired:undefined var
error:M.attacked:undefined var

thx for any help...
In response to Medawolf
How about you actually make the variable? /mob/var/attacking and /mob/var/fired would work.
In response to Kaiochao2536
Kaiochao2536 wrote:
How about you actually make the variable? /mob/var/attacking and /mob/var/fired would work.

tried that, don't work.
In response to Medawolf
fixed it, thx monkey =D
In response to Kaiochao2536
I'm not about to give him everything, he'll learn absolutely nothing that way.

Case in point: Monkey giving him everything he needed, and he learned nothing.

Thanks for that, Monkey.
In response to Garthor
Well its not even my code it's from a demo and also some people learn from examples but I dunno....I'm just trying to help him and I know you're gonna say "How is he going to learn anything if you just give him all the answers?" well like I said, some people learn from examples.
In response to Monkeykid0049
Some people learn from examples. A nice little statement that is technically correct and sounds reasonable. The trouble comes when you realize that "some" could be, you know, two. Two people learn from examples.

However, when you actually MAKE PEOPLE LEARN THINGS, they learn things. When you spoon-feed them what they want, they'll tend to copy it and learn nothing.

Stop helping people until you get a clue.
Page: 1 2