ID:142207
 
Code:
mob/zombie
name = "Zombie"
icon = 'zombie.dmi'
icon_state = "zombie"
hp = 50
speed = 50
New()
.=..()
spawn(30)
Look()
Bump(mob/M)
if(M.client)
M << "GOTCHA!"

mob
proc
Look()
var/mob/Player/M
while(src)
if(M in oview(5))
walk_to(src,M,1,40)
if(M in oview(1))
step_towards(src,M)
else
step_rand(src)
break
else
for(M in view(src))
break
sleep(20)
spawn(20)
Look()


Problem description: The above code is from a resource, in case you didn't realize...

The only problem I'm having out of it, is that every so often, when I get far enough away from the zombie, it will TELEPORT near me.

What's going wrong here?

You're using usr in a proc, which is bad. oview() defaults to usr. Set it to src instead.
Pakbaum wrote:
Problem description: The above code is from a resource, in case you didn't realize...

Don't Do It. First, demos are for demonstration, not for blatant copying. This means you understand how the code works, then rewrite it yourself, changing as suitable. And whatever demo you used, to be frank and to the point - it sucks horribly.

The only problem I'm having out of it, is that every so often, when I get far enough away from the zombie, it will TELEPORT near me.

I'm actually surprised that'd be the only problem. Doesn't even make sense, to me.

What's going wrong here?

You could say the better question would be "what's going right?"...
I think you should be able to re-read and follow through the execution of that code, if not instantly then with a little Reference usage... But anyway, let's see... I'll rewrite that in psuedo-code:
Look()
define a new var with no value (M), so it's set to null
loop while(src) still exists (the check is pointless because the proc will automatically stop if src is deleted and won't even get to run that check)
if(null in oview(usr,5))
//do stuff, but this block will never execute
useless extra if() check with step_towards()
else, then do a completely useless and dumb loop which does absolutely nothing
for(every mob in view)
stop the loop immediately on the first iteration without doing anything
call the proc again uselessly, as it already mostly loops (unless dumbly break-en), and this practice is pretty bad anyway in itself

Also, in Bump() you need to verify the argument atom is indeed a mob, or in cases it isn't (could be a dense obj or turf) you'll get a runtime error, as only mobs have the client var.

So, I guess you get the idea. Best scrap it and rewrite it yourself.
The 'approved'/'respectable'/'published'/'favorite' resources are accessible here. These are non-suckage guaranteed. Not to say all other resources are complete crap like the one you've used, but there are many like it. Of course this isn't a safe-ish method, but if you're going to check out and use a different resource, try and verify the person who made it isn't a complete noob somehow. You could guess that by their keyname, blog, forum posts, whatever... the crappy ones actually tend to be identifiable by some Majingoku1482 etc IIRC, or some such.
In response to Kaioken
No offense, but what is the point of the demonstration, if I can't change it to see if it could suit my situation?

I understand that taking different resources and smashing them together is bad form, but can I not simply use this code to re-learn the basics by trying out different systems of the same thing to achieve what I'm trying to do? If this is not the final product, then why harp over what's seen here?
In response to Pakbaum
Pakbaum wrote:
then why harp over what's seen here?

To get you to see that its a bad resource, and to help you learn.

Why do people get so offended so easily these days? =(
In response to Pakbaum
Pakbaum wrote:
No offense, but what is the point of the demonstration, if I can't change it to see if it could suit my situation?

Demos aren't meant to be used, really, only libraries. The point of them is that you read them, not use them. They're supposed to demonstrate how you can program something in one way, the reader is supposed to understand and test the code, read it a couple of times, etc. After you understand how to do it, you write that aspect in your environment, suited for
your game, with your own code preferences and habits and what not.
Writing it on your own is always better. You gain experience and learn to write things from scratch.
If you're going to just copy and edit demo code, you aren't really using it any different than some anime game source.

I understand that taking different resources and smashing them together is bad form, but can I not simply use this code to re-learn the basics

No. It's not a guide or a tutorial. It's a demonstration on how you can make X in DM, but not how to use DM (or its basic). A bad one, you shouldn't learn from at all, at that.
It's not that we don't have appropriate resources (guides, tutorials, articles) so you have to resort to using something unsuitable.

If this is not the final product, then why harp over what's seen here?

I don't get it. You made a Code Problem topic. You even explicitly asked: "What's going wrong here?". Are you complaining about me answering that? Or about my discouraging of usage of bad demos? Or should I have simply not replied because 'this is not the final product'? :o
In response to Kaioken
The second loop there is being used to select the first mob it finds, which allows the if block to execute.

The code is still bad, of course, but I just wanted to give some insight as to why it actually works somewhat.
In response to Cinnom
Oh, yeah, you're right! Although it looks like that works due to primarily luck, since the M var happened to be defined outside the loop, but usually you wouldn't have that normally.
In response to Cinnom
Ah...gotcha. Thanks for your input bro. Insight is the goal here ^.^
In response to Kaioken
Are you complaining about me answering that?

No no no, not at all. Don't get me wrong, I appreciate the input, I really do. I would rather get a response that questions what I'm doing, than no response at all. Your input IS welcome, good or bad.

Or about my discouraging of usage of bad demos?

Once more, I'm glad you replied, I was just hoping for something more direct/helpful. Such as 1) Showing me what's wrong with it first 2)Directing me to a more helpful resource then 3) Explaining how what I'm doing is not what I should be doing. The goal here was to get as much input and as many tips as I could, not to start an argument.

Finally, please put in your opinion, but give me some advice related to what I post as well, both are equally important.

Sorry if I came off as rude earlier, I was in sort of a bad mood >
In response to Pakbaum
Pakbaum wrote:
Sorry if I came off as rude earlier, I was in sort of a bad mood ><i apologize.
<br/> Sure, happens. No problem, I didn't get offended or anything, though I just questioned what you were meaning to say.
In response to Kaioken
So can you give me a better direction? Well-done resources applicable for me need? As in, a good way of learning how to do this the right way.
In response to Pakbaum
In response to Jeff8500
I must be missing what you're talking about then. I've looked through all of those (not opened them all) and I don't see anything NPC/AI related, that, or I'm just missing every time.

Both of those failing, I've gone blind :P

Could you possibly give me the name of one? Or link it for me?
In response to Pakbaum
In that case, just learn the walk/step procs, for() loops (and you may want to look up break and continue, too, for that matter), and the get_dist() proc (unless you would rather use Bump(). I think that's a little over simplified, though, as you can't really teach it projectiles without the get_dist() proc anyway!).

I'm pretty sure there has been some (good) AI code posted in the forums you could look at. Just make sure it was done by someone that knows what they're doing (Kaioken, Popisfizzy, Garthor, etc.).