ID:647362
 
Keywords: ai, coding, help, npc, walking
Code:
mob
Wondering_Seed_Salesman
icon = 'NPCs.dmi'
icon_state = "Salesman"
name = "{NPC}Traveling Seed Salesman"
verb
Talk()
set category = "NPC's"
set src in oview(2)
switch(input("Would you like to trade some gold for seeds?", text) in list ("Yes","No"))
if("Yes")
if(usr.gold >= 50)
usr << "Alrighty, it was nice doing business with you!"
usr << "Come back anytime, okay?"
usr.gotseeds += 5
if(usr.gold <= 49)
usr << "Sorry buddy, Standard price is 50 gold, go kill some wolves or something"
else
return


Problem description:

I need to get this guy to walk back and forth in a straight line.

I don't want him to walk around the map randomly, just up and down the road.

I have tried making different procs to try to get things to move in a straight line, but I can't get them to actually move. Could anyone please help me out?
Look up step use attributes such as

NORTH
SOUTH
WEST
EAST etc

Create a type of path finding procedure.

Search the resources or forums.
proc
Path_set(var/atom/movable/M, list/sequence, delay = 10, distance = 1, Rand_step_interval = 0, loop = 0)
var/valid = list(NORTH, SOUTH, EAST, WEST, NORTHWEST, SOUTHEAST, NORTHEAST ,SOUTHWEST)
var/list/path = list()
var/list/rand_sequence = list()
do
rand_sequence = list(null)
path = list(null)
if(length(sequence) < 1)
while(length(rand_sequence) <4)
var/N = pick(NORTH, SOUTH, EAST, WEST)
rand_sequence += N
sleep(1)

if(Rand_step_interval && delay <5)
delay = 5
if(length(sequence) < 1)
for(var/P in rand_sequence)
path += P
else
for(var/P in sequence)
path += P

for(var/D in path)
if(D in valid)
var/repeats = round(distance*32/M.step_size)
while(repeats > 0)
step(M, D)
sleep(1)
repeats --
if(Rand_step_interval)
sleep(rand(delay-5,delay+5))
else
sleep(delay)
while(loop)

mob
verb
StartCutScene()
set background=1
var/mob/Wondering_Seed_Salesman = /mob/Wondering_Seed_Salesman
for(var/mob/m in world)
if(istype(m, Wondering_Seed_Salesman))
Path_set(m, list(EAST, WEST), 1, 15, 0, 1)


mob
Wondering_Seed_Salesman
icon = 'basedemon.dmi'
icon_state = "salesman"
name = "{NPC}Traveling Seed Salesman"
npc = 0
cantdie = 1
verb
Talk()
set category = "NPC's"
set src in oview(2)
switch(input("Would you like to tade some trade some gold for seeds?", text) in list ("Yes","No"))
if("Yes")
if(usr.gold >= 50)
usr << "Alrighty, it was nice doing business with you!"
usr << "Come back anytime, okay?"
usr.gotseeds += 5
if(usr.gold <= 49)
usr << "Sorry buddy, Standard price is 50 gold, go kill some wolves or something"
else
return


I found this in the resources and set it up for him... With the verb I can get him to walk back and forth once, how ever if I try and set it to loop it doesn't do anything at all.

I have tried making it a proc and making it start up with the game, log in, verbs, every time the same problem happens, if I don't have it looping it will go once, but if I try and loop it so he is always walking back and forth nothing happens.

I tried
Path_set(m, list(EAST, WEST),  1, 15,  0, 1)

like the resource said, and it works in the resource demo. but mine only works if the last 1 is 0... Then it wont work, So I tried hooking the proc inside it's self like an auto save, but that made it not walk at all again, same with a goto. I tried setting it to background and setting the loop checks to 0. And it is always the same result. If it's not looping it works fine, as soon as I try to loop it in anyway it stops working all together, Any ideas?
Do you think I would be able to get away with making like... a pressure plate at the start of his walk. so when he returns he triggers the plate to make the proc run again? or is there a simpler way I am just missing...
Okay, In case anyone else finds this and has a similar problem making a cross turf with the StartCutScene proc effect worked, as long as nothing blocks his path he will/should keep walking in his pattern around the path :) Thanks for the help and if anyone wants the original stuff I used it is from GreatFisher and it is called "Path_set Library".
atom/movable/proc/Path_Set(delay,list/movement,repeat)
do
for(var/i=1,i<=movement.len,i++)
var/check1="[src.x][src.y][src.z]"
sleep(delay)
step(src,movement[i])
var/check2="[src.x][src.y][src.z]"
if(check1==check2)i--
while(repeat)

client/New()
..()
mob.icon='demo.dmi'
mob.icon_state="mob"
mob.loc=locate(5,5,1)

turf
Grass
icon='demo.dmi'
icon_state="turf"

mob/NPC
icon='demo.dmi'
icon_state="mob"
New()
spawn(1)src.Path_Set(delay=5,movement=list(NORTH,EAST,SOUTH,WEST),repeat=1)