i want the NPC's to run towards each other, Wander() does that, but they don't. all the NPC's do is just stand still. im not sure if they do that because they can't handle having an ally and an enemy in the same oview, or the charge() proc is screwing up the code. if your wandering what the WalkAround() proc is, its like step_rand, except the mobs don't make cheesy movements.
mob/NPC
var/mob/NPC/m
proc/charge()
while(src)
if(m.colorofwar == src.colorofwar)
WalkAround(src)
else
Wander(src)
proc/Wander()
while(src)
if(m in oview(5))
step_towards(src,m)
Wander()
Bump(mob/n)
if(istype(n,/mob/NPC))
attack(n)
proc/attack()
sleep(2)
var/damage = Strength - m.Defence
m.Life -= damage
view(src) << "[src] attacks [m]!"
view(src) << "[damage] damage!"
if(m.Life < 0)
del(src)
ID:147068
Oct 6 2004, 1:18 pm
|
|
On top of what DarkView said, I'll give you another tip. This is bad:
proc/Wander() You should never have a proc call itself this way to loop. It will eventually give you a stack overflow error. Instead, use spawn(). However here you're already using while(src) to loop, so as long as you make sure to add a sleep(delay) after the if(), you're all right. You should definitely add that sleep(), though, or you'll have an infinite loop. Lummox JR |
In response to DarkView
|
|
okay, the NPC's are Blue, Yellow, Red, Green, White, and Black. PC's are not targets at all (the mob is blank and his density is 0, making him a perfect overview camera). NPC's with the same colors are allies, when they spot an enemy within a range of 5, they run to the enemy and attack by bumping him, and bumping triggers the attack proc. I should put in some code where NPC's will run to the enemy that is closest to him, I saw Nadrew's skills demo and i know how to do it, getting the NPC's to attack is a different story.
|
In response to Mardok
|
|
Ok. Well use your charge() proc for this. A word of warning however, don't copy and paste my code snippets otherwise this wont work. You can copy the lines of code, but you'll have to do all the indentation (spacing) yourself because I'm not using tabs I'm using spaces.
proc/charge() Now for starters, we have to loop through all the /mob/NPCs in oview(5). For this we'll use a for() loop. Something like this: for(var/mob/NPC/pTarget in oview(5,src)) //We'll call the mob pTarget, which stands for 'potential Target'. We also have to take extra special care when using procs like oview(), range() and view() because it uses usr by defualt. Which if left will result in it checking the /mob/NPCs within range of the players mob, not the NPC. All you really need to know is that in range(), orange(), view() and oview() you have to write view(range,center) where center will usually be src. Ok, now we've got that done, we need to check to see if these potential targets are friendly or not. for(var/mob/NPC/pTarget in oview(5,src)) Now we've made it so the loop will skip anything on the same team as src, we just need to make it so that it sets m to anything else. for(var/mob/NPC/pTarget in oview(5,src)) Ok. Now hopefully everything should work. |
In response to DarkView
|
|
mob/NPC thanks for the help, but the NPC's are still not moving, i dont think it has to deal with any other code in the game, because i scrolled through it, looking for mistakes. all the code required for this procedure is here. |
In response to Mardok
|
|
Doh. I missed a huge mistake. You've got while(src) loops in your WalkAround() and Wander() procs.
What this is doing is making your AI get stuck in there because as long as the mob exists src is going to be true. Meaning that when it enters Wander() it's going to just keep on checking if m in oview() and if it is step towards it. I also think you've got Wander() and WalkAround() mixed up. It would seem that you want it to walk towards it's enemies and walk randomly otherwise, but you've got it wandering around randomly if it isn't on the same side, and walking towards it if it is. |
In response to DarkView
|
|
Doh, it still doesn't work, the mobs are still not moving. GAAAA, the frustration.
mob/NPC I can't think of anything that'll give us a clue of what's wrong. |
In response to Mardok
|
|
Putting src into oview() like I said may fix it. It may not but it's definantly going to cause you problems if you don't fix it.
How is charge() being called? Also, to locate the problem we'll use a technique where we output messages to the world when ever parts of these procs are called. First, make sure you've only got one of these NPCs in the world. Now add stuff like world << "charge() starting" to parts of the procs. The idea is when you run it you'll be able to see what's happening/not happening easier. For instance, if we put a world << "restart main charge loop" just after the while(src) in charge() we'll be able to see how often the main loop is looping. One last thing, remove the last two lines of WalkAround() (the spawn and call to WalkAround()). Otherwise everytime charge() calls WalkAround() it's going to start up a new infinate loop which you don't want (it'll cause the mob to WalkAround() while doing other things). |
When you wrote Wander(src) you're actually writing src.Wander(src) because no matter what you've always got to specify what atom (or datum) is calling the proc, verb or modifing the var. You can get away with leaving it blank most of the time because it defualts to src.
Anyway, back to the point. You're passing an arguement to Wander() when Wander() takes no arguements. So cut that out.
Now, onto the actual problem. You're never actually setting m in any of this. You've checked to see if it's in oview(5) but that's it.
I'm not sure how you want your NPCs to target players, but if you give me a brief description of how you want them to and the name of your /mob/player type I'll walk you through making them target players.
Also, it's not that important but you should give better names to your atom vars. Something like targetNPC would be a much more fitting name then 'm'.
One last thing, when posting code in the forum put