Ok I'm having some problems with this.
I wan't it to check if there is a mob in it's view then walk to them. If not I want it to walk randomly. I got to
mob
NPC
icon='npc.dmi'
New()
ID:267329
Mar 8 2003, 7:42 am
|
|
In response to Kunark
|
|
mob Tsk tsk tsk... you didn't <code>spawn()</code> out the call to <code>Wander()</code>! You need to call it with <code>spawn() Wander()</code>, not just <code>Wander()</code>. Also, <code>oview(5)</code> neeeds to be changed to <code>oview(src,5)</code>, because usr is not appropriate in procs. Also, you need to <code>break</code> the <code>for()</code> loop once the mob has moved. |
In response to Garthor
|
|
Wow... I must've been in a coma when I put that up, I thought about everything you put up there before I did it, then for some reason didn't do it...
//Do this instead: mob NPC icon='npc.dmi' New() spawn() Wander() proc/Wander() while(src) //While he exists... var/IsOview = 0 for(var/mob/PC/M in oview(src,5)) IsOview = 1 step_towards(src,M) break if(IsOview == 0) step_rand(src) sleep(5) But how can you say usr isn't appropriate in procs? It's appropriate in many situations, not this one, but whats the point in putting oview(src,5) when you can just do oview(5), which is easier to type considering you have to use this proc all the time in alot of games, and get the exact same result because in this right here proc, usr is always equal to src (when you call something like M.Damage() or something like that, src would change to M and usr would still equal the NPC.). |
In response to Kunark
|
|
Humm, I don't think so. I'm pretty sure usr is not set to src in New(). Let me check...
|
In response to Garthor
|
|
Calling Wander() is the same as calling src.Wander()... When it first starts out, usr is the same thing as src, unless src changes when a new proc is called.
I've used usr in those types of proc all the time, and never had a problem with it. It's not set to SRC when New() is called, but it's set to the same mob. |
In response to Kunark
|
|
Yeah, I guess you're right, usr is set to src in New(). Still, it's not a safe practice. If, for example, he decides that he only wants Wander() to be called when a player moves close enough to appreciate the wandering, then you'd run into problems.
|
In response to Garthor
|
|
Thats true because then the person that originally called the proc (usr) would be the PC instead of the mob.
|
In response to Kunark
|
|
If you want to call a Attack(M, src) proc to let the src attack the usr if its 1 tile near it, how would you guys change the wander to do that?
|
In response to Fint
|
|
src attack the usr? So he attacks himself?
How about instead M.Attack(src) (this would be the player attacks the NPC) or Attack(M) (same as src.Attack(src), this would be the monster attacks the player.)? |
mob
NPC
icon='npc.dmi'
New()
Wander()
proc/Wander()
while(src) //While he exists...
var/IsOview = 0
for(var/mob/PC/M in oview(5))
IsOview = 1
step_towards(src,M)
if(IsOview == 0)
step_rand(src)
sleep(5)