ID:155584
 
More specifically, used in a mob tree. I have weapons that i set to augment a variable for dmg done by a mob. How do i 'call' the obj/var/Weapon_dmg variable into a verb in the mob tree? I have a melee attack verb and want to add the variable of Weapon_dmg to the mathmatics defining damage for a melee attack.
Depends what reference the mob has to a weapon. Does it have a weapon in some variable?
In response to Stephen001
hmmm, no, i suppose it doesnt. I was just setting up the items for my obj tree and wondered how to link a sword or in this case a knife to a mobs melee attack. i would have to define a weapon variable for a mob as well then? Not just have an equip feature in the obj tree? This may be a little advanced for my current working knowledge, but i must learn =P.
In response to Kentos123
Can you post your two codes so I can see what you are exactly asking for?
In response to Xirre
its real basic right now, im not done coding the weapon.
Items

Weapons

Knife

Equip_Weapon()

Weapon_dmg += 10

Thats the basic code for a weapon when i ran into trouble, here is where i want it.
V this is under mob/verb V

melee_attack(mob/M as mob in oview(1))
var
MeleeDamage = usr.Strength + (Weapon_dmg) - (M.Armor * 2)
if(MeleeDamage <= 0)
icon_state = "Melee Attack"
usr << "Your attack could not bypass the armor of [M]"
M << " Your Armor has deflected a strike by [usr] "
sleep(2)
icon_state = " "
else
M.Health -= MeleeDamage
icon_state = "Melee Attack"
usr << " You have done <font color = red >[MeleeDamage] <font color = black>Damage to [M] "
M:Knock_out()
M:Kill()
sleep(2)
icon_state = " "

In response to Kentos123
Please try to use dm tags for displaying code.

As far as the problem goes, I would have the weapon equipped to a variable and retrieve it with the strength using a proc to add them up in advance.:

obj
weapon
var/damage = 10
verb
equip()
set src in usr // only availbe when in mob.contents
usr.w = src //set it to the usr's w varible.

mob
var
obj/weapon/w // a varible that is of the type /obj/weapon
strength = 5
proc
getStrength() //proc to get the basic stength of the current user.
return w.damage+strength //w is the weapon, so we are reading w's damage variable.

verb
attack()
var/damage = src.getStrength() //call the proc to get the basic stength of the current user.
In response to Pirion
usr.w = src comes up as an undefined definition. Isnt it being defined in that line?
In response to Kentos123
Kentos123 wrote:
usr.w = src comes up as an undefined definition. Isnt it being defined in that line?

That's an assignment, not a definition. For that line to work correctly, the /mob type has to have var/w defined. If you only defined w for /mob/player or something like that, you'll get a compiler error because usr is only known to be a /mob.

Just as a style note I would recommend not having different equip verbs for each type (weapon, armor, etc.) but just having the same verb called Equip for all of them.

Lummox JR
In response to Lummox JR
Thank you, im still unsure how to define w in this code, should be defined as text? and i should place it as a general var under mob, not something like mob/player right?
And my thoughts exactly on the equip/unequip verb.
In response to Kentos123
It should be defined under /mob instead of /mob/player, yes, mostly for simplicity. That way usr has access to it, and it's probably relevant to monsters as well. However I would recommend giving it a longer name, and even better I would recommend giving it a type.

mob
var/obj/item/weapon/weapon


Now you'll have a var named weapon, which is of type /obj/item/weapon. You can define Get() and Drop() verbs under /obj/item, and Equip() and Unequip() under the various equippable subtypes.

At any given time, the weapon var will show which weapon the mob in question is wielding.

Lummox JR
In response to Lummox JR
alright, but im still having the basic problem of using this variable in an equation for dmg and its still coming up as undefined in the items dm. ( I have different a different dm file for items, turf, player etc. )

proc

GetMeleeDamage()
return weapon.Weapon_dmg + Strength - (Armor * 2)


this shows- undefined type: weapon.Weapon_dmg


And...


    verb
Equip_Weapon()

set src in usr
if(Weapon_equipped == 1 )
usr << "You already have a weapon equipped."

else
if(Weapon_equipped == 0)
Weapon_equipped = 1
usr << " You have equipped a weapon "

usr.weapon = src



usr.weapon = src still is considered undefined.


perhaps im missing something important thats not in the codes above, chances are i might not be cut out for coding but ill be damned if i dont at least try and get things right. I thank you all for you input, but for some reason this is not working for me.
In response to Kentos123
    melee_attack(mob/M as mob in oview(1))
var/MeleeDamage = usr.Strength + (Weapon_dmg) - (M.Armor * 2)
if(MeleeDamage<=0)
flick(src,"Melee Attack")//Will run the Melee Attack icon state and change back
src << "Your attack could not bypass the armor of [M]."
M << "Your Armor has deflected a strike by [src]."
else
M.Health -= MeleeDamage
flick(src,"Melee Attack")
src << " You have done [MeleeDamage] Damage to [M]."
M:Knock_out()
M:Kill()


Tell me if there anything you need.