ID:271317
 
I'm currently trying to create the 'attack' verb.

I've asked some questions before about this, but I haven't had my answer, answered accurately, and I believe that has to do with the fact that my question was a little off..

So here I go again. ^_^ I think I got it right this time. :)



Here is my situation:

        Attack()
set src in oview(1)
..()
var/adamage = usr.ATK - src.DEF
if(adamage > 0)
usr << "You hit [src] with [adamage] damage!</BR></BR>"
src.HP -= adamage
var/bdamage = src.ATK - usr./DEF
usr << "[src] hits you back with [adamage] damage!</BR></BR>"
usr.HP -= adamage
Deathcheck()
sleep(100)
else
usr << "[src] misses its attack!</BR></BR>"
var/bdamage = src.ATK - usr./DEF
usr << "[src] hits you back with [adamage] damage!</BR></BR>"
usr.HP -= adamage
Deathcheck()
sleep(100)


Now, I've given the bugs their own, DEF, ATK, and HP variables, and I've given the user's variables as well..

What I keep getting as an error now, is that the variable, DEF, ATK, and HP are undefined variables.

I've already defined them.

Now here's my question:


"How do I call variables from other objects, mobs, etc. so that I can use them in verbs, procs, variables, etc.?"
I'm hoping this is a verb...Well not sure why you have ..() in a verb, but thats not the point.

Well there are many many many ways to do what your asking
//Heres an easy way
for(var/mob/M in view())
M << "[usr] attacks [src]!"
M << sound('pow.wav',0)
//or maybe you want to actually do something to M's variables
M.hp-- //Thats not the best example but you should get the point.


Hope that answers your question, if not maybe it will help you re-phrase your question so that we can better answer it.

-KirbyAllStar
In response to KirbyAllStar
This is a verb, and I took ..() out.

What I am having trouble with.. is that I can't figure out how to 'call' variables I've set already in other mobs or objs.

When I have:

var/damage = usr.ATK - src.DEF


For some reason, even though I've already said that the src is 'oview(1)' from the usr, it still says that src.DEF is not a defined variable. I want the src.DEF to be defined, and I want the verb ATTACK, which is not in the mob/bug's attributes, but the mob/player's attributes-

Basically- I want mob/player to be able to call variables declared in mob/X, where X is the mob that is in front of the user's sprite, or 'mob/player' if you will.

