ID:147817
 
I posted this originally on the newbie forum, but I believe it is difficult for that forum, and I didnt even have code at the time......but now I have a code but it doesnt do what I want it to do. And no one so far could help me.

This is for my game Dynasty Warriors Online

- 3 teams (Wu, Shu, Wei)
- NPC's should Attack, and Chase After/follow after NPC's and People not on there team.

Problem In my Code right now:
NPC's Will not fight eachother

Code:
mob/Enemies/proc/Attack(mob/M)

flick("Attack",src)
if(M.Dynasty == src.Dynasty)
return
src.Preattacking(M)
var/mindamage1 = src.Min_Attack
var/resist = M.Defense
var/resist2 = round(resist / 2)
var/mindamage2 = mindamage1 - resist2
var/maxdamage1 = src.Max_Attack
var/maxdamage2 = maxdamage1 - resist2
var/chance = src.DEX + M.AGI
var/chance2 = rand(1,chance)
var/damage = rand(mindamage2,maxdamage2)
if(get_dir(src,M) == SOUTHEAST) //And now, for a visual effect, the mob will actually jkump into the tile that his opponent is in and hit them.
pixel_y -= 14 //We do this by making the object LOOK as if it is in the other tile. But really, it is just the icon file's coordinates being modified. Here we make the icon go down 14 pixels.
pixel_x += 14 //Ditto for the x.
else //We will now check to see which direction the player is from the enemy again and again and set the icon to the right place.
if(get_dir(src,M) == SOUTHWEST)
pixel_y -= 14
pixel_x -= 14
else
if(get_dir(src,M) == NORTHEAST)
pixel_y += 14
pixel_x += 14
else
if(get_dir(src,M) == NORTHWEST)
pixel_y += 14
pixel_x -= 14
else
if(get_dir(src,M) == SOUTH)
pixel_y -= 14
else
if(get_dir(src,M) == NORTH)
pixel_y += 14
else
if(get_dir(src,M) == WEST)
pixel_x -= 14
else
pixel_x += 14
sleep(2) //This is set jsut right so it looks as if he also jumps back.
if(chance2 <= src.DEX)
if(damage <= 0)
damage = 1
view(usr) << "[src] hit [M] for \red[damage]\black points of damage."
M.HP -= damage
src.Postattacking(M)
else
view() << "[src] attacked [M], but missed."
src.Postattacking(M)
pixel_x = 0
pixel_y = 0 //Now, this is the same concept as above, but this time, we are reseting him back to his original position.

M.DeathCheck()


mob/Enemies/proc/Wander(walking_delay
if(walking_delay == null) walking_delay = 5
if(walking_delay == 0)
walking_delay = 1 //0 walking delay is far too laggy, lets make it 1 if you accidently put 0.
while(src) //This means "While I am still in the world."
var/found = 0 //This we will use as sort of an "else" statement for the for proc.
for(var/mob/PC/M in oview(5))
if(M.Dynasty == src.Dynasty)
step_rand(src)
break
found = 1
step_towards(src,M)
for(var/mob/PC/Mo in oview(1))
if(M.Dynasty <> src.Dynasty)
src.Attack(M)
break
if(found == 0) //If found is still 0, or "else".
step_rand(src)
sleep(walking_delay)
Why will no one help me? I will put you in the credits, please?
Seems to be a problem with NPC's calling Attack(), or having the same dynasty values.

[Edit] Whoops, sorry. It seems you only looking at the var/mob/PC/M's in oview(5), I'm guessing your enemies aren't PC type mobs.
In response to DarkView
OMG I am so stupid, I'll try to figure it out now, if it doesnt work ill be back, thanks so much, dark.

Thanks,
Nave
In response to Nave
runtime error: Cannot execute null.DeathCheck().
proc name: Attack (/mob/Enemies/proc/Attack)
usr: Thug (/mob/Enemies/Thug)
src: Thug (/mob/Enemies/Thug)
call stack:
Thug (/mob/Enemies/Thug): Attack(null)
Thug (/mob/Enemies/Thug): Wander(5)
Thug (/mob/Enemies/Thug): New( (5,1,1) (/turf/grass))
runtime error: Cannot read null.HP
proc name: Attack (/mob/Enemies/proc/Attack)
usr: Thug (/mob/Enemies/Thug)
src: Thug (/mob/Enemies/Thug)
call stack:
Thug (/mob/Enemies/Thug): Attack(null)
Thug (/mob/Enemies/Thug): Wander(5)
Thug (/mob/Enemies/Thug): New( (5,2,1) (/turf/grass))
runtime error: Cannot read null.HP
proc name: Attack (/mob/Enemies/proc/Attack)
usr: Thug (/mob/Enemies/Thug)
src: Thug (/mob/Enemies/Thug)
call stack:
Thug (/mob/Enemies/Thug): Attack(null)
Thug (/mob/Enemies/Thug): Wander(5)
Thug (/mob/Enemies/Thug): New( (3,2,1) (/turf/grass))
runtime error: Cannot read null.HP
proc name: Attack (/mob/Enemies/proc/Attack)
usr: Thug (/mob/Enemies/Thug)
src: Thug (/mob/Enemies/Thug)
call stack:
Thug (/mob/Enemies/Thug): Attack(null)
Thug (/mob/Enemies/Thug): Wander(5)
Thug (/mob/Enemies/Thug): New( (5,4,1) (/turf/grass))



Now the NPC's do exactly what i want them to do but, I get this run time error when i start a game.....i dont know what it means.
In response to Nave
Nave wrote:
Thug (/mob/Enemies/Thug): Attack(null)

Here is your problem. I'll go back through your stuff and see if I can figure out why it's happening...

*Goes away*
*Comes back*

Ok, I'm going to need to see an updated version of the wander proc, but from what I can guess it's because you've forgot to put a if(M) before the Attack(M).