Why is this code giving me duplicate definition and previous definition...
obj
dagger
name = "Dagger"
icon = 'weapons.dmi'
icon_state = "dagger"
var
strength = 1
equipped = 0
verb
Equip()
if (src.equipped == 1)
usr << "You already have this equipped!" // make sure they aren't "DOUBLE" equipping.
else
src.name = "Sword \[Equipped]" // Change the name so player knows it's equipped.
usr << "You wield the Sword."
usr.strength += src.strength // add the weapon strength to players strength. That way, player does more damage.
src.equipped = 1 // set the objects variable for equipped to 1 so that it can pass as being equipped.
Unequip()
if (src.equipped == 1)
usr << "You stop wielding the Sword."
src.name = "Sword"
usr.strength -= src.strength // Take the weapons strength away from player, so they do less damage.
src.equipped = 0
else
usr << "You don't have that equipped!"
Get()
set src in oview(1) // anyone within one tile of the object can get this verb
usr << "You get the Sword!"
usr.contents += src
shortsword
name = "Short sword"
icon = 'weapons.dmi'
icon_state = "shortsword"
var
strength = 2
equipped = 0
verb
Equip()
if (src.equipped == 1)
usr << "You already have this equipped!" // make sure they aren't "DOUBLE" equipping.
else
src.name = "Sword \[Equipped]" // Change the name so player knows it's equipped.
usr << "You wield the Sword."
usr.strength += src.strength // add the weapon strength to players strength. That way, player does more damage.
src.equipped = 1 // set the objects variable for equipped to 1 so that it can pass as being equipped.
Unequip()
if (src.equipped == 1)
usr << "You stop wielding the Sword."
src.name = "Sword"
usr.strength -= src.strength // Take the weapons strength away from player, so they do less damage.
src.equipped = 0
else
usr << "You don't have that equipped!"
Get()
set src in oview(1) // anyone within one tile of the object can get this verb
usr << "You get the Sword!"
usr.contents += src
ID:148952
![]() Aug 6 2002, 3:03 pm
|
|
I'm curious where you picked up this method of writing an Equip() verb, because it's really pretty bad. This is not to disparage your coding, but actually to disparage whoever first did it this way, because somebody really botched this up and everyone's been copying them ever since.
Take note of the following: obj This clearly means you don't have this var in your mob: mob And therein lies the problem. The player at no time has instant access to whatever weapon they're using--to find out, you'd have to loop through every weapon in inventory and find one with equipped!=0. That's a really lousy way to do this. If you use the mob.weapon var, however, you don't need to do any looping and you don't need to use the equipped var in your equipment, because a weapon's equip verb can look like this: obj/item/weapon Notice how I made the /obj/item/weapon class. My preferred way of handling things like this is to make an /obj/item class that has your basic Get() and Drop() verbs, then make subclasses like /obj/item/weapon, /obj/item/armor, etc. Those can each be given different verbs. Then you just set up your mob like this and you're good to go: mob Whenever any of these vars is null (they start out that way), you're not using one of them. Otherwise, they point to whatever equipment you're using. I added a little flourish here and put a cursed var in (belonging actually to obj/item, though I didn't show its definition). It's useful to anticipate that there may be some times that letting go of a weapon is impossible. Lummox JR |
but cant u just do this?
obj
dagger
name = "Dagger"
icon = 'weapons.dmi'
icon_state = "dagger"
var
strength = 1
equipped = 0
shortsword
name = "Short sword"
icon = 'weapons.dmi'
icon_state = "shortsword"
var
strength = 2
equipped = 0
verb
Equip()
if (src.equipped == 1)
usr << "You already have this equipped!" // make sure they aren't "DOUBLE" equipping.
else
src.name = "Sword \[Equipped]" // Change the name so player knows it's equipped.
usr << "You wield the Sword."
usr.strength += src.strength // add the weapon strength to players strength. That way, player does more damage.
src.equipped = 1 // set the objects variable for equipped to 1 so that it can pass as being equipped.
Unequip()
if (src.equipped == 1)
usr << "You stop wielding the Sword."
src.name = "Sword"
usr.strength -= src.strength // Take the weapons strength away from player, so they do less damage.
src.equipped = 0
else
usr << "You don't have that equipped!"
Get()
set src in oview(1) // anyone within one tile of the object can get this verb
usr << "You get the Sword!"
usr.contents += src
i was thinking that it was giving u duplicate definitions because u had 2 Equips,unequip etc..