ID:149285
 
We're having problems with this code, it's supposed to make to make you invulerable for a few seconds to attacks, the problem is, it makes you invincible forever and not just the few seconds. Here's the code:

obj/Ward
icon='ward.dmi'
icon_state="Moving"

obj/overlays
WardEnd
icon='ward.dmi'
icon_state="Ward"
layer=MOB_LAYER+1
WardStart
icon='ward.dmi'
icon_state="Holding"
layer=MOB_LAYER+1

mob/proc/Ward(mob/M as mob in view(1))
set category = "Spells"
if(usr.MP<=20)
usr<<"You don't have enough MP"

else
usr<<"You summon your power...."
usr.overlays+=/obj/overlays/WardStart
sleep(50)
usr.overlays-=/obj/overlays/WardStart
sleep(10)
var/damage=0*src.Level
sleep(150)
var/damage=2*src.Level


Anyone got any idea on how to fix this?

obj/Ward
icon='ward.dmi'
icon_state="Moving"

obj/overlays
WardEnd
icon='ward.dmi'
icon_state="Ward"
layer=MOB_LAYER+1
WardStart
icon='ward.dmi'
icon_state="Holding"
layer=MOB_LAYER+1

mob/proc/Ward(mob/M as mob in view(1))
set category = "Spells"
if(usr.MP<=20)
usr<<"You don't have enough MP"

else
usr<<"You summon your power...."
usr.overlays+=/obj/overlays/WardStart
sleep(50)
usr.overlays-=/obj/overlays/WardStart
sleep(10)
var/damage=0*src.Level
sleep(150)
var/damage=2*src.Level


Anyone got any idea on how to fix this?

Question: why do you have it specify a mob target (mob M as mob) but then not do anything with that target? Also, why do you define var/damage twice? Doesn't the compiler give you a warning or error when you compile this code?

Is damage=0*src.level the line that's supposed to make you invulnerable? It would be helpful if we knew what "invulnerable" meant in your game.
In response to Lesbian Assassin
Invulerable, in otherwords, unable to be hurt for a short period of time.
In response to Tents
I know that's what invulnerable means. What does it mean in your game? In other words, how does it work on the coding side... what part of the code refers to invulnerability? No one can help you without knowing what the problem is.
In response to Lesbian Assassin
Invulerable is just a word I used.
In response to Tents
Tents wrote:
Invulerable is just a word I used.

What Lexy's saying, Tents, is that you need to show us the code that's affected by the code you showed us. Seeing a line that says damage=0*src.level (which, by the way, is redundant, since 0*x==0) doesn't help us unless we know what var/damage actually does and where it's used.

Lummox JR
In response to Tents
Okay, now I have to leave for work. If you would've taken the time to answer my questions, I would've been able to post a solution for you by now. As it is, you'll have to hope that someone else helps you, or wait about ten hours for me to get back on the forums.

I know that invulnerable is just a word you're using. That's my whole point. The word itself means nothing in coding terms. You say the problem is that the code makes you invulnerable forever. Since invulnerable is just a word you're using, this description of your problem means nothing to anyone but you. In order to help you, we need to know exactly in your code it is that you're calling "invulnerability." Break it down.
In response to Lummox JR
What Tents is getting at is that he needs a piece of code to make this spell, make the mob "invulnerable" to attacks for a certain ammount of time. The fact is, he has no code for invulnarability and needs to know how to make this work.

~KnightRen
In response to KnightRen
KnightRen wrote:
What Tents is getting at is that he needs a piece of code to make this spell, make the mob "invulnerable" to attacks for a certain ammount of time. The fact is, he has no code for invulnarability and needs to know how to make this work.

~KnightRen

That's not at all what he said... his post says that the code does make the user invulnerable but forever instead of for a short period of time. If you're correct, that just illustrates my point: he needs to do a better job of explaining exactly what he wants to do.
In response to Lesbian Assassin
Considering this seems to be more of an argument than an assist, I will offer the following code to replace you current code. <BIG>Back up the original code first!</BIG>

mob/var/tmp/invulnerable = 0
mob/proc/TakeDamage(val)
if(invulnerable == 0)
hp -= val // Val is the damage, so to use the proc you specify target.TakeDamage(46), which will make target take 46 points of damage.
if(IsDead()) // This is an example proc a little further down, it basically checks to see if the character is dead
Die() // Change this to whatever proc you use to kill a character

mob/proc/IsDead()
if(hp <= 0) // checks to see if hp is at or below 0
return 1 // Will return the value 1, which makes if(IsDead()) true
else
return 0

Now, replace your old ward code with this....

mob/proc/Ward(mob/M as mob in view(1))
set category = "Spells"
if(usr.MP<=20)
usr<<"You don't have enough MP"

else
usr.MP -= 20 // Get rid of the 20 MP
usr<<"You summon your power...."
usr.overlays+=/obj/overlays/WardStart
usr.invulnerable = 1
sleep(50)
usr.overlays-=/obj/overlays/WardStart
usr.invulnerable = 0
usr<<"Your power disappears suddenly."


Whenever you need to damage the character, call TakeDamage(2413), and it will take damage, but only if they are not invincible. Also, you made need to change variables to whatever they are in your game. I think I caught everything, but post back on the results.


¿°Pólåt®¡Të°¿