ID:264035
 
Code:
mob
Attacking_NPC
Cacturne
icon = 'Hoenn Pokemon.dmi'
icon_state = "cacturne"
name = "Cacturne"
hp = 200
var/mob/character/Player
New()
. = ..()
spawn()
move()
proc/move()
while(src)
var/player_found = 0
for(Player in oview(8,src))
step_towards(src,Player)
player_found = 1
break
if(player_found != 1)
step_rand(src)
sleep(10)
sleep(5)

Bump(mob/M)
if(istype(M,/mob/character))
attack(M)
proc/attack(mob/M)
var/damage
M.hp -= damage
M <<"You are being attacked by [src]!"
src.Exp += rand(5,10)
Levelup()
M.deathcheck(src)


Problem description:
Player Undifined Type
Player Undifined Type
/mob/character undifined type path

                    for(Player in oview(8,src))
step_towards(src,Player)

Those are the lines with the player problem
                if(istype(M,/mob/character))

And thats the other problem, can someone help me?
mob/Attacking_NPC
New()
spawn move() //You dont need .=..() or any of that crap
proc/move()
while(src)
var/mob/A
for(A in oview(8,src))
break //When A is found stop the loop
if(A) //If A exists
step_towards(src,A)
else //If not,
step_rand(src)
sleep(5)
Bump(mob/M)
if(M.client) //if they are a player
attack(M)

You apparently dont have a mob/character defined, so its not finding that type. But dont even use it its useless. Just study this, it works for what you want.
In response to Dragonn
Dragonn wrote:
> mob/Attacking_NPC
> New()
> spawn move() //You dont need .=..() or any of that crap
>


Don't spread misinformation like this. Whenever you override a procedure, unless if you specifically want to completely replace the previous definition, you should ALWAYS call the parent, which is ..(). Additionally, you should be writing spawn() move(), because randomly excluding parenthesis is not good practice.

Also, explaining what you're doing in that for() loop would be helpful, because how it works is rather obtuse.
In response to Garthor
Yea it is misinformation. But do you think he is really going to understand parent procedures and stuff? I really just want to keep it simple, he'll get to that stuff and when he does (if he is anything like how I learned) what I said here won't impede him.

All I want to know is why you don't like excluding the spawn parenthesis when they aren't being used for anything in this situation?

And yes that for loop is obtuse but once explained its very simple. But that last sentence just sapped all my motivation lol
In response to Dragonn
Dragonn wrote:
Yea it is misinformation. But do you think he is really going to understand parent procedures and stuff? I really just want to keep it simple, he'll get to that stuff.

And you think telling him "it's useless" is going to help his understanding?

All I want to know is why you don't like excluding the spawn parenthesis when they aren't being used for anything in this situation?

Consistency. There's no need to be removing the parenthesis, so don't remove them.

And yes that for loop is obtuse but once explained its very simple. But that last sentence just sapped all my motivation lol

If you aren't willing to explain what your code does, then you shouldn't be posting any.
In response to Garthor
I dont value consistency though, I value shortness and getting rid of stuff that does nothing in specific cases.

Hm Im thinking of an analogy... Gimme a second

Ok

Like a guy who always throws the same pitch in baseball, yea he is consistent. But does that necessarily make him better? Or even worse for that matter?

I guess I just don't think it matters but I value the shortness.

Oh yea and for the guy who posted this if you ever come back, here be my shortened version of that code, whether for your benefit or mine:
mob/Attacking_NPC
New() spawn move()
proc/move() while(src)
var/mob/A
for(A in oview(8,src)) break
if(A) step_towards(src,A)
else step_rand(src)
sleep(5)
Bump(mob/M) if(M.client) attack(M)

9 lines as compared to 16 lines. And (to me) just as easy to read, its more close to regular sentence structure than code. As a matter of fact I now find the "normal" coding structure slower (not harder) to read than this style.
In response to Dragonn
????????
In response to Dragonn
Your analogy is dumb as is your practice of crushing code down at the expense of readability. Keep them both off the forums.
In response to Dragonn
Dragonn wrote:
>       spawn move() //You dont need .=..() or any 
>


Get off the forums until you realize that your advice is absoultely awful.
In response to Popisfizzy
...No. Why don't you explain why thats bad? Your accusations make no sense. And why don't YOU get off the forums you flamer. It does the same thing, its easy to read, I don't see the problem. You want to spawn move? You just spawned move. I don't see the issue. You and Garthor need to get off my back, I'm not going to stop so your baseless flaming is falling on deaf ears. And this is the first time I've been rude to you or him, but now you deserve it.
In response to Dragonn
Well, when moving you should almost always return the value of the default proc, which is what . = ..() does. Chances are you don't even know what the . variable is for if you're giving this kind of bad advice. There is also no need for that loop, as you can use locate() and oview() just as well. You're also simply assuming that the thing you bump into will be a mob, which it probably won't be in at least half the cases, but very certainly more.

