ID:155877
 
    New()
..()
spawn while(src)
sleep(rand(15,18))
var/mob/target
target=locate(/mob/player) in oview(7,src)
if(target)
if(src.aggresive)
while(target in oview(7))
if(target.x == src.x&&target.y != src.y && target.y > src.y) step(src,NORTH)
else if(target.x == src.x&&target.y != src.y && target.y < src.y) step(src,SOUTH)
else if(target.x != src.x&&target.y == src.y && target.x < src.x) step(src,WEST)
else if(target.x != src.x&&target.y == src.y && target.x > src.x) step(src,EAST)
else if(target.x> src.x&&target.y > src.y)
switch(rand(1,2))
if(1) step(src,EAST)
if(2) step(src,NORTH)
else if(target.x < src.x && target.y < src.y)
switch(rand(1,2))
if(1) step(src,WEST)
if(2) step(src,SOUTH)
else if(target.x < src.x&&target.y > src.y)
switch(rand(1,2))
if(1) step(src,WEST)
if(2) step(src,NORTH)
else if(target.x > src.x && target.y < src.y)
switch(rand(1,2))
if(1) step(src,EAST)
if(2) step(src,SOUTH)
else
switch(rand(1,4))
if(1) step(src,NORTH)
if(2) step(src,SOUTH)
if(3) step(src,EAST)
if(4) step(src,WEST)


That`s my AI system.
I wan`t to make that when targeting(players) 5 - 1 step in front of him, NPC turns to him and stop walking. If target(player) move the NPC will follow him untill he is not facing him 5 steps or 1 step infront of him.

P.S

I am not asking how to make this code better.And ty for reading and helping
LaNuiit wrote:
That`s my AI system.

And it's Zeta, and it's horrid.
You've most likely no idea what you are doing, and looking at your older post, I'd dearly recommend just starting from absolute scratch. Like, from here.
In response to Emasym
Emasym wrote:
LaNuiit wrote:
That`s my AI system.

And it's Zeta, and it's horrid.
You've most likely no idea what you are doing, and looking at your older post, I'd dearly recommend just starting from absolute scratch. Like, from here.

Lawl, thats not the answer i was looking for.
Uh, have you looked into step_towards() and getting the target's facing direction to decide where to move your AI to?

