ID:262536
 
Code:
    pistol
icon_state = "pistol"
aboutthingy = "A standard 9mm pistol."
var/fuel = 8
Harm(var/mob/Q)
if(Q in view(1))
sleep(20)
var/shot = (rand(1,4))
if(shot == 1)
view(8,Q)<<"<b>[usr] tried to pistol whip but [Q] dodged the attack!"
var/lol = Q:loc
for(var/mob/M in lol)
M:hp -= 0
M:Health()
if(shot > 1)
view(8,Q)<<"<b><font color = red>[usr] has pistol whipped [Q]!"
var/lol = Q:loc
for(var/mob/M in lol)
M:hp -= 25
M:Health()

if(Q in view (2))
if(fuel > 0)
var/shot = (rand(1,3))
if(shot == 1)
fuel --
view(8,Q)<<"<b>[usr] shot [Q] with [src] but missed!"
var/lol = Q:loc
for(var/mob/M in lol)
M:hp -= 0
M:Health()
sleep(30)
if(shot > 1)
fuel --
view(8,Q)<<"<b><font color = red>[usr] has shot [Q] with [src]!"
var/lol = Q:loc
var/lol2 = new /obj/Misc/bullet(usr.loc)
while(get_dist(lol,lol2) > 0)
sleep(1)
step_towards(lol2,lol)
del(lol2)
for(var/mob/M in lol)
M:hp -= 35
M:Health()
sleep(30)
else
usr<<"<b>*click*"


if(Q in view (3,4))
if(fuel > 0)
var/shot = (rand(1,2))
if(shot == 1)
fuel --
view(8,Q)<<"<b>[usr] shot [Q] with [src] but missed!"
var/lol = Q:loc
for(var/mob/M in lol)
M:hp -= 0
M:Health()
sleep(30)
if(shot == 2)
fuel --
view(8,Q)<<"<b><font color = red>[usr] has shot [Q] with [src]!"
var/lol = Q:loc
var/lol2 = new /obj/Misc/bullet(usr.loc)
while(get_dist(lol,lol2) > 0)
sleep(1)
step_towards(lol2,lol)
del(lol2)
for(var/mob/M in lol)
M:hp -= 35
M:Health()
sleep(30)
else
usr<<"<b>*click*"


Problem description:
This is bothering me, for some reason the different distances isn't working. You can only hit someone 1 tile away and when you do that you pistol whip AND shoot them, which isn't supposed to happen. Basically I just wanted to make it so that it pistol whips one tile away, and shoots after that losing accuracy farther away. The Q variable is the taget.
I haven't bothered to try and understand your problem (I only skimmed through it once) and really have no want to see what the code is doing but I noticed certain mistakes within it:

1) Why are you doing atom:proc/variable? Do atom.proc/variable. An example would be M:Health() should become M.Health()

2) What is the point in doing M:hp -= 0?

3) Don't use usr in a proc.

4) Don't do if(var==1) or if(var==0) for a boolean variable (a variable that can only be 1 or 0). Instead do if(var) or if(!var).
In response to DeathAwaitsU
Also, use return to stop the proc if needed!
In response to DeathAwaitsU
DeathAwaitsU wrote:
I haven't bothered to try and understand your problem (I only skimmed through it once) and really have no want to see what the code is doing but I noticed certain mistakes within it:

1) Why are you doing atom:proc/variable? Do atom.proc/variable. An example would be M:Health() should become M.Health()

That doesn't matter, it works either way.

2) What is the point in doing M:hp -= 0?

Just to be safe.

3) Don't use usr in a proc.

It's needed for when it announces the attack. It's not in the proc.

4) Don't do if(var==1) or if(var==0) for a boolean variable (a variable that can only be 1 or 0). Instead do if(var) or if(!var).

Doesn't really matter, but it's easier to type.


Thanks SniperJoe, it stopped the double attacking but I don't know if it's going to work at range.
In response to Justin Knight
Justin Knight wrote:
DeathAwaitsU wrote:
I haven't bothered to try and understand your problem (I only skimmed through it once) and really have no want to see what the code is doing but I noticed certain mistakes within it:

1) Why are you doing atom:proc/variable? Do atom.proc/variable. An example would be M:Health() should become M.Health()

That doesn't matter, it works either way.

It certainly does matter, . is almost always better then :.
2) What is the point in doing M:hp -= 0?

Just to be safe.

Safe from what?

3) Don't use usr in a proc.

It's needed for when it announces the attack. It's not in the proc.

Uhh, isn't your whole code pretty much a proc?
4) Don't do if(var==1) or if(var==0) for a boolean variable (a variable that can only be 1 or 0). Instead do if(var) or if(!var).

Doesn't really matter, but it's easier to type.

It does too matter, if(var) and if(!var) cover more options(ex: if(!var) checks if(var!=""&&var!=null&&var!=0)).

