I'm guessing I'm doing something very wrong. I'm trying to make an item system for my game. So far I tryed to get information for two items to begin with. Everytime I try to compile this code it gives me a bunch of duplaction errors.
obj/items/Sword
icon = 'rusty short sword.dmi'
verb
Equip()
set src in usr
if(usr.equip >= 1)
usr << "[src.name] is allready equiped"
else
usr.damage += 20
usr.equip += 1
suffix += "{-Equiped-}"
usr << "[src.name] is now equiped"
Un_Equip()
if(usr.equip == 0)
usr << "You don't have anything equiped"
else
usr.damage -= 20
usr.equip = 0
suffix = ""
usr << "Unequiped [src.name]"
icon = 'short sword.dmi'
verb
Equip()
set src in usr
if(usr.equip >= 1)
usr << "[src.name] is allready equiped"
usr.damage += 20
usr.equip += 1
suffix += "{-Equiped-}"
usr << "[src.name] is now equiped"
Un_Equip()
if(usr.equip == 0)
usr << "You don't have anything equiped"
else
usr.damage -= 20
usr.equip = 0
suffix = ""
usr << "Unequiped [src.name]"
loading swords.dme
loading Mapinterface.dmf
swords.dm:4:error: Equip: duplicate definition
C:\Documents and Settings\Lindsay\My Documents\BYOND\lib\rpg\items.dm:17:error: Equip: previous definition
swords.dm:13:error: Un_Equip: duplicate definition
C:\Documents and Settings\Lindsay\My Documents\BYOND\lib\rpg\items.dm:26:error: Un_Equip: previous definition
swords.dm:24:error: Equip: duplicate definition
swords.dm:32:error: Un_Equip: duplicate definition
ID:157869
Dec 19 2009, 8:10 pm
|
|
Dec 19 2009, 8:32 pm
|
|
You will need to create different subclasses of the Sword object to define a verb for each of them that has the same name. I would recommend however something more along the lines of defining variables for each subclass with an Equip() verb for all weapon objects
|
In response to Jotdaniel
|
|
on top of what he said it may simplify things to make equip and unequip one function.
for instance perform a check at the beginning of the equip function that checks to see if anything is equipped. If so, run the unequip code. if not run the code for equipping. just a little less work on your part and less confusion. |
In response to Dariuc
|
|
Could I have icon files connected to these subclasses? And what about when I want a diffrent weapon, like a mace? Same thing?
|
In response to GoodyKnocks
|
|
It's the same concept, I would make all weapons a subtype of say obj/weapon. So you would have obj/weapon/sword, and obj/weapon/mace, defining equip verbs under obj/weapon. If you do a quick forum search there's a lot of other methods for handling inventory, but it mostly depends on how polished you want it to look, and how you want your inventory to work.
|
In response to Jotdaniel
|
|
try to remove this code, the second:
icon = 'short sword.dmi' verb Equip() set src in usr if(usr.equip >= 1) usr << "[src.name] is allready equiped" usr.damage += 20 usr.equip += 1 suffix += "{-Equiped-}" usr << "[src.name] is now equiped" Un_Equip() if(usr.equip == 0) usr << "You don't have anything equiped" else usr.damage -= 20 usr.equip = 0 suffix = "" usr << "Unequiped [src.name]" |
Someone needs to learn about inheritance in the programming world.
|
In response to Spunky_Girl
|
|
Thank you. This is all very helpful. I'm going to get into the item coding later today again as soon as I have some spare time.
|