ID:179790
 
Small part of my code :

mob/monsters
typechar = "monsters"

proc
monsterattack(mob/M in oview(1))
if(M == null)
return 0
if(src.attack - M.defense > 0)
M.hp -= src.attack - M.defense
M.DeathCheck()
else
M << "[src.name] is harmless!"

I didn't put the code about the monsters moving randomly
and then following me, because it works.
The problem is that the monsters can't seem to be able to
hit me even once. I tried looking at some other tutorials
and i see stuff like LifeCycle and action_taken.
Am i missing something ?


sure, i can help. your movement works, so you are on the right path. you got the movement to start in the monsters new() proc, right? well thats were you get them to attack too.

when your monster goes to move, it should check if there is a hostile mob nearby. if so, (and this happens inside new) activate the attack proc, instead of moving.

good luck!
In response to Ernie Dirt
Maybe i should have posted all of the code...
Here it is :

mob/monsters
typechar = "monster"
var
walkspeed
warspeed

New()
wander()
checkarea()
proc
wander()
walk_rand(src,walkspeed)
checkarea()
for(var/mob/M in oview(4))
if(M == null)
return 0
if(M.typechar == "normal")
walk_t(src,M,0,warspeed)
monsterattack()
spawn(30)
checkarea()

(See previous post for the rest)

I tried some new things, but all those monsters do is follow me around without harming me.


In response to Cravens
if(src.attack - M.defense > 0)

This is just a thought, but instead of having 'if' try 'else if' . Not sure, but its worth a try.
In response to Cravens
Cravens wrote:

New()
<FONT color = red> wander() </Font>
checkarea()

proc
wander()
<FONT color = red> walk_rand(src,walkspeed) </FONT>
checkarea()
for(var/mob/M in oview(4))
if(M == null)
return 0
if(M.typechar == "normal")
walk_t(src,M,0,warspeed)
monsterattack()
spawn(30)
checkarea()
See the red areas? Thats were the problem is, as far as I can see. walk_rand is continuous, so the monsters will walk around forever. the code never reaches checkarea().

To take a single random step use step_rand. This will step once and then checkarea() will execute.

I will watch my pager until 2:30MST, if you want to talk.
Cravens wrote:
proc
monsterattack(mob/M in oview(1))
if(M == null)
return 0

This is going to be a problem too, as oview(1) really means oview(1,usr), where usr probably isn't the same as src (the attacking monster). Instead, you should probably do this:
proc
monsterattack(mob/M)
if(M == null) return 0
if(get_dist(M,src) > 1) return 0
...

That ought to work better.

Lummox JR
In response to SkullMan
Alright, here's both of the code (from my previous posts):

mob/monsters
typechar = "monster"
var
walkspeed
warspeed

New()
wander()
checkarea()
proc
wander()
walk_rand(src,walkspeed)
checkarea()
for(var/mob/M in oview(4))
if(M == null)
return 0
if(M.typechar == "normal")
walk_t(src,M,0,warspeed)
monsterattack()
spawn(30)
checkarea()
monsterattack(mob/M)
if(M == null) return 0
if(get_dist(M,src) > 1) return 0
if(src.attack - M.defense > 0)
M.hp -= src.attack - M.defense
M.DeathCheck()
else
M << "[src.name] is harmless!"

The monsters walks randomly, they can see and follow me, then they run in circles around me BUT they can't hit even once.
The monsterattack() doesn't seem to work.
Any idea ?

Thx





In response to Cravens
Cravens wrote:
monsterattack(mob/M in oview(1))
if(M == null) return 0
if(get_dist(M,src) > 1) return 0

The monsters walks randomly, they can see and follow me, then they run in circles around me BUT they can't hit even once.
The monsterattack() doesn't seem to work.
Any idea ?

You modified monsterattack(), I see, but you forgot to take out the useless "in oview(1)" line. That probably doesn't help matters.

Lummox JR
In response to Cravens
Cravens wrote:

monsterattack(mob/M)
if(M == null) return 0
if(get_dist(M,src) > 1) return 0
if(src.attack - M.defense > 0)
M.hp -= src.attack - M.defense
M.DeathCheck()
else
M << "[src.name] is harmless!"

One thing I always do when I'm having a problem like this is add in some world outputs to see where the program is not doing what I expect.

monsterattack(mob/M)
<font color = red>world << "start monsterattack, M = [M]" </font>// Just to make sure it gets here, and if it does, what is M's value
if(M == null) return 0
<font color = red>world << "M <> null"</font> // if we got here, M isn't null. I think this part may be your problem
if(get_dist(M,src) > 1) return 0
<font color = red>world << "dist [get_dist(M,src)]"</font> // just so you can see what showed up here
if(src.attack - M.defense > 0)// this could also be your problem.. what are the attack and defense values.. maybe attack-defense isn't greater than 0
M.hp -= src.attack - M.defense
M.DeathCheck()
<font color = red>world << "src.attack [src.attack], M.defense [M.defense]" </font>
else
M << "[src.name] is harmless!"

Something along this line. This will give you an idea of where the proc is bailing, and what some of the values are when it does. If you can't figure it out from there, this might give you some more information to give the people here.

If you are ever playing one of my games (assuming I ever finish one) and you get some random information like this... this is why :) I forget to take them back out on occasion. I believe you can do these to world.log, but I havent actually used these yet.


In response to Flick
Thanks Flick.

Now it seems to be stuck on the first output:
world << "start monsterattack, M = [M]"

and when i play and the a monster starts running after me, it says this :
start monsterattack, M =

I think it doesn't know what kind of mob is attacking...

Here's my monster stats code:
mob/monsters
Bug
attack = 3
defense = 2
walkspeed = 20
warspeed = 6
contents = newlist (/obj/swords/Blade)

I still need help with this...
In response to Cravens
Cravens wrote:
Thanks Flick.

Now it seems to be stuck on the first output:
world << "start monsterattack, M = [M]"

and when i play and the a monster starts running after me, it says this :
start monsterattack, M =

I think it doesn't know what kind of mob is attacking...
Exactly! :)
You notice that it didn't show any of the other 'world << stuff' items either. Thats because it got to the 'if(M == null) return 0 and M did so it returned. What you are going to need to do is to tell monsterattack() what M is. Go back to your checkarea() proc:

checkarea()
for(var/mob/M in oview(4))
if(M == null)
return 0
if(M.typechar == "normal")
walk_t(src,M,0,warspeed)
monsterattack(<font color=red>M</font>)

That should solve your immediate problem. I think there are going to be a couple more.

You might wan't to eliminate the:
if(M== null)
return 0
part of your checkarea() proc. Think about what would happen if M did equal null. Would checkarea() ever get called again? However, I don't think M could = null as you are for looping through the mobs that do exist in your oview(4).

Also, what if there are 4 mobs in oview(4)? Your critter is gonna be busy. :)

Good Luck

flick()