ID:2340256
 
im currently creating a clone jutsu and in this code i make the clone follow the user and looking for a target because i want my clone to attack the mob around.
everything work but when he start run after a mob he stop after 2 sec and he restart run after the mob and he do the same thing when he follow me this is the code.
thanks you for all
Code:
    proc
WCloneAi(GAME_MOB/owner, GAME_MOB/clone)
if(owner&&clone)
spawn()
sleep(1)
icon = 'Art/Jutsus/Water Element/Water Bunshin.dmi'
flick("form",clone)
sleep(5)
walk(clone,0)
clone.m_health = owner.m_health/2
clone.health = owner.health/2
clone.appearance = owner.appearance
clone.is_a_water_clone = 1
while(clone)
if(!owner)
del(clone)
if(followuser)
clone.icon_state = "run"
step_to(src,usr,2,0) //here where he follow the user
if(clone.Ctarget)
clone.Clonecombat() ///here if he found a target he go to the proc
followuser = FALSE
if(!clone.Ctarget)
clone.CLookForTarget() /// here if he don't found a target he will search again
followuser = TRUE
sleep(world.tick_lag)
sleep(rand(15,27))



proc
CLookForTarget() //// search target proc
if(src.targetlook == FALSE && !src.Ctarget && !src.dead)
targetlook = TRUE
for(var/GAME_MOB/mob in obounds(src,640))
if(mob && !mob.dead && !Ctarget && mob.village != src.village && !istype(mob,/STORE) && mob.level>9)
src.Ctarget = mob
targetlook = FALSE


Problem description:

sleep(rand(15,27))


Your code is telling it to sleep for about 2 seconds every iteration.

Ditch that line.

Also, you probably shouldn't be using usr like this:

if(followuser)
clone.icon_state = "run"
step_to(src,usr,2,0) //here where he follow the user


You should be using owner instead of usr, as you are already storing the clone's owner, and usr is potentially unsafe.
But if i remove sleep i will just run after me and hit me he dont restart following me. the clone are suppose to follow me and when he find a target he go after the target and attack it and if the target is down is suppose to begin the follow me again
This nonsense right here
                    sleep(1)
icon = 'Art/Jutsus/Water Element/Water Bunshin.dmi'
flick("form",clone)
sleep(5)
walk(clone,0)
clone.m_health = owner.m_health/2
clone.health = owner.health/2
clone.appearance = owner.appearance
clone.is_a_water_clone = 1 //to be perfectly honest, its typing should determine this already; it's an unnecessary variable

...belongs in a constructor (aka New() ); not in an AI proc. Properly structuring your code is a basic fundamental that will help you in the long run.

But anyways. I assume your Clonecombat() proc handles the clone following its target and attacking them? Because based on your issue, that's most likely the proc that's the source of your problem(s). And is the one piece of code you did not give us to look at. No where in the code you provided, do I see a step() or step_to() the clone's target.

I'm also noticing your HUGE obounds size (640! o.O). I'm just going to copypasta this little snippet from the step_to() proc in Dream Maker's reference (F1 in Dream Maker).

"Move Ref on a path to the location Trg, taking obstacles into account. If Ref is within Min steps of Trg, no action will be taken. This is also the case if the target is too far away (more than twice world.view steps)."
In response to Carcanox32
Carcanox32 wrote:
But if i remove sleep i will just run after me and hit me he dont restart following me. the clone are suppose to follow me and when he find a target he go after the target and attack it and if the target is down is suppose to begin the follow me again


Removing the two second sleep will not change the logic flow at all. It will simply remove the 2 second wait you are complaining about. That's all removing that will change.
In response to Ter13
Ter13 wrote:
Carcanox32 wrote:
But if i remove sleep i will just run after me and hit me he dont restart following me. the clone are suppose to follow me and when he find a target he go after the target and attack it and if the target is down is suppose to begin the follow me again

Removing the two second sleep will not change the logic flow at all. It will simply remove the 2 second wait you are complaining about. That's all removing that will change.



Yeah it work it the 2 sec are gone so i think the problems is something else
In response to Spunky_Girl
Spunky_Girl wrote:
This nonsense right here
>                     sleep(1)
> icon = 'Art/Jutsus/Water Element/Water Bunshin.dmi'
> flick("form",clone)
> sleep(5)
> walk(clone,0)
> clone.m_health = owner.m_health/2
> clone.health = owner.health/2
> clone.appearance = owner.appearance
> clone.is_a_water_clone = 1 //to be perfectly honest, its typing should determine this already; it's an unnecessary variable
>

...belongs in a constructor (aka New() ); not in an AI proc. Properly structuring your code is a basic fundamental that will help you in the long run.

But anyways. I assume your Clonecombat() proc handles the clone following its target and attacking them? Because based on your issue, that's most likely the proc that's the source of your problem(s). And is the one piece of code you did not give us to look at. No where in the code you provided, do I see a step() or step_to() the clone's target.

I'm also noticing your HUGE obounds size (640! o.O). I'm just going to copypasta this little snippet from the step_to() proc in Dream Maker's reference (F1 in Dream Maker).

"Move Ref on a path to the location Trg, taking obstacles into account. If Ref is within Min steps of Trg, no action will be taken. This is also the case if the target is too far away (more than twice world.view steps)."


Yeah the is a clone var it only a undefined var that i did not remove