ID:141828
 
Code:
mob
hollows
Weak_Hollow
icon='hollows.dmi'
name="Weak Hollow"
race="Hollow"
mhp = 50
hp = 50
rei = 50
mrei = 50
strength = 7
defence = 7
reiatsu = 7
npchollow = 1
player = 0
firing = 0
proc/Battle()
for(var/mob/A in get_step(src,src.dir))
if(src.firing == 1)
sleep(40)
src.firing = 0
else
var/damage = src.strength * 1.2 / A.defence
A.hp -= damage
A << "[src] attacks you for [damage] damage!!"
src<<"You attack [A] for [damage] damage!!"
DeathCheck(A)
src.firing = 1
sleep(15)
New()
walk_rand(src,12)
. = ..()
AI()
proc
AI()
while(src)
var/c = 0
for(var/mob/M in oview(3,src))
if(M.client)
c = 1
if(c)
for(var/mob/M in oview(2,src))
if(M.client)
step_towards(src,M)
else
walk(src,0)
sleep(10)
Bump(mob/M)
if(M in oview (1))
src.canattack = 0
Battle(M)


Problem description:
hmm well , i can only get it to stand still and attack in oview or i can get it to walk randomly. but when i try to make it walk randomly then attack when the player is in its view it just walks around and ignores the AI, so what im asking is i guess, how can i make both work at once ive tried like 3-5 different ways but they end up only taking 1 action as well, any help with this will be appriciated
Dude, stop spamming the same issue.

mob
hollows
Weak_Hollow


New()
//this line is not neccesary
. = ..() // lets do default operations
spawn()AI()

Bump(mob/M)
/* if(M in oview (1))why check for a M in the oview(1) after the AI bumped
some already, by the way oview(1,src)) so it doesnt count the src in the oview


src.canattack = 0
Battle(M)
why sending the M to the battle proc if you arent even reciving it ?

*/

if(ismob(M)&& TARGET == M)
Battle() // just that would be much better
var
TARGET = ""

proc
Battle()

var/mob/A=locate() in get_step(src,src.dir)
if(src.firing) // == 1 is not needed
//why shouldn't attack like that >,<
return // no no you are attacking already
else
var/damage = src.strength * 1.2 / A.defence
A.hp -= damage
A << "[src] attacks you for [damage] damage!!"
src<<"You attack [A] for [damage] damage!!"
DeathCheck(A)
src.firing = 1
sleep(15)
src.firing = 0
AI()

while(src)

for(var/mob/M in oview(8,src))
if(M.client&&!TARGET)
TARGET = M//we got a target *YAY*
if(TARGET)//we got a target
//pretty bad
step_towards(src,TARGET)//lets walk to our target
else
step_rand(src) //if we got no target lets move randomize
sleep(3) //that's enough to break our infinite loop
In response to Danny Kenobi
Thank you alot , im sorry for spamming it but either no one would help , i recoded it, or some Panzy would just tell me to go read the DM Guide even though ive read it 13 times
In response to Sasuke3232
or some Panzy would just tell me to go read the DM Guide even though ive read it 13 times

That must have taken a really long time.
Very often people post code on these forums looking for help to get it working, but the way that they're trying to go about solving the problem will never work. Someone trying to help will see that we can fix the code, so they suggest that the person recode it, or "read the guide".

Unfortunately, what's developed is that we now have a group of people who, the moment they see code that doesn't work regardless of the reason, will rush in and yell "read the guide". The problem is that they don't take the time or effort to figure out what the programmer is trying to do, where they went wrong, and what the fundamental problem is.

...

On to your post. You've got a lot going on here; some of it makes sense, some of it isn't working together right, and some of it I can't understand.

To start with, you've got a Battle() proc which you're using to make the enemy attack. You're calling that proc from Bump() and supplying it with an argument (M) so that Battle() knows who to attack. However, when you define Battle(), you didn't define it to accept an argument, so you then have to find the person to attack by doing that whole "for(mob/A in get_step())" thing. It would be easier to to accept the argument that you're passing in Bump():

proc/Battle(mob/target)
if(src.firing)
// etc.


...

The main problem here, though, is the two different calls to walking functions. In New() you call walk_rand() to make the enemy walk around. However, in the AI() proc you also have a call to a walk function: walk(src,0)
That cancels any other walking procs. That's why the AI() and walk_rand() procs don't work together.

I would restructure this system. I'd call AI() in new, like you're already doing, but I wouldn't call walk_rand(). Instead, I'd do something like the following:

enemy
var
movement_speed = 10 // One movement every 1 second
New()
. = ..()
behavior() // That's the proc I use instead of AI
proc
behavior()
find a target in view
if(target)
step towards it // maybe even bump into it
else
step randomly
spawn(movement_speed)
behavior()


That behavior proc defines a loop just like the "while(src)" loop that you made, only here the loop is called a "recursive function", which means that it's a function that calls itself.

...

On the Dream Makers site there's an article called Where Do I Put My Code which has an example very similar to this at the end (how to make an enemy move and attack). You may find it helpful to read that.