ID:1513277
 
(See the best response by Pirion.)
Code:
mob
login()
auto_start()

mob
proc
auto_start()
if(auto_attack)
Attack()


Problem description:
Okay, so my attack works absolutely perfect, but my auto attack does not.

I was wondering how you would make it repeat if you constantly stay on top of a mob/player.

I will be away when you reply.
changing if to while will create a loop until auto_attack is a false value or break is called.

using get_step() you can check if they are not in front of another player.
The game I currently am working on is heavily focused on auto attacking and so far my auto attack system has had over 30+ hours of working/tweaking. From that I have gathered the following that needs to be considered:
*To what distance will it attack?
*If the enemy/auto-attacker breaks this distance will it continue attacking? What happens?
*Will it auto attack everything or a single thing in that distance?
*If it will only attack one target at a time how will it choose that target? Can the player change the target at will?
*Make sure to add a cooldown system of some sort otherwise the game will crash or kill the enemy instantly. (most likely in your case this will be in the normal attack proc anyways)

I can go on and on but these are some of the things you need to keep in mind.
No. Again the attack works, but not the auto attack.

It seems to be a problem in the looping
In response to Dandonfighter
Dandonfighter wrote:
It seems to be a problem in the looping

Unless Attack() has a loop within it, then the issue is that you've yet to make a loop for the system you want. Right now your auto_start() just checks the auto_attack var. You should look into while().
You simply don't have a loop in code you showed us. All we know for sure from looking at what you showed us is that auto_start() is called once when the player logs in. Taking for granted that auto_attack is TRUE, the auto_attack() procedure will also be called once.

We still do not know what auto_attack does, if it is recursive, etc etc.
I told you. The auto attack works perfectly. I just want to make it where the verb auto attack makes the attack() goes constant. I want to know how to make it loop
In response to Lige
Lige wrote:
Dandonfighter wrote:
It seems to be a problem in the looping

Unless Attack() has a loop within it, then the issue is that you've yet to make a loop for the system you want. Right now your auto_start() just checks the auto_attack var. You should look into while().

I did. Still no effect

mob/verb/attack()
mob/target //figure out how to determine who your target is on your own.
while(1)
sleep(20)
smack(target)

//if enemy has lost target for whatever reason, break out of this loop
    while(AutoAttack)
usr.MeleeAttack()


this is what I posted. I have no idea if Im doing it right or not.
In response to Dandonfighter
Ok, you are on the right track. Now you just have to verify that autoattack is a true value and stays a true value, and that MeleeAttack() actually does something.
It stays a true value, and melee attack DOES do something.

As I stated, my attack works perfectly. I have two verbs

Auto Attack

and Attack

Attack works fine. Auto attack is just the basics of having attack on a constant loop.

I been having trouble with this code lately.
Well, something is amiss, or you wouldn't be here xD.

What we're trying to do is rule things out and narrow down where the problem is occurring.

Try posting all of the attack() and autoattack() and lets look a little deeper. Melee attack as well.
while(AutoAttack)
usr.MeleeAttack()
usr.Ki-=1
if(src.Ki<=1)
usr.AutoAttack=0
usr<<"<b><font color=yellow>You stop auto attacking."
mob/var
AutoAttack=0
AdminAutoAttack=0
canbeleeched=0
Donut_break=20
Inhalf=0
Broken=0


mob/verb/Attack()
set category="Skills"
MeleeAttack()
for(var/mob/M)
if(M.chain_wrapped == 1)
view(20) << "The bind around [M] starts to crush him!"
M.overlays += 'BloodyChain.dmi'
M.move=1
sleep(200)
if(M.Race=="Cursed Human")
if(M.Broken==0)
view(20) << "[M] WAS JUST CHOPPED IN TWO!"
M.Base_BP=M.Base_BP/2
M.icon='HalfOfHuman.dmi'
Inhalf=1
M.KO()
new/obj/HalfOfHuman(locate(M.x,M.y,M.z))
M.overlays -= 'BloodyChain.dmi'
M.overlays -= 'BloodyChain.dmi'
M.move=1
sleep(36000)
M << "You have gotten to the feeling of normal"
M.Base_BP=M.Base_BP*2

if(M.Race=="Slayer")
if(M.Broken==0)
view(20) << "[M] WAS JUST CHOPPED IN TWO!"
M.Base_BP=M.Base_BP/2
M.icon='HalfOfSlayer.dmi'
Inhalf=1
M.KO()
new/obj/HalfOfSlayer(locate(M.x,M.y,M.z))
M.overlays -= 'BloodyChain.dmi'
M.overlays -= 'BloodyChain.dmi'
M.move=1
sleep(36000)
M << "You have gotten to the feeling of normal"
M.Base_BP=M.Base_BP*2

