ID:273543
 
mob
Move()
spawn(src.movementdelay)
..()
mob/var/movementdelay = 2
client//I also overrode client movement...should this be in mob/Move() or is it fine here in client/Move()
Move()
if(!src.mob.MOVEMENT)
return
..()


For some odd reason, every time I try set up some sort of delay in movement I get a very weird issue my mob moves like this: --_-_-_-_-_--_-, Consider the path is supposed to be a straight line, and when I go to turn my direction, say down two squares then continue left, it jumps back and forth between moving down south and left, and just moving left without going down so it ends up jumping back and forth before it picks which it actually decides to do whether it be stay on the original square without moving down, or be on that lower square and continue moving left, Is there a proper way to do a movement delay that I'm not getting? It worked before... or I just never noticed the bug.

[second edit]

Whats a good way to do an AI Code...
Very basic demo of what I'm acctually doing for AI, but I'm wondering what would be ways to make a more efficient AI Code...

loop with while?
mob
proc
AI()
while(src)
//grab target with a loop of mobs in view
if(target.health>src.health)
src.Attack()
if(target.health<src.health)
src.Run()
Attack()
if(target in view(8))
//move towards, and see if you should still attack
//attack with either a ranged or close range attack
mob/var/tmp/run=1
mob/var/tmp/Move_Delay = 1

mob/verb/Run()
set name="Start/Stop Running"
if(!src.run)
src.run = 1
src.icon_state = ""
src<<"You start running!"
src.MoveDelay = 0.6
return
else
src.run = 0
usr.icon_state = "Walk"
src<<"You stop running, and begin to walk."
src.MoveDelay = 4
return




This is my run/walk code, I'm not sure if this is helpful for you in anyways, but it has to do with move delay so I thought you could take something from this :P.
In response to Chaorace
Thanks, I've already got something like that in my game, so It does help to see how someone else does it, its similar to mine though, but the problem is more with the movement delay its self, not with lowering or increasing the delay, it seems that since I have a delay, it screws with my movement to the extent that mob/Move() cant figure out if it wants to continue going left, or actually go down one step THEN move left like it should.
In response to King killer 113711
Bump >.>
King killer 113711 wrote:
For some odd reason, every time I try set up some sort of delay in movement I get a very weird issue [...]

Player movement control should be done in client/Move() (or the client/Direction() procs, which are the source of client/Move()). In there, disregard any movement attempts by the player while he's supposed to be unable to move.
When you do let him move and call the default function to do so, note not to discard its return value; return it forward. This isn't very important in client/Move() specifically (it is in atom/movable/Move() for example), but it's a bad practice to arbitrarily discard return values.

Whats a good way to do an AI Code...

[link]
In response to Kaioken
Okay, Thanks for the help on movement and as for the AI Help, I went and worked it into "this" Its rough, not going to keep ALL parts the same way, but is this being done in the right direction?

mob/NPC/monster
var/ai_activated = 1
var/cycle_delay = 2
var/atom/target
var/players_in_view = list()
New()
AI()
..()
proc
AI()
spawn()
while(src.ai_activated)
if(!target||isnull(target))
for(var/mob/M in oview(8))
players_in_view += M
target = pick(players_in_view)
if(!target)
world<<"No target?"
step_rand(src)
world<<"target"
else
if(target)
if(!Attack(target))
step_towards(src,target)
sleep(src.cycle_delay)
Attack(mob/M)
if(M in view(6))
world<<"[target] Far"
return 1
if(M in view(3))
world<<"[target] Close"
return 1
return 0
In response to King killer 113711
Every instance of view() and oview() should have a second argument specifying the center (src).

Additionally, picking the target should occur OUTSIDE the for() loop. As it is, you're picking a new target for each mob you see, which isn't particularly detrimental but is still silly.
In response to Garthor
Thanks garthor, I was under the assumption that it defaulted to src, but to This is the updated version
mob/NPC/monster
var/ai_activated = 1
var/cycle_delay = 2
var/atom/target
var/players_in_view = list()
New()
..()
AI()
proc
AI()
spawn()
while(src.ai_activated)
if(!target||isnull(target))
for(var/mob/M in oview(8,src))
players_in_view += M
if(length(players_in_view))
target = pick(players_in_view)
if(!target)
world<<"No target?"
step_rand(src)
world<<"target"
else
if(target)
if(!Attack(target))
step_towards(src,target)
sleep(src.cycle_delay)
Attack(mob/M)
if(M in view(6,src))
world<<"[target] Far"
return 1
if(M in view(3,src))
world<<"[target] Close"
return 1
return 0
In response to King killer 113711
After testing alot, There's still the same issue with movement...