ID:139869
 
mob
proc
NPCAI2()
var/mob/M = usr
while(src)
if(M in oview(1))
if(istype(src,/mob/enemies/Oktorok))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Link3))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Ganon))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Zelda))
sleep(20)
NPCAI2()
else
sleep(20)
src.MONATTACK(M)
NPCAI2()
else
sleep(10)
if(prob(25))
step(src,NORTH)
if(prob(25))
step(src,SOUTH)
if(prob(25))
step(src,WEST)
if(prob(25))
step(src,EAST)
if(prob(25))
step(src,NORTHWEST)
if(prob(25))
step(src,NORTHEAST)
if(prob(25))
step(src,SOUTHWEST)
if(prob(25))
step(src,SOUTHEAST)
break
sleep(5)
spawn(2)
NPCAI2()
mob
proc
MONATTACK(mob/M in get_step(src,src.dir))
var/damage = src.Level*10
view() << "[src] attacks [M] for [damage]!"
M.HP -= damage
if(M.HP <= 0)
M.Death(src)
mob
enemy
Zelda
name= "Zelda"
icon = 'Zelda.dmi'
MaxHP = 2000
HP = 2000
NPC=1
Level = 2e+006
New()
NPCAI2()
mob
enemy
Ganon
name= "Ganon"
icon = 'Ganon.dmi'
MaxHP = 6000
HP = 6000
NPC=1
Level = 6e+006
New()
NPCAI2()
mob
enemy
Link3
name= "Link"
icon = '!!!gba link2.dmi'
MaxHP = 1000
HP = 1000
NPC=1
Level = 1e+006
New()
NPCAI2()

I get no errors in this code string, but when I compile and run, the NPC's don't attack me.
I tried deleting:

if(istype(src,/mob/enemies/Oktorok))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Link3))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Ganon))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Zelda))
sleep(20)
NPCAI2()

But then they attacked the other NPC's and themselves but wouldn't attack me. Help.
Alright, my suggestion would be to revamp this code. I will help you a bit:
mob
proc
NPCAI2()
//var/mob/M = usr - This is a proc, using usr is not a good idea. Plus, this is not needed.
while(src && src.loc) //Alright, I just added src.loc there, because at some point you might send them somewhere,
// such as 0,0,0, and this will keep them from checking, as there is no point in it.
for(var/mob/M in oview(1))
/*if(istype(src,/mob/enemies/Oktorok))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Link3))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Ganon))
sleep(20)
NPCAI2()
if(istype(src,/mob/enemy/Zelda))
sleep(20)
NPCAI2()
For all of that, you might just want to make an AI code for the AI themselves.
If this is supposed to be checking if the person AROUND them is of the types specified, then src is the wrong thing to use.
src checks to see if the source of this code is of the specified type.
if(M.client)
sleep(20)
src.MONATTACK(M)
NPCAI2()
else
sleep(10)
/*if(prob(25))
step(src,NORTH)
if(prob(25))
step(src,SOUTH)
if(prob(25))
step(src,WEST)
if(prob(25))
step(src,EAST)
if(prob(25))
step(src,NORTHWEST)
if(prob(25))
step(src,NORTHEAST)
if(prob(25))
step(src,SOUTHWEST)
if(prob(25))
step(src,SOUTHEAST)
Learn up on step_rand. That proc does everything you just specified.*/

step_rand(src)
sleep(5)
// spawn(2)
//NPCAI2() These 2 lines are not needed.
//This is saying that you should keep trying to do this loop when the src is not there or not in a location anymore.
//Just call the NPCAI2 again when the NPC respawns.
mob
proc
MONATTACK(mob/M in get_step(src,src.dir))
var/damage = src.Level*10
view() << "[src] attacks [M] for [damage]!"
M.HP -= damage
if(M.HP <= 0) //Your Death proc should check to see if the HP is 0. It prevents an extra line here, so it would help.
M.Death(src)
mob
enemy
Zelda
name= "Zelda"
icon = 'Zelda.dmi'
MaxHP = 2000
HP = 2000
NPC=1
Level = 2e+006
New()
NPCAI2()
mob
enemy
Ganon
name= "Ganon"
icon = 'Ganon.dmi'
MaxHP = 6000
HP = 6000
NPC=1
Level = 6e+006
New()
NPCAI2()
mob
enemy
Link3
name= "Link"
icon = '!!!gba link2.dmi'
MaxHP = 1000
HP = 1000
NPC=1
Level = 1e+006
New()
NPCAI2()


Also, make sure you always put a ..() in the New() proc.

I also recommend looking up some AI tutorials, such as Forum_account's Enemy AI Demo.
In response to Albro1
Ok I wanted it to check if those types were there because I didn't want the NPC's to spam kill other NPC's because I overloaded the dungeon with NPC's and it was intentional and I DID want them to attack the mob if it wasn't an NPC... the rest is fine though. I will report the errors!
In response to Narutorox123456
If you want it like that, just define the NPCs as /mob/NPC and check for that.
In response to Albro1
Albro1 wrote:
If you want it like that, just define the NPCs as /mob/NPC and check for that.

When I tried to run the game with the code you gave me, the window opened but crashed... why?
In response to Narutorox123456
It most likely conflicts with your other code. What I showed you was more of an example of how to make it better than it was a complete fix. Like I said, just look up some AI tutorials, and make a new system from scratch.
  • You're abusing usr
  • You're going to crash your call stack pretty fast through abusing recursive function calls
  • You're completely butchering a loop
  • You completely misunderstand if(prob25)
  • You completely defy most object-oriented programming paradigm
  • Your design is flawed


