mob/proc/Damage(A,B,C,D)
src.HP-=A
src.MP-=B
src.HP+=C
src.MP+=D
EvenOut()
DeathCheck()
..()
mob/proc/DeathCheck(src as mob)
if(HP<=0)
world << "<B>[usr] has killed [src]!"
mob/proc/EvenOut()
if(HP>MaxHP)
HP=MaxHP
if(MP>MaxMP)
MP=MaxMP
if(MP>0)
MP = 0
if(HP>0)
HP = 0
ID:157079
May 28 2010, 1:26 pm
|
|
Is there a better way of doing this? If so, could you give an example? Because this is the best way I could think of doing it.
|
May 28 2010, 2:24 pm
|
|
You're doing good, but there's a few things you got wrong. In Damage and EvenOut, you need to define a mob being affected. And in DeathCheck, you used usr in a proc, which is a very bad thing to do. There are some places where usr can be used in a proc, but that is not one of them. Define two mobs as arguments, one for the killer and one for the victim. But you haven't hard-coded anything, which is good, and you get what procs are used for, which is also good.
|
Well, if the damage check is that simple, you can just use negative values in A and B if you want to increase them.
Also, his procs are all attached to a mob as src, so I don't get what you mean by define a mob being affected. |
In response to Warlord Fred
|
|
Alright, I revised it a bit, I'm pretty sure I am good with this now. I am going to try to now work on displaying numbers on the HUD. It is really complicated though, I may just do it in an inefficient way because I do not understand how libraries such as Lummox's works. (I'll be back asking for help XD)
Anyways: mob/proc/Damage(A,B) |
In response to Darkjohn66
|
|
Advice revoked.
|
Yes. Yes, there is a better way of doing this. For one, let's learn something about Dream Maker, and objects in general.
Every object has its own functions. For example, atoms all have the Enter() function. Each atom's Enter() function is unique in that it belongs to that atom. In pretty much every language, we are provided with some way to refer to the source of the function (the object it belongs to). In DM, we have the src variable. The src variable will always, always, always refer to the object that owns the function. You do not need to redefine it (and I'd assume you actually can't). It will always, always, always exist in an object function call. The usr variable is something else entirely. The usr variable refers to the mob of the client that started the call stack (or if it was started by the world, nothing). 99% of the time someone is using usr on BYOND, they want to use src. Learning which one to use is vital, because if you don't know what you're doing, there is a good chance you're going to end up creating problems. Do not use usr unless you know you need to. If you don't know, then chances are, you shouldn't. Also, please be aware that the "as" modifier does absolutely nothing outside of verbs. The "as" modifier is for verbs and calls to input(), and probably some other places I'm forgetting. I'd comment on your EvenOut function, but I'll assume that you just made a typo twice in a row. If you still don't know what I'm talking about, every call to EvenOut() will either set your health to 0, or leave your health below 0 (same for mana). Anyway, as for a better way to handle this, I'd like to think this method seems a little bit smarter. mob We can use events that trigger events, as opposed to arbitrary checks every time we want to do something. If we're being healed, make sure we aren't going over our cap. If we're taking damage and our health drops below 1, die. etc... |
In response to Keeth
|
|
Alright, I am going to set up the victim variable within that code and look over what Keeth posted.
This is the setup of the logic:
/* Also, Thank You! |
In response to Warlord Fred
|
|
Warlord Fred wrote:
I'd recommend not using src in a damage proc, but instead defining a target mob as an argument. Also add a victim mob arg in DeathCheck, and a target mob arg in EvenOut. I'd recommend ignoring this advice as it's wrong. src is by and away the only variable that makes sense to use in this context. However, you DO need an argument for the attacker in the damage proc, if only to pass it to the deathcheck proc. And, small nitpicks: the last two inequalities in EvenOut() are backwards. ..() is thoroughly meaningless in the first definition of a proc (if you wrote "proc", then ..() by definition cannot possibly do anything). |
In response to Darkjohn66
|
|
You should know about the % (modulo) operator. It's basically the remainder from division. So, to split a number into its digits:
proc/digits(var/N) |
In response to Garthor
|
|
This is confusing to me. I don't understand how I could do the math I need for this by using the modulus operator. I tried to mess around and test, but this is all I came up with.
mob/verb/digit_test() Which when used, just tells me: <font color=silver> 1000 is N, 1 is L. 100 is N, 2 is L. 10 is N, 3 is L. 1 is N, 4 is L. 0 is N, 5 is L. </font> |
In response to Darkjohn66
|
|
Modulo is the remainder after the most possible divisions (without a decimal) is used.
ex: 10 % 3 = 1 3 + 3 = 6 (+ 3) = 9 (+ 3) = 12(Which is greater than 10) So it stops at 9, and returns the remainder of 10 - 9 which is 1. At least that's how I think it works :/ |
In response to Leur
|
|
I don't understand how that could help me though Leur, and I am still pretty confused at the least.
|
In response to Darkjohn66
|
|
Because you should be looking at what's in L, not what N is at each iteration. What L will contain after that is {0,0,0,0,1}, which are the digits in the number (though backwards, but that really doesn't matter).
|