Like if target is facing WEST, step_towards(location in front of target's direction).

It's mostly getting the target and the AI's direction that you're comparing and using step_towards().

Also, one thing I suggest you test is having multiple targets for the AI first, because... your current code looks like your AI will step to different targets rather then sticking to one.
In response to HolyDoomKnight
HolyDoomKnight wrote:
Uh, have you looked into step_towards() and getting the target's facing direction to decide where to move your AI to?

Like if target is facing WEST, step_towards(location in front of target's direction).

It's mostly getting the target and the AI's direction that you're comparing and using step_towards().

Also, one thing I suggest you test is having multiple targets for the AI first, because... your current code looks like your AI will step to different targets rather then sticking to one.

here is my full code so it will be more understandable:
    New()
..()
spawn while(src)
sleep(rand(15,18))
var/mob/target
target=locate(/mob/player) in oview(7,src)
if(target)
if(src.aggresive)
while(target in oview(7))
if(target.x == src.x&&target.y != src.y && target.y > src.y) step(src,NORTH)
else if(target.x == src.x&&target.y != src.y && target.y < src.y) step(src,SOUTH)
else if(target.x != src.x&&target.y == src.y && target.x < src.x) step(src,WEST)
else if(target.x != src.x&&target.y == src.y && target.x > src.x) step(src,EAST)
else if(target.x> src.x&&target.y > src.y)
switch(rand(1,2))
if(1) step(src,EAST)
if(2) step(src,NORTH)
else if(target.x < src.x && target.y < src.y)
switch(rand(1,2))
if(1) step(src,WEST)
if(2) step(src,SOUTH)
else if(target.x < src.x&&target.y > src.y)
switch(rand(1,2))
if(1) step(src,WEST)
if(2) step(src,NORTH)
else if(target.x > src.x && target.y < src.y)
switch(rand(1,2))
if(1) step(src,EAST)
if(2) step(src,SOUTH)
var/mob/b = ""
if(src.dir==NORTH && target.y == src.y +1 &&target.x == src.x) b = target
else if(src.dir==SOUTH && target.y==src.y -1 &&target.x == src.x) b = target
else if(src.dir==WEST && target.x == src.x -1 &&target.y == src.y) b = target
else if(src.dir==EAST && target.x == src.x +1 &&target.y == src.y) b = target
if(b != "")
var/d = src.strength * 500
d = d - target.defense * 500
if(d > 0)
if(d >= 1)
view(b)<<"<font color=red>[src] hits [b] for [cn(d)] power"
b.powerlevel -= d
else
view(b)<<"[b] resists [src]'s attack"


if(b.powerlevel <= 0)
b.overlays += 'Halo.dmi'
b.powerlevel = b.maxpowerlevel
b.ki = b.maxki
b.stamina = b.maxstamina
b.deaths ++
b.dead = 1
b.zenni = 0
b.safezone = 0
b.flying = 0
b.icon_state = ""
b.underlays = null
b.density = TRUE
world<<output("<font color=green>[target]</font color> was killed by <font color=red>[src]","Chat")
b.loc = locate(210,1,2)
else
if(d >= 1)
view(b)<<"<font color=red>[src] hits [b] for [cn(d)] power"
b.powerlevel -= d
else
view(b)<<"[b] resists [src]'s attack"
b.powerlevel-=1
if(b.powerlevel <= 0)
b.powerlevel = b.maxpowerlevel
b.ki = b.maxki
b.stamina = b.maxstamina
b.overlays += 'Halo.dmi'
b.deaths ++
b.dead = 1
b.zenni = 0
b.safezone = 0
b.flying = 0
b.underlays = null
b.icon_state = ""
b.density = TRUE
world<<output("<font color=green>[target]</font color> was killed by <font color=red>[src]","Chat")
b.loc = locate(210,1,2)
sleep(6)
else
switch(rand(1,4))
if(1) step(src,NORTH)
if(2) step(src,SOUTH)
if(3) step(src,EAST)
if(4) step(src,WEST)
else
switch(rand(1,4))
if(1) step(src,NORTH)
if(2) step(src,SOUTH)
if(3) step(src,EAST)
if(4) step(src,WEST)
Shouldn't "while(target in oview(7))" be "while(target in oview(7,src))"?
In response to LaNuiit
Yeah, posting the rest of the code that's not related to what you're trying to solve doesn't entirely help.

LaNuiit wrote:
...
I wan`t to make that when targeting(players) 5 - 1 step in front of him, NPC turns to him and stop walking.

I'm assuming you want your NPC to face the player when they stopped moving.
You can look into get_dir() to get the direction from NPC to target player.

If target(player) move the NPC will follow him untill he is not facing him 5 steps or 1 step infront of him.

From this, I'm assuming you want your NPC to follow your target play until the player breaks line of sight or is directly in front of the NPC.
Which can be by checking the tiles between the NPC's location and at the end of the NPC's view range.
Where from there you can use step_towards() to move your NPC to target location or call step() within a for loop.

You can use get_dist() to calculate the distance between the NPC and target and use a check to see if the NPC is 1 tile away from the target.

...
In response to Immibis
Immibis wrote:
Shouldn't "while(target in oview(7))" be "while(target in oview(7,src))"?

No.The code works fine.
In response to LaNuiit
oview defaults to using usr for the second parameter, and you should never use usr in a proc unless you're sure it's safe. usr is set to the mob in this proc, for some reason which isn't documented and therefore could change in any update...

If the code works fine why are you posting for help?

Also, I tested the code and found that it freezes the server without a sleep() call inside the "while(target in oview(7))" loop.
In response to Immibis
Immibis wrote:
oview defaults to using usr for the second parameter, and you should never use usr in a proc unless you're sure it's safe. usr is set to the mob in this proc, for some reason which isn't documented and therefore could change in any update...

If the code works fine why are you posting for help?

Also, I tested the code and found that it freezes the server without a sleep() call inside the "while(target in oview(7))" loop.

Thats was my question :

"I wan`t to make that when targeting(players) 5 - 1 step in front of him, NPC turns to him and stop walking. If target(player) move the NPC will follow him untill he is not facing him 5 steps or 1 step infront of him."
In response to LaNuiit
Those two things are completely unrelated.