Make more sense? :(
In response to Elite_SnowMan
Elite_SnowMan wrote:
This is a verb, and I took ..() out.

What I am having trouble with.. is that I can't figure out how to 'call' variables I've set already in other mobs or objs.

When I have:

> var/damage = usr.ATK - src.DEF
>

For some reason, even though I've already said that the src is 'oview(1)' from the usr, it still says that src.DEF is not a defined variable. I want the src.DEF to be defined, and I want the verb ATTACK, which is not in the mob/bug's attributes, but the mob/player's attributes-

Basically- I want mob/player to be able to call variables declared in mob/X, where X is the mob that is in front of the user's sprite, or 'mob/player' if you will.

Make more sense? :(

I think the problem is that src is not defined as a mob. maybe the proper syntax would be:
set src as mob in oview(1)


I think things like this are covered in the guide. I also think I would have done it as :

    verb
SayHi(var/mob/B in oview(5))
world << "[usr] waves at [B]. [B] has [B.HP] HP"



HP is a mob var in my code. The second way is how I normally do it, but I'm not going to tell you it's the best way. What you need to do is define what type (using AS) the src is.
In response to Jik
This code works, but is it advisable to use this with multiple mobs?

mob

man01
man101
name = "Man"
var
LEVEL = 1
DEF = 1
ATK = 5
HP = 25
icon = 'man01.dmi'
icon_state = "man101"
verb
Check_Health()
usr << "You have [HP] HP."
man102
name = "Man"
var
LEVEL = 1
DEF = 2
ATK = 10
HP = 30
icon = 'man01.dmi'
icon_state = "man102"
verb
Check_Health()
usr << "You have [HP] HP."

Login()
loc = locate(23,34,1)
..()


verb
Attack()
set src in oview(1)
for(var/mob/M in oview(1))
usr << "You have attacked [M]!</BR></BR>"
var
damage = usr:ATK - M:DEF
bdamage = M:ATK - usr:DEF

M:HP -= damage
usr:HP -= bdamage
usr << "You attack with [damage] damage!</BR></BR>"
usr << "[M] defends with [bdamage] damage!</BR></BR>"
M.Deathcheck()
usr.Deathcheck()
proc
Deathcheck()
if(src:HP <= 0)
src << "You have died."
del(src)
sleep(200)
..()
else
sleep(200)
..()



Is there a better way?
In response to Elite_SnowMan
Here.
mob
verb
attack(mob/M in get_step(src,src.dir))
var/damage = max(0,(src.atk - M.def))
M.hp -= damage
src << "You attack [M] for [damage] damage"
M << "[src] attacks you for [damage]"
src.DeathCheck(M)
proc
DeathCheck(mob/victim)
if(victim.hp <= 0)
if(victim.client)
victim.loc = locate("deathspawn")
victim.gold = round(victim.gold/2)
src.gold += victim.gold
else // monster
src.xp += victim.givexp
del(victim)
mob
var
gold
hp
xp
givexp

In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
Here.
> mob
> verb
> attack(mob/M in get_step(src,src.dir))
> var/damage = max(0,(src.atk - M.def))
> M.hp -= damage
> src << "You attack [M] for [damage] damage"
> M << "[src] attacks you for [damage]"
> src.DeathCheck(M)
> proc
> DeathCheck(mob/victim)
> if(victim.hp <= 0)
> if(victim.client)
> victim.loc = locate("deathspawn")
> victim.gold = round(victim.gold/2)
> src.gold += victim.gold
> else // monster
> src.xp += victim.givexp
> del(victim)
> mob
> var
> gold
> hp
> xp
> givexp
>



Now, what if I wanted to have two victims? Victim1 and Victim2. THAT'S my real question. Would I have to have this deathcheck proc within each mob to check if it's dead or not, or is there some universal way to deal with this?
In response to Elite_SnowMan
It will work with 999 victims.
In response to Xx Dark Wizard xX
Okay, so how would I rename 'victim'...? with src? or changing M? o_O :(


And, this is the errors that show up for your code alone:
loading test1.dme
test1.dm:15:error:src.gold:undefined var
test1.dm:17:error:src.xp:undefined var
test1.dm:4:error:src.atk:undefined var
test1.dm:4:error:M.def:undefined var
test1.dm:8:error:src.DeathCheck:undefined proc

test1.dmb - 5 errors, 0 warnings (double-click on an error to jump to it)


:(
In response to Elite_SnowMan
No you read the god damn guide and stop copy pasting code from the forums.
In response to Xx Dark Wizard xX
O_O I'm on chapter 4, so I am reading the 'god damn guide'. Also, I didn't think you're idea would work, so I put your material all by itself in and ran it and it gave me those errors!

So why are you badgering me? Is it because either
a) I don't understand something and you aren't understanding that.. or
b) You are wrong and being ignorant about it.

I hope it's 'a' to be honest- because in this case I'd rather be wrong, than someone who is supposed to have more experience. :\

In response to Elite_SnowMan
Elite_SnowMan wrote:
O_O I'm on chapter 4, so I am reading the 'god damn guide'. Also, I didn't think you're idea would work, so I put your material all by itself in and ran it and it gave me those errors!

So why are you badgering me? Is it because either
a) I don't understand something and you aren't understanding that.. or
b) You are wrong and being ignorant about it.
I hope it's 'a' to be honest- because in this case I'd rather be wrong, than someone who is supposed to have more experience. :\


Ok, for one, if you look at what you have added (meaning copying and pasting his code) you would understand the first few errors. The last error was in his code. The proc giving the error should be a mob proc.

His point is that you can't just copy and paste what someone may give you here. That is not the point of the information they are giving you. You should study and try and understand it. Then use that knowledge to apply what was told to you to your own code.

The errors you posted are easily understood if you have read the guide.
In response to Jik
Okay. I'm still reading the guide.. but I don't get how complicated my question really is.. it seems so simple.

"How do I define src.DEF or usr.DEF ... etc. ?"

[referring to most of the above code- including my own.]


:(
In response to Elite_SnowMan
That was mentioned in chapter 3.
In response to Elite_SnowMan
Elite_SnowMan wrote:
Okay. I'm still reading the guide.. but I don't get how complicated my question really is.. it seems so simple.

"How do I define src.DEF or usr.DEF ... etc. ?"

[referring to most of the above code- including my own.]


:(

to use src, something must be the source of the proc. That would also mean that the proc would have to be in that type. Just like with usr.

To get away from making things confusing and possibly inter mixing src and usr, why not pass the src (or target) of the proc/verb as an argument (like what I showed you I do). That way the argument can be given a type in the definition of the proc
proc(var/mob/Attacker, var/mob/Target)


in this case both Attacker and Target have all the vars that go with mob objects. I would suggest doing this for all your procs (verbs always have usr) until you get a better understanding of how to use src.

Not trying to belittle you here, but it does get confusing, which is why I tend to pass agruments. A bit more code, but it's more exact (visually) to me.

Hope this helps. Keep reading though, and do the codes they present in there. I'm finding that I may go back, read it again and code out the examples.