ID:1260641
 
(See the best response by Lugia319.)
Code:
I think I almost have my code working.
it is an auto attack code that makes if you walk in front of a mob it starts attacking.

 mob
verb
Auto_Attack()
set category = "Skills"
if(auto_attack == 0)
src << "You are now auto-attacking."
auto_attack = 1
if(auto_attack == 1)
src << "You are no longer auto-attacking."
auto_attack = 0


Bump(mob/M)
var/autodamage = powerlevel/2
if(auto_attack == 1)
if(istype(M,/mob))
flick("attack",usr)
M << "[text]"
usr << "\red You hit [M]"
M.attacker = src.name
M.powerlevel -= autodamage
M.DeathCheck(src)
usr.cooldown = 1
spawn(usr.speed * 2) usr.cooldown = 0




if(auto_attack == 0)
return


Problem description:

I know whats going on in my code, but every time I turn it on, it turns right off.
--------------------------------------
(Example)
"You are now auto-attacking."
"You are no longer auto-attacking."
---------------------------------------

So can someone tell me how I can make it work. I got it from here, and I'm going to work on it until someone reply, Thanks ahead of the time for the help :D



Simple answer: your two if statements in auto attack should be an if/else.
Best response
Let's have a little lesson in computational logic. First, the simplest case

var/X = 0 // Set X to 0
X += 1 // Add 1 to X
X += 2 // Add 2 to X
src << "X = [X]" // X = 3


This is read straight down. Let's take a look at what happens when you call procs

var/X = 0
X += 1 // Add 1 to X
X = AddTwo(X) // Do AddTwo with X as the argument
src << "X = [X]" // X = 3

AddTwo(AddTo as num)
AddTo += 2 // Add 2 to the argument
return AddTo // Return the number


Control was shifted over the proc, but it kept reading down the line afterwards. Now let's look at your code.

 mob
verb
Auto_Attack() // Auto attack verb
set category = "Skills"
if(auto_attack == 0) // If you're not auto attacking
src << "You are now auto-attacking."
auto_attack = 1 // Set auto-attack to 1
// Now when this line completes, it'll go to the next line outside the if()
if(auto_attack == 1) // If your'e auto attacking
// You are auto attacking because you set auto attack to 1 in the previous line.
src << "You are no longer auto-attacking."
auto_attack = 0 // Stop auto attacking

A return statement would fix this, no sweats. Or an else.
In response to Lugia319
Well, Now it won't attack when I run into him, is something wrong with the bump?
In response to TheScatman95
Heres a small alteration for you, Also if a certain thing isnt working and you are unsure why and think you can debug it yourself, throw in some simple world << "DBG Stage 1" etc etc inside the code, if one of those msgs dont show up then you know whats causing the problem
mob
verb
Auto_Attack() //Instead of making this do == checks you can also do !auto_attack which means if its 0 it makes it 1 otherwise make it 0.
set category = "Skills"
if(!auto_attack)
src << "You are now auto-attacking."
auto_attack = 1
else
src << "You are no longer auto-attacking."
auto_attack = 0


Bump(mob/M)
var/autodamage = powerlevel/2
if(auto_attack && istype(M,/mob)) //First it will check for auto attack, then make sure its a mob they be bumping.
flick("attack",usr)
M << "[text]"
usr << "\red You hit [M]"
M.attacker = src.name
M.powerlevel -= autodamage
M.DeathCheck(src)
usr.cooldown = 1
spawn(usr.speed * 2) usr.cooldown = 0
else ..() //If they arnt autoattacking then we want them to continue the normal bump proc
I used the code you just gave me, but it STILL wont attack im when he bumps into him. Is there a problem in the bump code?
In response to TheScatman95
It's possible you defined Bump() somewhere else and didn't call ..().
In response to Kaiochao
Is there a solution? Do I place the code somewhere else?
In response to TheScatman95
Just check if there's other mob/Bump()s in your code and stick a ..() in it that will get called when it should be.
In response to Kaiochao
At the end of the other bump ocdes?
Okay, I did that, BUT IT STILL wont work.

What gives? Why wont it just hit the guy with a bump? Where is the problem. can you guys help?
Can you show us your current code?
In response to Super Saiyan X
it is Midgetbuster's code that he posted

In response to TheScatman95
I don't think this is the problem, but usr isn't used in Bump() as the only objects involved are src (the mover) and the obstacle in the arguments. You could try replacing usr with src in Bump.
Still didnt work....
and us should stay on the statment, because the usr should be getting the message, NOT the obj.
What else could be the problem?
In response to TheScatman95
What? What do you think usr means? The object that bumps into the enemy is always src. Using usr here isn't proper.

Note that "object" is a general term for all datums, atoms, etc.

I didn't think that was the cause of this particular problem, though, although abusing 'usr' can cause problems in the future. I think we need to see more of the code.
The code miget-buster provided is solid and Kaio is correct in the usr over src thing.

You should take a look inside your deathcheck proc or provide that here.

In response to Jittai
mob/proc/DeathCheck()
if(src.powerlevel <= 0 && !src.race == "Majin")
world<<"<b>[src] has died!</b>"
src.loc=locate(0,0,0)
dead = 1
demi = 0
leveled = 0
sleep(70)
overlays += 'halo.dmi'
loc=locate(100,100,3)
src<<"<b>Welcome to Afterlife...."
src.powerlevel=src.powerlevel_max

if(src.race == "Majin" && src.powerlevel >= -100 && src.powerlevel <= 0)
loc=locate(100,100,3)
src<<"You will regenrate in 2 mins"
sleep(20000)
usr.loc=locate(1,1,1)
else
if(powerlevel <= -100)
world<<"<b>[src] has died!</b>"
src.loc=locate(0,0,0)
dead = 1
demi = 0
leveled = 0
sleep(70)
overlays += 'halo.dmi'
loc=locate(100,100,3)
src<<"<b>Welcome to Afterlife...."
src.powerlevel=src.powerlevel_max


This has nothing to do with my current problem, for if I cant get the code to even work, then I cant even call the deathcheck up.



You should make those sleeps spawn()? That can cause issues, I don't think it is causing the current one- but the code works on my demo and the only thing that was different was the death proc.
Page: 1 2