Thanks SniperJoe, it stopped the double attacking but I don't know if it's going to work at range.
In response to Artekia
Artekia, do you just like to fight? I asked for help on a problem, not to be given a bad attitude.
In response to Justin Knight
...I'm sorry for trying to help you. I swear I'll never do it again. I'm so sorry.
In response to Artekia
That came out way more as a bad attitude than trying to help.
In response to Justin Knight
Maybe to you. I admit, I'm not always a very nice person, but I could have been a lot more harsh(Heck, I just reread my post, and I don't see anything that should offend anyone).
In response to Artekia
That doesn't matter, it works either way.

It certainly does matter, . is almost always better then :.
It doesn't matter in this situation, i'm editing someone else's code, he rarely uses the : operator.

2) What is the point in doing M:hp -= 0?

Just to be safe.

Safe from what?

Safe from bugs.

3) Don't use usr in a proc.

It's needed for when it announces the attack. It's not in the proc.

Uhh, isn't your whole code pretty much a proc?

Who cares, you're just fighting with this one.

Doesn't really matter, but it's easier to type.

It does too matter, if(var) and if(!var) cover more options(ex: if(!var) checks if(var!=""&&var!=null&&var!=0)).
Doesn't matter in this situation, it's just a simple hit calculator.
In response to DeathAwaitsU
DeathAwaitsU wrote:
4) Don't do if(var==1) or if(var==0) for a boolean variable (a variable that can only be 1 or 0). Instead do if(var) or if(!var).

Does it really matter? All it does it save a small amount of space and is slightly easier to type. If someone want to use if(var==1) or if(var==0), let them.
In response to Jamesburrow
Sure, if(var==1) and if(var==0) may work in many cases, but then you'll most likely get used to always using it, and generally if(var) and if(!var) and more robust and better to get used to.
In response to Artekia
Artekia wrote:
Sure, if(var==1) and if(var==0) may work in all cases, but then you'll most likely get used to always using it, and generally if(var) and if(!var) and more robust and better to get used to.

So what if you get used to it? If it works, it works. Yes, I use if(var) and
if(!var), but if you don't want to use it, why should you?
In response to Jamesburrow
Because if(var==1) and if(var==0) won't work in all situations.
In response to Artekia
Artekia wrote:
Because if(var==1) and if(var==0) won't work in all situations.

Name one where it wont.

[EDIT]
Never mind, I remember a few cases where it won't.....
In response to Justin Knight
Justin Knight wrote:
3) Don't use usr in a proc.

It's needed for when it announces the attack. It's not in the proc.

Uhh, isn't your whole code pretty much a proc?

Who cares, you're just fighting with this one.

Using usr in proc is not going to work about 50% of the time. You are supposed to use src in a proc anf usr in a verb. Considering there were NO verbs there, it was obviously a proc. Considering it was in a proc, use src if you want to make sure it works every time.
In response to Justin Knight
Justin Knight wrote:
That doesn't matter, it works either way.

It certainly does matter, . is almost always better then :.
It doesn't matter in this situation, i'm editing someone else's code, he rarely uses the : operator.

2) What is the point in doing M:hp -= 0?

Just to be safe.

Safe from what?

Safe from bugs.

What bugs is it protecting you from?

3) Don't use usr in a proc.

It's needed for when it announces the attack. It's not in the proc.

Uhh, isn't your whole code pretty much a proc?

Who cares, you're just fighting with this one.

Usr is pretty unstable, and you should almost never use it in procs. You should never have to.

Doesn't really matter, but it's easier to type.

It does too matter, if(var) and if(!var) cover more options(ex: if(!var) checks if(var!=""&&var!=null&&var!=0)).
Doesn't matter in this situation, it's just a simple hit calculator.

You're pretty much safe, but it is always better to use more robust code.
In response to Jamesburrow
Well, here's a snippet from Wizkidd's Hello Operator(http://byondscape.com/ascape.dmb/ Wizkidd0123.2005-0129/):

The ! operator can be read as "NOT". If you want to code robustly (robust means watertight/bulletproof, and trust me: you do), this is a very important operator for you. To understand the ! operator, first you must understand that 0, null, and "", although similar in nature, are different values. Therefore, checking

if(A==0)

simply doesn't do it. A could also be equal to null or "".

Using the || operator (it's read as "OR"), which we haven't covered yet (I'll get to it soon!), we could do something like this:

if(A==0||A==null||A=="")

Tedious, isn't it? That's why we have the ! operator. Instead of typing the redunant code above, we instead say

if(!A)

Not only is if(!A) more elegant, but it will someday save you from many, many headaches.



The reason I didn't make something myself, is one: I'm lazy and two: I'm in splitting agony from this darn tooth, I had a cavity filled today. I know that's not a very good excuse, but all I really want to do right now is lay down and hope the pain goes away.(my numbing just wore off)
In response to Artekia
People, people this is an OBJ proc. src is the object! usr is the person! If I used src then it would look like this: "Pistol has hit John Doe with the pistol!"
In response to Justin Knight
Usr is never safe in most proc, even if it is an "OBJ proc". It's dandy in verbs and a few other cases, but generally, you should avoid it otherwise. You should never need it in this case.
Page: 1 2 3 4