What do you want to accomplish (in plain, proper English)?
In response to Albro1
Albro1 wrote:
Also, make sure you always put a ..() in the New() proc.

May I wonder why?
Programming is not some weird act of voodoo where you have magic formulas that nobody knows why they are used, but that they have to be used and if only for the sake of using them.

atom.New() as no default action.

'By the time New() is called, the object has already been created at the specified location and all of its variables have been initialized. You can perform additional initialization by overriding this procedure.'
In response to Schnitzelnagler
Schnitzelnagler wrote:
Albro1 wrote:
Also, make sure you always put a ..() in the New() proc.

May I wonder why?
Programming is not some weird act of voodoo where you have magic formulas that nobody knows why they are used, but that they have to be used and if only for the sake of using them.

atom.New() as no default action.

'By the time New() is called, the object has already been created at the specified location and all of its variables have been initialized. You can perform additional initialization by overriding this procedure.'

You can perform many additional initialization procedures by overriding atom.New multiple times. For example:

atom
New()
world << "A"

// in another file:

atom
New()
world << "B"

turf
Click()
new /obj(src)


When you click on a turf you'll only see "A" or "B" as output, not both. If you put ..() in each New proc you will see both "A" and "B".

I agree that it does need explaining but it does have a purpose. You might use an object's constructor to initialize something without realizing that you already define its constructor in another place. This could create some bugs that are very difficult to track down.
In response to Forum_account
I'm well aware of both what calling the parent procedure does and when to do so, thank you.

My point is that by the same logic, you could argue that you should always call the parent in every single procedure, but that is simply unreasonable. When there is a reason to do so, sure, do it, but not just for the sake of doing it. Not to mention that there are plenty of situations where you do not want to call the parent on purpose.
In response to Schnitzelnagler
Schnitzelnagler wrote:
I'm well aware of both what calling the parent procedure does and when to do so, thank you.

I wasn't talking about parent procedures, I was talking about overriding the same proc twice. You also asked for a reason why you should call ..(). If you really knew why you could have explained it yourself.

When there is a reason to do so, sure, do it, but not just for the sake of doing it. Not to mention that there are plenty of situations where you do not want to call the parent on purpose.

The situations where you don't want to call ..() are much easier to identify because you're consciously deciding that you don't want any more actions to occur. I can't imagine a way that you'd get in bigger trouble by calling ..() out of habit when you shouldn't. Do you have an example?
In response to Forum_account
Forum_account wrote:
You also asked for a reason why you should call ..().

By no means. I asked why one should '(...)make sure you always put a ..() in the New() proc.'
As I tried to explain in the paragraph directly following my question, I don't see why you would encourage a mystical formula. If there is a reason to do something, sure, do it (and if you explain the reason, even better), but doing something because of doing it seems... off.

But, as this discussion is derailing the topic, I'll go shush now.
In response to Schnitzelnagler
Schnitzelnagler wrote:
  • You're abusing usr
  • You're going to crash your call stack pretty fast through abusing recursive function calls
  • You're completely butchering a loop
  • You completely misunderstand if(prob25)
  • You completely defy most object-oriented programming paradigm
  • Your design is flawed

What do you want to accomplish (in plain, proper English)?
I didn't misunderstand if(prob(25)) because I actually typed it right unlike you... and also I got this error with the steprand code he gave me. My design isn't flawed because there is no inconsistent indentations...
In response to Narutorox123456
Schnitzelnagler knows what he is talking about most of the time. Him typing if(prob25) was a typo, I am sure. Lashing out at people trying to help you is not the way to go here.

Also, your design being flawed does not mean you have inconsistent indentation... It means that you have problems in the design of your code. Just because something works, does not mean it is right. He most likely meant that you are trying to get your NPC to do something, but you are doing it in the wrong fashion.
In response to Albro1
Albro1 wrote:
Schnitzelnagler knows what he is talking about most of the time. Him typing if(prob25) was a typo, I am sure. Lashing out at people trying to help you is not the way to go here.

Also, your design being flawed does not mean you have inconsistent indentation... It means that you have problems in the design of your code. Just because something works, does not mean it is right. He most likely meant that you are trying to get your NPC to do something, but you are doing it in the wrong fashion.

Oh, I guess I misunderstood him. Ok. I will try editing the code the right way to see if it works.
In response to Narutorox123456
Narutorox123456 wrote:
I didn't misunderstand if(prob(25)) because I actually typed it right unlike you... and also I got this error with the steprand code he gave me. My design isn't flawed because there is no inconsistent indentations...

Him making a typo doesn't mean that you know the first thing about independent random events. A chain of if(prob(25)) procs like you have will not result in a 25% chance of each action, which should be pretty damn clear what with you having eight possible actions there (or, you have eight written, the number of ACTUAL actions possible there is combinatorial).
In response to Narutorox123456
Thank you for correcting my typo, but you haven't answered the main and most important question.

Schnitzelnagler wrote:
What do you want to accomplish (in plain, proper English)?

The reason I'm asking this is simple. I want to help you design code to do what you have in mind, but the problem is that right now, I would have to guess at what you assume that the code you presented should do, meaning we have two points in the communication where somebody is blindly taking assumptions. That's never a good point, so by actually elaborating on what you have in mind, you grant the volunteers trying to assist you the chance to come up with a productive response that fits your need, instead of some random stuff you likely do not even want.