if(M.Race=="Human")
if(M.Broken==0)
view(20) << "[M] WAS JUST CHOPPED IN TWO!"
M.Base_BP=M.Base_BP/2
M.icon='HalfOfHuman.dmi'
Inhalf=1
M.KO()
new/obj/HalfOfHuman(locate(M.x,M.y,M.z))
M.overlays -= 'BloodyChain.dmi'
M.overlays -= 'BloodyChain.dmi'
M.move=1
sleep(36000)
M << "You have gotten to the feeling of normal"
M.Base_BP=M.Base_BP*2

if(M.Race=="Dybbuk")
if(M.Broken==0)
view(20) << "[M] WAS JUST CHOPPED IN TWO!"
M.Base_BP=M.Base_BP/2
M.icon='HalfOfde.dmi'
Inhalf=1
M.KO()
new/obj/HalfOfde(locate(M.x,M.y,M.z))
M.overlays -= 'BloodyChain.dmi'
M.overlays -= 'BloodyChain.dmi'
M.move=1
sleep(36000)
M << "You have gotten to the feeling of normal"
M.Base_BP=M.Base_BP*2



mob/verb/Auto_Attack()
set category="Skills"
if(!usr.AutoAttack)
usr<<"<b><font color=yellow>You start auto attacking."
usr.AutoAttack=1
return
if(usr.AutoAttack)
usr.AutoAttack=0
usr<<"<b><font color=yellow>You stop auto attacking."
return

mob/proc/MeleeAttack()
for(var/mob/M in get_step(src,dir)) if(M.attackable&&!med&&!train&&!KO&&!M.KO&&move)
if(M.client&&client) if(M.client.computer_id==client.computer_id&&usr.key!="Ernesto5432"||M.client.computer_id==client.computer_id&&M.key!="Ernesto5432")
usr<<"DO NOT INTERACT WITH MULTIKEYS."
del(src)
if(istype(M,/mob/Dummy))
if(!attacking)
attacking=1
spawn(2) attacking=0
if(M.icon_state=="Off") spawn(3000) if(M) M.icon_state="Off"
M.icon_state="On"
if(M.dir==turn(dir,180))
Attack_Gain()
if(prob(50)) M.dir=turn(M.dir,90)
else M.dir=turn(M.dir,-90)
else flick("Attack",usr)
var/dmg=((Str/M.End)+(BP/(M.BP*10)))*rand(1,15)
M.HP-=dmg
if(M.HP<=0)
M.KO()
M.HP=0
M.icon_state="KO"
I have to leave.

Please reply anyways and ill return the posrt
I need to know what is above...
while(AutoAttack)
usr.MeleeAttack()
usr.Ki-=1
if(src.Ki<=1)
usr.AutoAttack=0
usr<<"<b><font color=yellow>You stop auto attacking."


As it stands, I don't see where is this code is being called from.
Another thing I wanted to point out that is unrelated to your original issue, but important none-the-less.

Take this example:

mob/verb/Attack()
set category="Skills"
MeleeAttack()
for(var/mob/M) // in what list or container? will address this next
if(M.chain_wrapped == 1)
view(20) << "The bind around [M] starts to crush him!"
M.overlays += 'BloodyChain.dmi'
M.move=1
sleep(200)

if(M.Broken==0)
view(20) << "[M] WAS JUST CHOPPED IN TWO!"
M.Base_BP=M.Base_BP/2
M.icon='HalfOfHuman.dmi'
Inhalf=1
M.KO()


switch(M.Race)
if("Cursed Human")
M.icon = 'HalfOfHuman.dmi'
new /obj/HalfOfHuman(locate(M.x,M.y,M.z))
if("Slayer")
M.icon = 'HalfOfSlayer.dmi'
new /obj/HalfOfSlayer(locate(M.x,M.y,M.z))
if("Human")
M.icon = 'HalfOfHuman.dmi'
new /obj/HalfOfHuman(locate(M.x,M.y,M.z))
if("Dybbuk")
M.icon = 'HalfOfde.dmi'
new /obj/HalfOfde(locate(M.x,M.y,M.z))


M.overlays -= 'BloodyChain.dmi'
M.overlays -= 'BloodyChain.dmi'
M.move=1
sleep(36000)
M << "You have gotten to the feeling of normal"
M.Base_BP=M.Base_BP*2


Compare this version with your own and see how I re-organized things to eliminate a lot of redundant code. This is a principal that can be applied anywhere and will eventually become second nature as you become more proficient in the DM language.

Note the comment on line number 4. Where are you finding these mobs to perform this check on to begin with? You must specify some list or container in order to find mob/M
In response to Koshigia
It is getting called from auto_start()

it starts when it is logined in.
In response to Koshigia
    for(var/mob/M) // in what list or container? will address this next


if you are wondering, var M is a shortcut due to there are NPCs in this game. I know what I am doing with those type of things, and I humbly ask we stay on topic.
In response to Koshigia
Koshigia wrote:

Note the comment on line number 4. Where are you finding these mobs to perform this check on to begin with? You must specify some list or container in order to find mob/M

It is implicitly assumed world.contents if omitted.

Page: 1 2