In other words: "Get off the forums until you realize that your advice is absoultely awful."

[Edit]
I misread the proc, and for some reason though you were telling him not to do . = ..() in Move(). In New() the default proc does nothing, but the rest of what I said holds true.
In response to Garthor
err... I Started All This? wow o_o Anyway, Would I keep me attack proc somewhere? cause this is what i was told would work
mob/Attacking_NPC
New() spawn move()
proc/move() while(src)
var/mob/A
for(A in oview(8,src)) break
if(A) step_towards(src,A)
else step_rand(src)
sleep(5)
Bump(mob/M) if(M.client) attack(M)

But it gives me the attack is undefined proc, so im confused...alot..
In response to Reno Kujika
ok i put this in
mob/Attacking_NPC
New() spawn move()
proc/move() while(src)
var/mob/A
for(A in oview(8,src)) break
if(A) step_towards(src,A)
else step_rand(src)
sleep(5)
Bump(mob/M) if(M.client) attack(M)

proc/attack(mob/M)
var/damage
M.hp -= damage
M <<"You are being attacked by [src]!"
M.deathcheck(src)

I Think Im All Good, I go near the NPC To see if he will attack me, and this is said when he moves a tile(every single time!)
runtime error: Cannot read null.Health
proc name: deathcheck (/mob/proc/deathcheck)
usr: Attacking NPC (/mob/Attacking_NPC)
src: Reno Kujika (/mob)
call stack:
Reno Kujika (/mob): deathcheck(null)
attack(Reno Kujika (/mob))
Attacking NPC (/mob/Attacking_NPC): Bump(Reno Kujika (/mob))
Attacking NPC (/mob/Attacking_NPC): Move(Cave Floor (23,192,4) (/turf), 4)
Attacking NPC (/mob/Attacking_NPC): move()
Attacking NPC (/mob/Attacking_NPC): New(Cave Floor (10,185,4) (/turf))

and I know that probaly doesnt go in dm bracket things but its the best way i could show u and when it Attacks(AKA: Bumps me) this is said
runtime error: undefined variable /turf/var/client
proc name: Bump (/mob/Attacking_NPC/Bump)
runtime error: undefined variable /turf/var/client
proc name: Bump (/mob/Attacking_NPC/Bump)

Now I'm really confused..
In response to Reno Kujika
Those are because of bad assumptions that Dragonn made when writing his code. I'd suggest never using code written by him, as he's proven himself to not be good with help. If you want to follow the setup that Dragonn provided, then this is a better way of doing so.
mob/attacker
New()
//As New() must return, this spawn()s off
//movement_loop(), which is an infinite loop and
//will not end until src is deleted. To work around
//this replace the condition in the while loop
//below.
spawn() movement_loop()

proc/movement_loop()
while(1)
//This checks to find a /mob within eight tiles
//of the src.
var/mob/m = locate(/mob) in oview(src, 8)

//If m is found, step towards it. If not, just
//wander randomly.
if(m) step_towards(src, m)
else step_rand(src)

//Wait five ticks before iterating again.
sleep(5)

Bump(mob/m)
//This checks to see that m is, in fact, a /mob.
if(istype(m))
//If it is, attack.
attack(m)


There are several changes I would make to this. Firstly, I'd have the loop only iterate as long as the attacker should attack, as it's stupid for things to keep fighting once their health gets below a certain point, unless their rather daft. I'd also have several other things stored in variable, such as the distance it will attack and how long it'd wait (I'd most likely create a range of times they could wait). I would create my own procs to handle stepping randomly (some attacks may only defend their own area, while some may wander randomly about) and stepping toward (though this one is straightforward, one may wish to tweak with how this works). I would also handle conditions for attacking in the latter proc. The point of all this would be so you could define child types of /mob/attacker that would be easily modifiable in the way they work, while all based off the same "template".
In response to Popisfizzy
runtime error: Cannot execute null.deathcheck().
proc name: deathcheck (/proc/deathcheck)
usr: Wild Cacturne (/mob/Attacking_NPC)
src: null
call stack:
deathcheck(Reno Kujika (/mob))
attack(Reno Kujika (/mob))
Wild Cacturne (/mob/Attacking_NPC): Bump(Reno Kujika (/mob))

That comes up when it kills me, any other time its good(Thanks again) Do u know what could be wrong? Or Anyone?
In response to Reno Kujika
That's in code you didn't post, as far as I can tell. I can't help you without seeing it.
In response to Popisfizzy
I see...well, I posted all the code I had for that, so Thanks anyway(When they get killed by it they got to deal with it lol)
In response to Reno Kujika
The problem is in your deathcheck() proc, which you didn't post.
In response to Popisfizzy
Aside from that, deathcheck() and attack() need to both be mob procs, not global procs.
In response to Garthor
Correct, Popisfizzy, and Garthor That helped me, Thanks. I Got it working like i want it, Thank You Everyone!